From 23ec3e07c84c42162c56e7b5d9345fa29a72f9b4 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Tue, 19 Jan 2021 15:07:16 +0100 Subject: [PATCH] tools/bluestore: Add command 'show-sharding' to ceph-bluestore-tool Add command 'show-sharding' to ceph-bluestore-tool. Signed-off-by: Adam Kupczyk (cherry picked from commit 882714e0c90e7c2492af47adf885141e57aee783) --- doc/man/8/ceph-bluestore-tool.rst | 5 +++++ src/kv/RocksDBStore.cc | 19 +++++++++++++++++++ src/kv/RocksDBStore.h | 2 +- src/os/bluestore/bluestore_tool.cc | 28 ++++++++++++++++++++++------ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/doc/man/8/ceph-bluestore-tool.rst b/doc/man/8/ceph-bluestore-tool.rst index 2a1813e6968..bb67ccc71e7 100644 --- a/doc/man/8/ceph-bluestore-tool.rst +++ b/doc/man/8/ceph-bluestore-tool.rst @@ -24,6 +24,7 @@ Synopsis | **ceph-bluestore-tool** bluefs-bdev-migrate --path *osd path* --dev-target *new-device* --devs-source *device1* [--devs-source *device2*] | **ceph-bluestore-tool** free-dump|free-score --path *osd path* [ --allocator block/bluefs-wal/bluefs-db/bluefs-slow ] | **ceph-bluestore-tool** reshard --path *osd path* --sharding *new sharding* [ --sharding-ctrl *control string* ] +| **ceph-bluestore-tool** show-sharding --path *osd path* Description @@ -109,6 +110,10 @@ Commands Interrupted resharding does not corrupt data. It is always possible to continue previous resharding, or select any other sharding scheme, including reverting to original one. +:command:`show-sharding` --path *osd path* + + Show sharding that is currently applied to BlueStore's RocksDB. + Options ======= diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index c121734efaf..b7fa258638f 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -3330,3 +3330,22 @@ int RocksDBStore::reshard(const std::string& new_sharding, const RocksDBStore::r return r; } + +bool RocksDBStore::get_sharding(std::string& sharding) { + rocksdb::Status status; + std::string stored_sharding_text; + bool result = false; + sharding.clear(); + + status = env->FileExists(sharding_def_file); + if (status.ok()) { + status = rocksdb::ReadFileToString(env, + sharding_def_file, + &stored_sharding_text); + if(status.ok()) { + result = true; + sharding = stored_sharding_text; + } + } + return result; +} diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 969fe5bfe46..0735e115c36 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -516,7 +516,7 @@ public: bool unittest_fail_after_successful_processing = false; }; int reshard(const std::string& new_sharding, const resharding_ctrl* ctrl = nullptr); - + bool get_sharding(std::string& sharding); }; diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index 275f73c4c5f..12293fdfd1b 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -275,7 +275,8 @@ int main(int argc, char **argv) "free-dump, " "free-score, " "bluefs-stats, " - "reshard") + "reshard, " + "show-sharding") ; po::options_description po_all("All options"); po_all.add(po_options).add(po_positional); @@ -942,12 +943,8 @@ int main(int argc, char **argv) cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl; exit(EXIT_FAILURE); } - if (r < 0) { - cerr << "error starting k-v inside bluestore: " << cpp_strerror(r) << std::endl; - exit(EXIT_FAILURE); - } - RocksDBStore* rocks_db = dynamic_cast(db_ptr); ceph_assert(db_ptr); + RocksDBStore* rocks_db = dynamic_cast(db_ptr); ceph_assert(rocks_db); r = rocks_db->reshard(new_sharding, &ctrl); if (r < 0) { @@ -956,6 +953,25 @@ int main(int argc, char **argv) cout << "reshard success" << std::endl; } bluestore.close_db_environment(); + } else if (action == "show-sharding") { + BlueStore bluestore(cct.get(), path); + KeyValueDB *db_ptr; + int r = bluestore.open_db_environment(&db_ptr, false); + if (r < 0) { + cerr << "error preparing db environment: " << cpp_strerror(r) << std::endl; + exit(EXIT_FAILURE); + } + ceph_assert(db_ptr); + RocksDBStore* rocks_db = dynamic_cast(db_ptr); + ceph_assert(rocks_db); + std::string sharding; + bool res = rocks_db->get_sharding(sharding); + bluestore.close_db_environment(); + if (!res) { + cerr << "failed to retrieve sharding def" << std::endl; + exit(EXIT_FAILURE); + } + cout << sharding << std::endl; } else { cerr << "unrecognized action " << action << std::endl; return 1; -- 2.47.3