From ddc1d6904a8852d6584a8fb7721de78d56bd454e Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 8 Dec 2017 16:41:51 +0300 Subject: [PATCH] MDEV-14123: .rocksdb folder may break workflow which re-create data directory Part2: make MyRocks add its directory into @@ignore_db_dirs when starting. This is necessary because apparently not everybody are using plugin's my.cnf So load ha_rocksdb.{so,dll} manually and then hit MDEV-12451, MDEV-14461 etc. --- sql/sql_show.cc | 51 +++++++++++++++++++ storage/rocksdb/ha_rocksdb.cc | 10 ++++ .../rocksdb/r/mariadb_ignore_dirs.result | 9 ++++ storage/rocksdb/mysql-test/rocksdb/suite.opt | 2 +- .../rocksdb/t/mariadb_ignore_dirs.test | 17 +++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 storage/rocksdb/mysql-test/rocksdb/r/mariadb_ignore_dirs.result create mode 100644 storage/rocksdb/mysql-test/rocksdb/t/mariadb_ignore_dirs.test diff --git a/sql/sql_show.cc b/sql/sql_show.cc index de9d7d77dc8..f63d4a2d4f4 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -787,6 +787,57 @@ static void dispose_db_dir(void *ptr) } +/* + Append an element into @@ignore_db_dirs + + This is a function to be called after regular option processing has been + finalized. +*/ + +void ignore_db_dirs_append(const char *dirname_arg) +{ + char *new_entry_buf; + LEX_STRING *new_entry; + size_t len= strlen(dirname_arg); + + if (!my_multi_malloc(0, + &new_entry, sizeof(LEX_STRING), + &new_entry_buf, len + 1, + NullS)) + return; + + memcpy(new_entry_buf, dirname_arg, len+1); + new_entry->str = new_entry_buf; + new_entry->length= len; + + if (my_hash_insert(&ignore_db_dirs_hash, (uchar *)new_entry)) + { + // Either the name is already there or out-of-memory. + my_free(new_entry); + return; + } + + // Append the name to the option string. + size_t curlen= strlen(opt_ignore_db_dirs); + // Add one for comma and one for \0. + size_t newlen= curlen + len + 1 + 1; + char *new_db_dirs; + if (!(new_db_dirs= (char*)my_malloc(newlen ,MYF(0)))) + { + // This is not a critical condition + return; + } + + memcpy(new_db_dirs, opt_ignore_db_dirs, curlen); + if (curlen != 0) + new_db_dirs[curlen]=','; + memcpy(new_db_dirs + (curlen + ((curlen!=0)?1:0)), dirname_arg, len+1); + + if (opt_ignore_db_dirs) + my_free(opt_ignore_db_dirs); + opt_ignore_db_dirs= new_db_dirs; +} + bool ignore_db_dirs_process_additions() { diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 3613634f344..e08329ab61e 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -111,6 +111,10 @@ bool thd_binlog_filter_ok(const MYSQL_THD thd); MYSQL_PLUGIN_IMPORT bool my_disable_leak_check; +// Needed in rocksdb_init_func +void ignore_db_dirs_append(const char *dirname_arg); + + namespace myrocks { static st_global_stats global_stats; @@ -3934,6 +3938,7 @@ static rocksdb::Status check_rocksdb_options_compatibility( return status; } + /* Storage Engine initialization function, invoked when plugin is loaded. */ @@ -3962,6 +3967,11 @@ static int rocksdb_init_func(void *const p) { mysql_mutex_init(rdb_mem_cmp_space_mutex_key, &rdb_mem_cmp_space_mutex, MY_MUTEX_INIT_FAST); + const char* initial_rocksdb_datadir_for_ignore_dirs= rocksdb_datadir; + if (!strncmp(rocksdb_datadir, "./", 2)) + initial_rocksdb_datadir_for_ignore_dirs += 2; + ignore_db_dirs_append(initial_rocksdb_datadir_for_ignore_dirs); + #if defined(HAVE_PSI_INTERFACE) rdb_collation_exceptions = new Regex_list_handler(key_rwlock_collation_exception_list); diff --git a/storage/rocksdb/mysql-test/rocksdb/r/mariadb_ignore_dirs.result b/storage/rocksdb/mysql-test/rocksdb/r/mariadb_ignore_dirs.result new file mode 100644 index 00000000000..9b91cdb5551 --- /dev/null +++ b/storage/rocksdb/mysql-test/rocksdb/r/mariadb_ignore_dirs.result @@ -0,0 +1,9 @@ +# +# RocksDB plugin adds #rocksdb to ignore_db_dirs +# +select @@ignore_db_dirs; +@@ignore_db_dirs +#rocksdb +select @@ignore_db_dirs; +@@ignore_db_dirs +aa,bbb,#rocksdb diff --git a/storage/rocksdb/mysql-test/rocksdb/suite.opt b/storage/rocksdb/mysql-test/rocksdb/suite.opt index 3829658ab1c..22c9d7a300e 100644 --- a/storage/rocksdb/mysql-test/rocksdb/suite.opt +++ b/storage/rocksdb/mysql-test/rocksdb/suite.opt @@ -1,2 +1,2 @@ ---ignore-db-dirs=#rocksdb --plugin-load=$HA_ROCKSDB_SO --default-storage-engine=rocksdb +--plugin-load=$HA_ROCKSDB_SO --default-storage-engine=rocksdb diff --git a/storage/rocksdb/mysql-test/rocksdb/t/mariadb_ignore_dirs.test b/storage/rocksdb/mysql-test/rocksdb/t/mariadb_ignore_dirs.test new file mode 100644 index 00000000000..49591dd612a --- /dev/null +++ b/storage/rocksdb/mysql-test/rocksdb/t/mariadb_ignore_dirs.test @@ -0,0 +1,17 @@ +--source include/have_rocksdb.inc + + +--echo # +--echo # RocksDB plugin adds #rocksdb to ignore_db_dirs +--echo # + +select @@ignore_db_dirs; + +--let $_mysqld_option=--ignore-db-dirs=aa --ignore-db-dirs=bbb +--source include/restart_mysqld_with_option.inc + +select @@ignore_db_dirs; + +--let $_mysqld_option=--ignore-db-dirs=#rocksdb +--source include/restart_mysqld_with_option.inc +