Skip to content

Commit

Permalink
add ability to track per-database applied hlc (facebook#1113) (facebo…
Browse files Browse the repository at this point in the history
…ok#1113)

Summary:
Adds the ability in HybridLogicalClock to maintain per-database applied HLC. The
feature is guarded by a new sysvar 'maintain_database_hlc'.

The database name is extracted from all Table_map_log_event or Query_log_event
in a trx and stored as a set in THD. This gives a list of all databases touched
by this trx. After engine commit, the HLC of the trx is updated as
'applied_hlc' for every database touched by the trx.

We track the per-database applied_hlc as a map (with the key as the database
name and value as applied hlc) per instance.

Per-database applied HLC is exposed as a information schema table
'database_applied_hlc'. On querying this table, we get the map of per-database
applied hlc and populate the result set.

Reference Patch: facebook@b90a327

8.0 porting notes:
* 'sys_vars.maintain_database_hlc_basic' MTR test case expanded and
   unified.

Pull Request resolved: facebook#1113

Reviewed By: luqun

Differential Revision: D20131111

Pulled By: bhatvinay
  • Loading branch information
bhatvinay authored and inikep committed Apr 25, 2024
1 parent 3d1da56 commit 41997e7
Show file tree
Hide file tree
Showing 35 changed files with 1,389 additions and 7 deletions.
1 change: 1 addition & 0 deletions mysql-test/r/dd_is_compatibility_ci.result
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ COLUMNS
COLUMNS_EXTENSIONS
COLUMN_PRIVILEGES
COLUMN_STATISTICS
DATABASE_APPLIED_HLC
ENABLED_ROLES
ENGINES
EVENTS
Expand Down
1 change: 1 addition & 0 deletions mysql-test/r/dd_is_compatibility_cs.result
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ COLUMNS
COLUMNS_EXTENSIONS
COLUMN_PRIVILEGES
COLUMN_STATISTICS
DATABASE_APPLIED_HLC
ENABLED_ROLES
ENGINES
EVENTS
Expand Down
5 changes: 4 additions & 1 deletion mysql-test/r/information_schema_ci.result
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ COLUMNS
COLUMNS_EXTENSIONS
COLUMN_PRIVILEGES
COLUMN_STATISTICS
DATABASE_APPLIED_HLC
ENABLED_ROLES
ENGINES
EVENTS
Expand Down Expand Up @@ -904,7 +905,7 @@ AND table_name COLLATE utf8_general_ci not like 'innodb_%'
AND table_name COLLATE utf8_general_ci not like 'rocksdb_%'
GROUP BY TABLE_SCHEMA;
TABLE_SCHEMA count(*)
information_schema 51
information_schema 52
mysql 35
create table t1 (i int, j int);
create trigger trg1 before insert on t1 for each row
Expand Down Expand Up @@ -2510,6 +2511,7 @@ COLUMNS TABLE_SCHEMA
COLUMNS_EXTENSIONS TABLE_SCHEMA
COLUMN_PRIVILEGES TABLE_SCHEMA
COLUMN_STATISTICS SCHEMA_NAME
DATABASE_APPLIED_HLC DATABASE_NAME
ENABLED_ROLES ROLE_NAME
ENGINES ENGINE
EVENTS EVENT_SCHEMA
Expand Down Expand Up @@ -2581,6 +2583,7 @@ COLUMNS TABLE_SCHEMA
COLUMNS_EXTENSIONS TABLE_SCHEMA
COLUMN_PRIVILEGES TABLE_SCHEMA
COLUMN_STATISTICS SCHEMA_NAME
DATABASE_APPLIED_HLC DATABASE_NAME
ENABLED_ROLES ROLE_NAME
ENGINES ENGINE
EVENTS EVENT_SCHEMA
Expand Down
5 changes: 4 additions & 1 deletion mysql-test/r/information_schema_cs.result
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ COLUMNS
COLUMNS_EXTENSIONS
COLUMN_PRIVILEGES
COLUMN_STATISTICS
DATABASE_APPLIED_HLC
ENABLED_ROLES
ENGINES
EVENTS
Expand Down Expand Up @@ -904,7 +905,7 @@ AND table_name COLLATE utf8_general_ci not like 'innodb_%'
AND table_name COLLATE utf8_general_ci not like 'rocksdb_%'
GROUP BY TABLE_SCHEMA;
TABLE_SCHEMA count(*)
information_schema 51
information_schema 52
mysql 35
create table t1 (i int, j int);
create trigger trg1 before insert on t1 for each row
Expand Down Expand Up @@ -2510,6 +2511,7 @@ COLUMNS TABLE_SCHEMA
COLUMNS_EXTENSIONS TABLE_SCHEMA
COLUMN_PRIVILEGES TABLE_SCHEMA
COLUMN_STATISTICS SCHEMA_NAME
DATABASE_APPLIED_HLC DATABASE_NAME
ENABLED_ROLES ROLE_NAME
ENGINES ENGINE
EVENTS EVENT_SCHEMA
Expand Down Expand Up @@ -2581,6 +2583,7 @@ COLUMNS TABLE_SCHEMA
COLUMNS_EXTENSIONS TABLE_SCHEMA
COLUMN_PRIVILEGES TABLE_SCHEMA
COLUMN_STATISTICS SCHEMA_NAME
DATABASE_APPLIED_HLC DATABASE_NAME
ENABLED_ROLES ROLE_NAME
ENGINES ENGINE
EVENTS EVENT_SCHEMA
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ The following options may be given as the first argument:
If set to 1 table names are stored in lowercase on disk
and table names will be case-insensitive. Should be set
to 2 if you are using a case insensitive file system
--maintain-database-hlc
Enable maintaining of max HLC applied per database
--mandatory-roles=name
All the specified roles are always considered granted to
every user and they can't be revoked. Mandatory roles
Expand Down Expand Up @@ -2603,6 +2605,7 @@ log-timestamps UTC
long-query-time 10
low-priority-updates FALSE
lower-case-table-names 1
maintain-database-hlc FALSE
mandatory-roles
master-info-file master.info
master-info-repository TABLE
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/r/mysqld--help-win.result
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ The following options may be given as the first argument:
If set to 1 table names are stored in lowercase on disk
and table names will be case-insensitive. Should be set
to 2 if you are using a case insensitive file system
--maintain-database-hlc
Enable maintaining of max HLC applied per database
--mandatory-roles=name
All the specified roles are always considered granted to
every user and they can't be revoked. Mandatory roles
Expand Down Expand Up @@ -1820,6 +1822,7 @@ log-timestamps UTC
long-query-time 10
low-priority-updates FALSE
lower-case-table-names 1
maintain-database-hlc FALSE
mandatory-roles
master-info-file master.info
master-info-repository TABLE
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/r/mysqlshow_ci.result
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Database: information_schema
| COLUMN_STATISTICS |
| COLUMNS |
| COLUMNS_EXTENSIONS |
| DATABASE_APPLIED_HLC |
| ENABLED_ROLES |
| ENGINES |
| EVENTS |
Expand Down Expand Up @@ -192,6 +193,7 @@ Database: INFORMATION_SCHEMA
| COLUMN_STATISTICS |
| COLUMNS |
| COLUMNS_EXTENSIONS |
| DATABASE_APPLIED_HLC |
| ENABLED_ROLES |
| ENGINES |
| EVENTS |
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/r/mysqlshow_cs.result
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Database: information_schema
| COLUMNS_EXTENSIONS |
| COLUMN_PRIVILEGES |
| COLUMN_STATISTICS |
| DATABASE_APPLIED_HLC |
| ENABLED_ROLES |
| ENGINES |
| EVENTS |
Expand Down Expand Up @@ -193,6 +194,7 @@ Database: INFORMATION_SCHEMA
| COLUMNS_EXTENSIONS |
| COLUMN_PRIVILEGES |
| COLUMN_STATISTICS |
| DATABASE_APPLIED_HLC |
| ENABLED_ROLES |
| ENGINES |
| EVENTS |
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/suite/funcs_1/r/is_columns_is_ci.result
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def information_schema COLUMN_STATISTICS SCHEMA_NAME 1 NULL NO varchar 64 192 NU
def information_schema COLUMN_STATISTICS TABLE_NAME 2 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8_bin varchar(64) select NULL
def information_schema COLUMN_STATISTICS COLUMN_NAME 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8_bin varchar(64) select NULL
def information_schema COLUMN_STATISTICS HISTOGRAM 4 NULL NO json NULL NULL NULL NULL NULL NULL NULL json select NULL
def information_schema DATABASE_APPLIED_HLC DATABASE_NAME 1 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(192) select NULL
def information_schema DATABASE_APPLIED_HLC APPLIED_HLC 2 NO bigint NULL NULL NULL NULL NULL NULL NULL bigint unsigned select NULL
def information_schema ENABLED_ROLES ROLE_NAME 1 NULL YES varchar 255 1020 NULL NULL NULL utf8mb4 utf8mb4_0900_ai_ci varchar(255) select NULL
def information_schema ENABLED_ROLES ROLE_HOST 2 NULL YES varchar 255 1020 NULL NULL NULL utf8mb4 utf8mb4_0900_ai_ci varchar(255) select NULL
def information_schema ENABLED_ROLES IS_DEFAULT 3 NULL YES varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) select NULL
Expand Down Expand Up @@ -736,6 +738,8 @@ NULL information_schema COLUMNS_EXTENSIONS SECONDARY_ENGINE_ATTRIBUTE json NULL
3.0000 information_schema COLUMN_STATISTICS TABLE_NAME varchar 64 192 utf8mb3 utf8_bin varchar(64)
3.0000 information_schema COLUMN_STATISTICS COLUMN_NAME varchar 64 192 utf8mb3 utf8_bin varchar(64)
NULL information_schema COLUMN_STATISTICS HISTOGRAM json NULL NULL NULL NULL json
3.0000 information_schema DATABASE_APPLIED_HLC DATABASE_NAME varchar 64 192 utf8 utf8_general_ci varchar(192)
NULL information_schema DATABASE_APPLIED_HLC APPLIED_HLC bigint NULL NULL NULL NULL bigint unsigned
4.0000 information_schema ENABLED_ROLES ROLE_NAME varchar 255 1020 utf8mb4 utf8mb4_0900_ai_ci varchar(255)
4.0000 information_schema ENABLED_ROLES ROLE_HOST varchar 255 1020 utf8mb4 utf8mb4_0900_ai_ci varchar(255)
3.0000 information_schema ENABLED_ROLES IS_DEFAULT varchar 3 9 utf8mb3 utf8mb3_general_ci varchar(3)
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/suite/funcs_1/r/is_columns_is_cs.result
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def information_schema COLUMN_STATISTICS SCHEMA_NAME 1 NULL NO varchar 64 192 NU
def information_schema COLUMN_STATISTICS TABLE_NAME 2 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_bin varchar(64) select NULL
def information_schema COLUMN_STATISTICS COLUMN_NAME 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8_bin varchar(64) select NULL
def information_schema COLUMN_STATISTICS HISTOGRAM 4 NULL NO json NULL NULL NULL NULL NULL NULL NULL json select NULL
def information_schema DATABASE_APPLIED_HLC DATABASE_NAME 1 NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(192) select NULL
def information_schema DATABASE_APPLIED_HLC APPLIED_HLC 2 NO bigint NULL NULL NULL NULL NULL NULL NULL bigint unsigned select NULL
def information_schema ENABLED_ROLES ROLE_NAME 1 NULL YES varchar 255 1020 NULL NULL NULL utf8mb4 utf8mb4_0900_ai_ci varchar(255) select NULL
def information_schema ENABLED_ROLES ROLE_HOST 2 NULL YES varchar 255 1020 NULL NULL NULL utf8mb4 utf8mb4_0900_ai_ci varchar(255) select NULL
def information_schema ENABLED_ROLES IS_DEFAULT 3 NULL YES varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) select NULL
Expand Down Expand Up @@ -759,6 +761,8 @@ NULL information_schema COLUMNS_EXTENSIONS SECONDARY_ENGINE_ATTRIBUTE json NULL
3.0000 information_schema COLUMN_STATISTICS TABLE_NAME varchar 64 192 utf8mb3 utf8mb3_bin varchar(64)
3.0000 information_schema COLUMN_STATISTICS COLUMN_NAME varchar 64 192 utf8mb3 utf8_bin varchar(64)
NULL information_schema COLUMN_STATISTICS HISTOGRAM json NULL NULL NULL NULL json
3.0000 information_schema DATABASE_APPLIED_HLC DATABASE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(192)
NULL information_schema DATABASE_APPLIED_HLC APPLIED_HLC bigint NULL NULL NULL NULL bigint unsigned
4.0000 information_schema ENABLED_ROLES ROLE_NAME varchar 255 1020 utf8mb4 utf8mb4_0900_ai_ci varchar(255)
4.0000 information_schema ENABLED_ROLES ROLE_HOST varchar 255 1020 utf8mb4 utf8mb4_0900_ai_ci varchar(255)
3.0000 information_schema ENABLED_ROLES IS_DEFAULT varchar 3 9 utf8mb3 utf8mb3_general_ci varchar(3)
Expand Down
46 changes: 46 additions & 0 deletions mysql-test/suite/funcs_1/r/is_tables_is.result
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,29 @@ user_comment
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA information_schema
TABLE_NAME DATABASE_APPLIED_HLC
TABLE_TYPE SYSTEM VIEW
ENGINE NULL
VERSION 10
ROW_FORMAT NULL
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT #AI#
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION NULL
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA information_schema
TABLE_NAME ENABLED_ROLES
TABLE_TYPE SYSTEM VIEW
ENGINE NULL
Expand Down Expand Up @@ -1441,6 +1464,29 @@ user_comment
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA information_schema
TABLE_NAME DATABASE_APPLIED_HLC
TABLE_TYPE SYSTEM VIEW
ENGINE NULL
VERSION 10
ROW_FORMAT NULL
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT #AI#
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION NULL
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA information_schema
TABLE_NAME ENABLED_ROLES
TABLE_TYPE SYSTEM VIEW
ENGINE NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COLUMNS
COLUMNS_EXTENSIONS
COLUMN_PRIVILEGES
COLUMN_STATISTICS
DATABASE_APPLIED_HLC
ENABLED_ROLES
ENGINES
EVENTS
Expand Down
Loading

0 comments on commit 41997e7

Please sign in to comment.