Skip to content

Commit 36a4edb

Browse files
sunshine-Chuninikep
authored andcommitted
Apply sst file manager in myrocks clone to add slow-rm during checkpoints removal (facebook#1386)
Summary: This diff makes the following two changes: 1. Clone use rocksdb::DestroyDB() to clean the checkpoint. However, we didn't pass the sst file manager so didn't make use of the slow-rm feature provided by sst file manager. This will lead up to a discard spike when rolling checkpoints. This change pass the sst file manager when cleaning checkpoints. 2. During slow-rm sst files, the checkpoint directory may not be deleted immediately. In the rolling checkpoint function call, we will first delete the checkpoint directory, then create a new one with the same name. Since we are slow removing the sst files, it's possible that when we create the new checkpoints, the old directory hasn't been deleted yet. This will cause a 'directory exist' error when creating a new checkpoint directory. In this change, we add an additional suffix to differentiate rolling checkpoints directory to avoid this error. Pull Request resolved: facebook#1386 Test Plan: Imported from GitHub, without a `Test Plan:` line. Directory creation and deletion test is covered by `rolling_checkpoint.test`. Did additional cp_clone to verify the correctness. ``` [root@udb18397.ftw5 /var/log]# less mysqld-3301.log | grep '.clone_checkpoint-1-' 2023-11-02T11:49:43.142720-07:00 1355 [Note] [MY-011071] [Server] Plugin rocksdb reported: 'creating checkpoint in directory: /data/mysql/3301/.rocksdb/.clone_checkpoint-1-1 ' 2023-11-02T11:49:46.671314-07:00 1355 [Note] [MY-011071] [Server] Plugin rocksdb reported: 'created checkpoint in directory: /data/mysql/3301/.rocksdb/.clone_checkpoint-1-1 ' 2023-11-02T11:58:20.464175-07:00 1355 [Note] [MY-011071] [Server] Plugin rocksdb reported: 'deleting temporary checkpoint in directory : /data/mysql/3301/.rocksdb/.clone_checkpoint-1-1 ' 2023-11-02T11:58:20.753155-07:00 1355 [Note] [MY-011071] [Server] Plugin rocksdb reported: 'creating checkpoint in directory: /data/mysql/3301/.rocksdb/.clone_checkpoint-1-2 ' 2023-11-02T11:58:22.045484-07:00 1355 [Note] [MY-011071] [Server] Plugin rocksdb reported: 'created checkpoint in directory: /data/mysql/3301/.rocksdb/.clone_checkpoint-1-2 ' 2023-11-02T11:58:23.794134-07:00 1355 [Note] [MY-011071] [Server] Plugin rocksdb reported: 'deleting temporary checkpoint in directory : /data/mysql/3301/.rocksdb/.clone_checkpoint-1-2 ' ``` Differential Revision: D50938261
1 parent 688a4c7 commit 36a4edb

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

storage/rocksdb/clone/donor.cc

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ namespace {
5656
class [[nodiscard]] rdb_checkpoint final {
5757
public:
5858
rdb_checkpoint()
59-
: m_dir{
60-
make_dir_name(m_next_id.fetch_add(1, std::memory_order_relaxed))} {}
59+
: m_prefix_dir{make_dir_prefix_name(
60+
m_next_id.fetch_add(1, std::memory_order_relaxed))} {}
6161

6262
~rdb_checkpoint() {
6363
// Ignore the return value - at this point the clone operation is completing
@@ -68,6 +68,7 @@ class [[nodiscard]] rdb_checkpoint final {
6868
// Returns MySQL error code
6969
[[nodiscard]] int init() {
7070
assert(!m_active);
71+
m_dir = make_dir_name(m_prefix_dir, m_next_sub_id++);
7172
const auto result = myrocks::rocksdb_create_checkpoint(m_dir.c_str());
7273
m_active = (result == HA_EXIT_SUCCESS);
7374
return m_active ? 0 : ER_INTERNAL_ERROR;
@@ -100,13 +101,17 @@ class [[nodiscard]] rdb_checkpoint final {
100101
rdb_checkpoint &operator=(rdb_checkpoint &&) = delete;
101102

102103
private:
103-
const std::string m_dir;
104+
const std::string m_prefix_dir;
105+
106+
std::string m_dir;
104107

105108
bool m_active = false;
106109

107110
static std::atomic<std::uint64_t> m_next_id;
108111

109-
[[nodiscard]] static std::string make_dir_name(std::uint64_t id) {
112+
std::uint64_t m_next_sub_id = 1;
113+
114+
[[nodiscard]] static std::string make_dir_prefix_name(std::uint64_t id) {
110115
const auto base_str = myrocks::clone::checkpoint_base_dir();
111116
const auto id_str = std::to_string(id);
112117
std::string result;
@@ -120,6 +125,19 @@ class [[nodiscard]] rdb_checkpoint final {
120125
result += id_str;
121126
return result;
122127
}
128+
129+
[[nodiscard]] static std::string make_dir_name(
130+
const std::string &dir_name_prefix, std::uint64_t id) {
131+
const auto id_str = std::to_string(id);
132+
std::string result;
133+
result.reserve(dir_name_prefix.length() + id_str.length() +
134+
1); // +1 for '-', the trailing
135+
// '\0' is accounted by the sizeof.
136+
result = dir_name_prefix;
137+
result += '-';
138+
result += id_str;
139+
return result;
140+
}
123141
};
124142

125143
std::atomic<std::uint64_t> rdb_checkpoint::m_next_id{1};

storage/rocksdb/ha_rocksdb.cc

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,6 @@ int rocksdb_create_checkpoint(const char *checkpoint_dir_raw) {
475475
return HA_EXIT_FAILURE;
476476
}
477477

478-
int rocksdb_remove_checkpoint(const char *checkpoint_dir_raw) {
479-
const auto checkpoint_dir = rdb_normalize_dir(checkpoint_dir_raw);
480-
LogPluginErrMsg(INFORMATION_LEVEL, ER_LOG_PRINTF_MSG,
481-
"deleting temporary checkpoint in directory : %s\n",
482-
checkpoint_dir.c_str());
483-
const auto status = rocksdb::DestroyDB(checkpoint_dir, rocksdb::Options());
484-
if (status.ok()) {
485-
return HA_EXIT_SUCCESS;
486-
}
487-
my_error(ER_GET_ERRMSG, MYF(0), status.code(), status.ToString().c_str(),
488-
rocksdb_hton_name);
489-
return HA_EXIT_FAILURE;
490-
}
491-
492478
static int rocksdb_create_checkpoint_validate(
493479
THD *const thd MY_ATTRIBUTE((__unused__)),
494480
struct SYS_VAR *const var MY_ATTRIBUTE((__unused__)),
@@ -1301,6 +1287,26 @@ static void rocksdb_set_reset_stats(
13011287
RDB_MUTEX_UNLOCK_CHECK(rdb_sysvars_mutex);
13021288
}
13031289

1290+
int rocksdb_remove_checkpoint(const char *checkpoint_dir_raw) {
1291+
const auto checkpoint_dir = rdb_normalize_dir(checkpoint_dir_raw);
1292+
LogPluginErrMsg(INFORMATION_LEVEL, ER_LOG_PRINTF_MSG,
1293+
"deleting temporary checkpoint in directory : %s\n",
1294+
checkpoint_dir.c_str());
1295+
1296+
auto op = rocksdb::Options();
1297+
op.sst_file_manager.reset(NewSstFileManager(
1298+
rocksdb_db_options->env, rocksdb_db_options->info_log, "",
1299+
rocksdb_sst_mgr_rate_bytes_per_sec, false /* delete_existing_trash */));
1300+
const auto status = rocksdb::DestroyDB(checkpoint_dir, op);
1301+
1302+
if (status.ok()) {
1303+
return HA_EXIT_SUCCESS;
1304+
}
1305+
my_error(ER_GET_ERRMSG, MYF(0), status.code(), status.ToString().c_str(),
1306+
rocksdb_hton_name);
1307+
return HA_EXIT_FAILURE;
1308+
}
1309+
13041310
#ifndef __APPLE__
13051311

13061312
static void rocksdb_set_io_write_timeout(

0 commit comments

Comments
 (0)