[Commits] 7546be4493e: Support Create_time and Update_time in MyRocks table status
revision-id: 7546be4493efb8509aae772e02d382078db8c5e7 (fb-prod201903-145-g7546be4493e) parent(s): 6dc3fa2e054d999a12cd5d7aaf637e4ac7c3f149 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2019-10-17 01:08:00 +0300 message: Support Create_time and Update_time in MyRocks table status Address review input: - Change the default to be rocksdb_table_dictionary_format=1. One needs to set the parameter to 2 to get Create_time to be saved. - Other small changes --- mysql-test/suite/rocksdb/r/rocksdb.result | 2 +- .../r/rocksdb_table_dictionary_format.result | 2 +- .../suite/rocksdb/r/show_table_status.result | 14 ++++++++++ mysql-test/suite/rocksdb/t/show_table_status.test | 25 +++++++++++++++-- .../r/rocksdb_table_dictionary_format_basic.result | 2 +- storage/rocksdb/rdb_datadic.cc | 32 ++++++++++++++-------- storage/rocksdb/rdb_datadic.h | 16 +++++++---- 7 files changed, 71 insertions(+), 22 deletions(-) diff --git a/mysql-test/suite/rocksdb/r/rocksdb.result b/mysql-test/suite/rocksdb/r/rocksdb.result index c76f31afaab..59856d2f6e8 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb.result +++ b/mysql-test/suite/rocksdb/r/rocksdb.result @@ -979,7 +979,7 @@ rocksdb_store_row_debug_checksums OFF rocksdb_strict_collation_check OFF rocksdb_strict_collation_exceptions rocksdb_table_cache_numshardbits 6 -rocksdb_table_dictionary_format 2 +rocksdb_table_dictionary_format 1 rocksdb_table_stats_background_thread_nice_value 19 rocksdb_table_stats_max_num_rows_scanned 0 rocksdb_table_stats_recalc_threshold_count 100 diff --git a/mysql-test/suite/rocksdb/r/rocksdb_table_dictionary_format.result b/mysql-test/suite/rocksdb/r/rocksdb_table_dictionary_format.result index 8f2fa96a04a..82f1064f937 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb_table_dictionary_format.result +++ b/mysql-test/suite/rocksdb/r/rocksdb_table_dictionary_format.result @@ -1,6 +1,6 @@ select @@rocksdb_table_dictionary_format; @@rocksdb_table_dictionary_format -2 +1 # # Server restarted # diff --git a/mysql-test/suite/rocksdb/r/show_table_status.result b/mysql-test/suite/rocksdb/r/show_table_status.result index 345882040ef..58119860482 100644 --- a/mysql-test/suite/rocksdb/r/show_table_status.result +++ b/mysql-test/suite/rocksdb/r/show_table_status.result @@ -25,6 +25,9 @@ DROP DATABASE `db_new..............................................end`; # # MDEV-17171: Bug: RocksDB Tables do not have "Creation Date" # +select @@rocksdb_table_dictionary_format; +@@rocksdb_table_dictionary_format +2 use test; create table t1 (a int) engine=rocksdb; select create_time is not null, update_time, check_time @@ -99,3 +102,14 @@ where table_schema=database() and table_name='t1'; create_time=(select create_time from t2) 1 update_time NULL drop table t1, t2; +# +# Check how it works for partitioned tables +# +create table t1 (pk int primary key) partition by hash(pk) partitions 2; +insert into t1 values (1); +select create_time IS NOT NULL , update_time IS NOT NULL +from information_schema.tables +where table_schema=database() and table_name='t1'; +create_time IS NOT NULL 1 +update_time IS NOT NULL 1 +drop table t1; diff --git a/mysql-test/suite/rocksdb/t/show_table_status.test b/mysql-test/suite/rocksdb/t/show_table_status.test index 59effcc788c..19f46ddb251 100644 --- a/mysql-test/suite/rocksdb/t/show_table_status.test +++ b/mysql-test/suite/rocksdb/t/show_table_status.test @@ -1,5 +1,5 @@ --source include/have_rocksdb.inc - +--source include/have_partition.inc # # SHOW TABLE STATUS statement # @@ -62,9 +62,15 @@ CREATE TABLE `t1_new..............................................end`(a int) en INSERT INTO `t1_new..............................................end` VALUES (1); --query_vertical SELECT TABLE_SCHEMA, TABLE_NAME FROM information_schema.table_statistics WHERE TABLE_NAME = 't1_new..............................................end' DROP DATABASE `db_new..............................................end`; + --echo # --echo # MDEV-17171: Bug: RocksDB Tables do not have "Creation Date" --echo # + +--let $_mysqld_option=--rocksdb_table_dictionary_format=2 +--source include/restart_mysqld_with_option.inc + +select @@rocksdb_table_dictionary_format; use test; create table t1 (a int) engine=rocksdb; @@ -130,7 +136,8 @@ select create_time from information_schema.tables where table_schema=database() and table_name='t1'; ---source include/restart_mysqld.inc +# We stiil have $_mysqld_option=--rocksdb_table_dictionary_format=2 +--source include/restart_mysqld_with_option.inc select create_time=(select create_time from t2) /* should change */, @@ -139,3 +146,17 @@ from information_schema.tables where table_schema=database() and table_name='t1'; drop table t1, t2; + +--echo # +--echo # Check how it works for partitioned tables +--echo # +create table t1 (pk int primary key) partition by hash(pk) partitions 2; +insert into t1 values (1); + +select create_time IS NOT NULL , update_time IS NOT NULL +from information_schema.tables +where table_schema=database() and table_name='t1'; +drop table t1; + +--let $_mysqld_option= +--source include/restart_mysqld.inc diff --git a/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_table_dictionary_format_basic.result b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_table_dictionary_format_basic.result index 825d7a7113a..c64a31f6e96 100644 --- a/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_table_dictionary_format_basic.result +++ b/mysql-test/suite/rocksdb_sys_vars/r/rocksdb_table_dictionary_format_basic.result @@ -6,7 +6,7 @@ INSERT INTO invalid_values VALUES('\'aaa\''); SET @start_global_value = @@global.ROCKSDB_TABLE_DICTIONARY_FORMAT; SELECT @start_global_value; @start_global_value -2 +1 "Trying to set variable @@global.ROCKSDB_TABLE_DICTIONARY_FORMAT to 444. It should fail because it is readonly." SET @@global.ROCKSDB_TABLE_DICTIONARY_FORMAT = 444; ERROR HY000: Variable 'rocksdb_table_dictionary_format' is a read only variable diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc index 234f7a789ff..ceb23bbdd06 100644 --- a/storage/rocksdb/rdb_datadic.cc +++ b/storage/rocksdb/rdb_datadic.cc @@ -3517,17 +3517,23 @@ bool Rdb_tbl_def::put_dict(Rdb_dict_manager *const dict, Rdb_key_def::TABLE_CREATE_TIMESTAMP_SIZE + m_key_count * Rdb_key_def::PACKED_SIZE * 2); - if (rocksdb_table_dictionary_format < - ROCKSDB_DATADIC_FORMAT_CREATE_TIMESTAMP) { - rdb_netstr_append_uint16(&indexes, Rdb_key_def::DDL_ENTRY_INDEX_VERSION_1); - // We are using old data format, which means we cannot save Create_time - // Set it to be shown as unknown right away, so that the behavior before - // server restart and after is the same. - set_create_time(0); - } - else { - rdb_netstr_append_uint16(&indexes, Rdb_key_def::DDL_ENTRY_INDEX_VERSION_2); - rdb_netstr_append_uint64(&indexes, create_time); + switch (rocksdb_table_dictionary_format) { + case ROCKSDB_DATADIC_FORMAT_INITIAL: + rdb_netstr_append_uint16(&indexes, Rdb_key_def::DDL_ENTRY_INDEX_VERSION_1); + // We are using old data format, which means we cannot save Create_time + // Set it to be shown as unknown right away, so that the behavior before + // server restart and after is the same. + set_create_time(0); + break; + case ROCKSDB_DATADIC_FORMAT_CREATE_TIMESTAMP: + rdb_netstr_append_uint16(&indexes, Rdb_key_def::DDL_ENTRY_INDEX_VERSION_2); + rdb_netstr_append_uint64(&indexes, create_time); + break; + default: + DBUG_ASSERT(0); + rdb_netstr_append_uint16(&indexes, Rdb_key_def::DDL_ENTRY_INDEX_VERSION_1); + set_create_time(0); + break; } for (uint i = 0; i < m_key_count; i++) { @@ -4068,6 +4074,7 @@ bool Rdb_ddl_manager::init(Rdb_dict_manager *const dict_arg, // NO_LINT_DEBUG sql_print_error("RocksDB: Table_store: invalid keylist for table %s", tdef->full_tablename().c_str()); + delete tdef; return true; } tdef->m_key_count = real_val_size / (Rdb_key_def::PACKED_SIZE * 2); @@ -4087,6 +4094,7 @@ bool Rdb_ddl_manager::init(Rdb_dict_manager *const dict_arg, "for Index Number (%u,%u), table %s", gl_index_id.cf_id, gl_index_id.index_id, tdef->full_tablename().c_str()); + delete tdef; return true; } if (max_index_id_in_dict < gl_index_id.index_id) { @@ -4096,6 +4104,7 @@ bool Rdb_ddl_manager::init(Rdb_dict_manager *const dict_arg, "but also found larger index id %u from dictionary. " "This should never happen and possibly a bug.", max_index_id_in_dict, gl_index_id.index_id); + delete tdef; return true; } if (!m_dict->get_cf_flags(gl_index_id.cf_id, &flags)) { @@ -4104,6 +4113,7 @@ bool Rdb_ddl_manager::init(Rdb_dict_manager *const dict_arg, "RocksDB: Could not get Column Family Flags " "for CF Number %d, table %s", gl_index_id.cf_id, tdef->full_tablename().c_str()); + delete tdef; return true; } diff --git a/storage/rocksdb/rdb_datadic.h b/storage/rocksdb/rdb_datadic.h index 9c2a96e77b7..4e10e772ecf 100644 --- a/storage/rocksdb/rdb_datadic.h +++ b/storage/rocksdb/rdb_datadic.h @@ -216,7 +216,7 @@ const uint ROCKSDB_DATADIC_FORMAT_CREATE_TIMESTAMP = 2; // Maximum possible value: const uint ROCKSDB_DATADIC_FORMAT_MAX = 2; -const uint ROCKSDB_DATADIC_FORMAT_DEFAULT = ROCKSDB_DATADIC_FORMAT_MAX; +const uint ROCKSDB_DATADIC_FORMAT_DEFAULT = ROCKSDB_DATADIC_FORMAT_INITIAL; /* @@ -523,9 +523,11 @@ class Rdb_key_def { // Data dictionary schema version. Introduce newer versions // if changing schema layout enum { + // Used when rocksdb_table_dictionary_format=ROCKSDB_DATADIC_FORMAT_INITIAL DDL_ENTRY_INDEX_VERSION_1 = 1, - // this includes a 64-bit table_creation_time at the end. - // Allowed since ROCKSDB_DATADIC_FORMAT_CREATE_TIMESTAMP. + + // Used when rocksdb_table_dictionary_format= + // ROCKSDB_DATADIC_FORMAT_CREATE_TIMESTAMP DDL_ENTRY_INDEX_VERSION_2 = 2, CF_DEFINITION_VERSION = 1, BINLOG_INFO_INDEX_NUMBER_VERSION = 1, @@ -1370,9 +1372,11 @@ class Rdb_binlog_manager { 1. Table Name => internal index id mappings key: Rdb_key_def::DDL_ENTRY_INDEX_START_NUMBER(0x1) + dbname.tablename - value: DDL_ENTRY_INDEX_VERSION_1, {cf_id, index_id}*n_indexes_of_the_table - or value: DDL_ENTRY_INDEX_VERSION_2, create_timestamp, {cf_id, index_id}* - n_indexes_of_the_table + value has two versions: + version=DDL_ENTRY_INDEX_VERSION_1, {cf_id, index_id}*n_indexes_of_the_table. + version=DDL_ENTRY_INDEX_VERSION_2, create_timestamp, {cf_id, index_id}* + n_indexes_of_the_table. + version is 2 bytes. cf_id and index_id are 4 bytes. create_timestamp is 8 bytes.
participants (1)
-
psergey