summaryrefslogtreecommitdiff
path: root/storage/rocksdb
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2018-06-07 15:12:26 +0100
committerVladislav Vaintroub <wlad@mariadb.com>2018-06-07 15:12:26 +0100
commitea70586282d902fe067cee11a5aeb7086ed375f8 (patch)
treeabd6a47b72d9efd2e236c89cae35b54398096026 /storage/rocksdb
parentdc9c555415b1d37b713839b9f8143a053f402c0e (diff)
downloadmariadb-git-ea70586282d902fe067cee11a5aeb7086ed375f8.tar.gz
MDEV-16300 : remove rocksdb checkpoint created by mariabackup.
Add variable rocksdb_remove_mariabackup_checkpoint. If set, it will remove $rocksdb_datadir/mariabackup-checkpoint directory. The variable is to be used by exclusively by mariabackup, to remove temporary checkpoints.
Diffstat (limited to 'storage/rocksdb')
-rw-r--r--storage/rocksdb/ha_rocksdb.cc69
-rw-r--r--storage/rocksdb/mysql-test/rocksdb/r/rocksdb.result1
-rw-r--r--storage/rocksdb/mysql-test/rocksdb_sys_vars/r/rocksdb_remove_mariabackup_checkpoint_basic.result4
-rw-r--r--storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_remove_mariabackup_checkpoint_basic.test5
4 files changed, 78 insertions, 1 deletions
diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc
index 96bc7dad3e6..7cddfea33a7 100644
--- a/storage/rocksdb/ha_rocksdb.cc
+++ b/storage/rocksdb/ha_rocksdb.cc
@@ -479,6 +479,7 @@ static uint32_t rocksdb_access_hint_on_compaction_start;
static char *rocksdb_compact_cf_name;
static char *rocksdb_checkpoint_name;
static my_bool rocksdb_signal_drop_index_thread;
+static my_bool rocksdb_signal_remove_mariabackup_checkpoint;
static my_bool rocksdb_strict_collation_check = 1;
static my_bool rocksdb_ignore_unknown_options = 1;
static my_bool rocksdb_enable_2pc = 0;
@@ -515,6 +516,67 @@ std::atomic<uint64_t> rocksdb_row_lock_wait_timeouts(0);
std::atomic<uint64_t> rocksdb_snapshot_conflict_errors(0);
std::atomic<uint64_t> rocksdb_wal_group_syncs(0);
+
+
+/*
+ Remove directory with files in it.
+ Used to remove checkpoint created by mariabackup.
+*/
+#ifdef _WIN32
+#include <direct.h> /* unlink*/
+#ifndef F_OK
+#define F_OK 0
+#endif
+#endif
+
+static int rmdir_force(const char *dir) {
+ if (access(dir, F_OK))
+ return true;
+
+ char path[FN_REFLEN];
+ char sep[] = {FN_LIBCHAR, 0};
+ int err = 0;
+
+ MY_DIR *dir_info = my_dir(dir, MYF(MY_DONT_SORT | MY_WANT_STAT));
+ if (!dir_info)
+ return 1;
+
+ for (uint i = 0; i < dir_info->number_of_files; i++) {
+ FILEINFO *file = dir_info->dir_entry + i;
+
+ strxnmov(path, sizeof(path), dir, sep, file->name, NULL);
+
+ err = my_delete(path, 0);
+
+ if (err) {
+ break;
+ }
+ }
+
+ my_dirend(dir_info);
+
+ if (!err)
+ err = rmdir(dir);
+
+ return (err == 0) ? HA_EXIT_SUCCESS : HA_EXIT_FAILURE;
+}
+
+
+static void rocksdb_remove_mariabackup_checkpoint(
+ my_core::THD *const,
+ struct st_mysql_sys_var *const ,
+ void *const var_ptr, const void *const) {
+ std::string mariabackup_checkpoint_dir(rocksdb_datadir);
+
+ mariabackup_checkpoint_dir.append("/mariabackup-checkpoint");
+
+ if (unlink(mariabackup_checkpoint_dir.c_str()) == 0)
+ return;
+
+ rmdir_force(mariabackup_checkpoint_dir.c_str());
+}
+
+
static std::unique_ptr<rocksdb::DBOptions> rdb_init_rocksdb_db_options(void) {
auto o = std::unique_ptr<rocksdb::DBOptions>(new rocksdb::DBOptions());
@@ -1312,6 +1374,11 @@ static MYSQL_SYSVAR_STR(create_checkpoint, rocksdb_checkpoint_name,
rocksdb_create_checkpoint,
rocksdb_create_checkpoint_stub, "");
+static MYSQL_SYSVAR_BOOL(remove_mariabackup_checkpoint,
+ rocksdb_signal_remove_mariabackup_checkpoint,
+ PLUGIN_VAR_RQCMDARG, "Remove mariabackup checkpoint",
+ nullptr, rocksdb_remove_mariabackup_checkpoint, FALSE);
+
static MYSQL_SYSVAR_BOOL(signal_drop_index_thread,
rocksdb_signal_drop_index_thread, PLUGIN_VAR_RQCMDARG,
"Wake up drop index thread", nullptr,
@@ -1675,7 +1742,7 @@ static struct st_mysql_sys_var *rocksdb_system_variables[] = {
MYSQL_SYSVAR(datadir),
MYSQL_SYSVAR(supported_compression_types),
MYSQL_SYSVAR(create_checkpoint),
-
+ MYSQL_SYSVAR(remove_mariabackup_checkpoint),
MYSQL_SYSVAR(checksums_pct),
MYSQL_SYSVAR(store_row_debug_checksums),
MYSQL_SYSVAR(verify_row_debug_checksums),
diff --git a/storage/rocksdb/mysql-test/rocksdb/r/rocksdb.result b/storage/rocksdb/mysql-test/rocksdb/r/rocksdb.result
index 6138dac92e5..dc13bb375b8 100644
--- a/storage/rocksdb/mysql-test/rocksdb/r/rocksdb.result
+++ b/storage/rocksdb/mysql-test/rocksdb/r/rocksdb.result
@@ -959,6 +959,7 @@ rocksdb_print_snapshot_conflict_queries OFF
rocksdb_rate_limiter_bytes_per_sec 0
rocksdb_read_free_rpl_tables
rocksdb_records_in_range 50
+rocksdb_remove_mariabackup_checkpoint OFF
rocksdb_reset_stats OFF
rocksdb_seconds_between_stat_computes 3600
rocksdb_signal_drop_index_thread OFF
diff --git a/storage/rocksdb/mysql-test/rocksdb_sys_vars/r/rocksdb_remove_mariabackup_checkpoint_basic.result b/storage/rocksdb/mysql-test/rocksdb_sys_vars/r/rocksdb_remove_mariabackup_checkpoint_basic.result
new file mode 100644
index 00000000000..01145cd2ab8
--- /dev/null
+++ b/storage/rocksdb/mysql-test/rocksdb_sys_vars/r/rocksdb_remove_mariabackup_checkpoint_basic.result
@@ -0,0 +1,4 @@
+SET GLOBAL rocksdb_create_checkpoint=CONCAT(@@rocksdb_datadir,'/mariabackup-checkpoint');
+SET GLOBAL rocksdb_remove_mariabackup_checkpoint=ON;
+SET GLOBAL rocksdb_create_checkpoint=CONCAT(@@rocksdb_datadir,'/mariabackup-checkpoint');
+SET GLOBAL rocksdb_remove_mariabackup_checkpoint=ON;
diff --git a/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_remove_mariabackup_checkpoint_basic.test b/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_remove_mariabackup_checkpoint_basic.test
new file mode 100644
index 00000000000..30f38283ba4
--- /dev/null
+++ b/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_remove_mariabackup_checkpoint_basic.test
@@ -0,0 +1,5 @@
+# Simulate creating and removing mariabackup checkpoint twice
+SET GLOBAL rocksdb_create_checkpoint=CONCAT(@@rocksdb_datadir,'/mariabackup-checkpoint');
+SET GLOBAL rocksdb_remove_mariabackup_checkpoint=ON;
+SET GLOBAL rocksdb_create_checkpoint=CONCAT(@@rocksdb_datadir,'/mariabackup-checkpoint');
+SET GLOBAL rocksdb_remove_mariabackup_checkpoint=ON;