Skip to content

Commit 65149f3

Browse files
sunshine-Chunfacebook-github-bot
authored andcommitted
Address comments for 'Apply sst file manager in myrocks clone' (#1388)
Summary: This change is to address the comments of Apply sst file manager in myrocks clone to add slow-rm during checkpoints removal (#1386). Will squash after commit. Pull Request resolved: #1388 Differential Revision: D51107316 fbshipit-source-id: 69903b786972f8754afac7f3d8697d162266d34f
1 parent 0063ae7 commit 65149f3

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

storage/rocksdb/clone/donor.cc

Lines changed: 15 additions & 17 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,9 +68,8 @@ class [[nodiscard]] rdb_checkpoint final {
6868
// Returns MySQL error code
6969
[[nodiscard]] int init() {
7070
assert(!m_active);
71-
m_full_dir = make_dir_full_name(
72-
m_dir.c_str(), m_next_sub_id.fetch_add(1, std::memory_order_relaxed));
73-
const auto result = myrocks::rocksdb_create_checkpoint(m_full_dir.c_str());
71+
m_dir = make_dir_name(m_prefix_dir, m_next_sub_id++);
72+
const auto result = myrocks::rocksdb_create_checkpoint(m_dir.c_str());
7473
m_active = (result == HA_EXIT_SUCCESS);
7574
return m_active ? 0 : ER_INTERNAL_ERROR;
7675
}
@@ -79,22 +78,21 @@ class [[nodiscard]] rdb_checkpoint final {
7978
[[nodiscard]] int cleanup() {
8079
if (!m_active) return 0;
8180
m_active = false;
82-
return myrocks::rocksdb_remove_checkpoint(m_full_dir.c_str()) ==
83-
HA_EXIT_SUCCESS
81+
return myrocks::rocksdb_remove_checkpoint(m_dir.c_str()) == HA_EXIT_SUCCESS
8482
? 0
8583
: ER_INTERNAL_ERROR;
8684
}
8785

8886
[[nodiscard]] constexpr const std::string &get_dir() const noexcept {
8987
assert(m_active);
90-
return m_full_dir;
88+
return m_dir;
9189
}
9290

9391
[[nodiscard]] std::string path(const std::string &file_name) const {
9492
// We might be calling this for inactive checkpoint too, if the donor is in
9593
// the middle of a checkpoint roll. The caller will handle any ENOENTs as
9694
// needed.
97-
return myrocks::rdb_concat_paths(m_full_dir, file_name);
95+
return myrocks::rdb_concat_paths(m_dir, file_name);
9896
}
9997

10098
rdb_checkpoint(const rdb_checkpoint &) = delete;
@@ -103,17 +101,17 @@ class [[nodiscard]] rdb_checkpoint final {
103101
rdb_checkpoint &operator=(rdb_checkpoint &&) = delete;
104102

105103
private:
106-
const std::string m_dir;
104+
const std::string m_prefix_dir;
107105

108-
std::string m_full_dir;
106+
std::string m_dir;
109107

110108
bool m_active = false;
111109

112110
static std::atomic<std::uint64_t> m_next_id;
113111

114-
std::atomic<std::uint64_t> m_next_sub_id{1};
112+
std::uint64_t m_next_sub_id = 1;
115113

116-
[[nodiscard]] static std::string make_dir_name(std::uint64_t id) {
114+
[[nodiscard]] static std::string make_dir_prefix_name(std::uint64_t id) {
117115
const auto base_str = myrocks::clone::checkpoint_base_dir();
118116
const auto id_str = std::to_string(id);
119117
std::string result;
@@ -128,14 +126,14 @@ class [[nodiscard]] rdb_checkpoint final {
128126
return result;
129127
}
130128

131-
[[nodiscard]] static std::string make_dir_full_name(std::string base_dir,
132-
std::uint64_t id) {
129+
[[nodiscard]] static std::string make_dir_name(
130+
const std::string &dir_name_prefix, std::uint64_t id) {
133131
const auto id_str = std::to_string(id);
134132
std::string result;
135-
result.reserve(base_dir.length() + id_str.length() +
133+
result.reserve(dir_name_prefix.length() + id_str.length() +
136134
1); // +1 for '-', the trailing
137135
// '\0' is accounted by the sizeof.
138-
result = base_dir;
136+
result = dir_name_prefix;
139137
result += '-';
140138
result += id_str;
141139
return result;

storage/rocksdb/ha_rocksdb.cc

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,26 @@ static void rocksdb_set_reset_stats(
12901290
RDB_MUTEX_UNLOCK_CHECK(rdb_sysvars_mutex);
12911291
}
12921292

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

12951315
static void rocksdb_set_io_write_timeout(
@@ -1310,27 +1330,6 @@ static void rocksdb_set_io_write_timeout(
13101330
RDB_MUTEX_UNLOCK_CHECK(rdb_sysvars_mutex);
13111331
}
13121332

1313-
int rocksdb_remove_checkpoint(const char *checkpoint_dir_raw) {
1314-
const auto checkpoint_dir = rdb_normalize_dir(checkpoint_dir_raw);
1315-
LogPluginErrMsg(INFORMATION_LEVEL, ER_LOG_PRINTF_MSG,
1316-
"deleting temporary checkpoint in directory : %s\n",
1317-
checkpoint_dir.c_str());
1318-
1319-
std::string trash_dir = std::string(rocksdb_datadir) + "/trash";
1320-
rocksdb::Options op = rocksdb::Options();
1321-
op.sst_file_manager.reset(NewSstFileManager(
1322-
rocksdb_db_options->env, rocksdb_db_options->info_log, trash_dir,
1323-
rocksdb_sst_mgr_rate_bytes_per_sec, true /* delete_existing_trash */));
1324-
const auto status = rocksdb::DestroyDB(checkpoint_dir, op);
1325-
1326-
if (status.ok()) {
1327-
return HA_EXIT_SUCCESS;
1328-
}
1329-
my_error(ER_GET_ERRMSG, MYF(0), status.code(), status.ToString().c_str(),
1330-
rocksdb_hton_name);
1331-
return HA_EXIT_FAILURE;
1332-
}
1333-
13341333
#endif // !__APPLE__
13351334

13361335
enum rocksdb_flush_log_at_trx_commit_type : unsigned int {

0 commit comments

Comments
 (0)