From 2ab28aa3295dbe29ab12bf0e7b81c675e92bd337 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 25 Mar 2019 18:42:00 +0300 Subject: [PATCH] tools/ceph-kvstore-tool: command to show RocksDB compaction stats. In fact this command will provide zeros for most of compaction stuff as completed compactions are required to provide most of numbers. But one can use it to learn per-level DB statistics: (amount of files, occupied space, etc). Signed-off-by: Igor Fedotov --- src/test/cli/ceph-kvstore-tool/help.t | 1 + src/tools/ceph_kvstore_tool.cc | 6 +++++- src/tools/kvstore_tool.cc | 30 ++++++++++++++++++++++++++- src/tools/kvstore_tool.h | 5 ++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/test/cli/ceph-kvstore-tool/help.t b/src/test/cli/ceph-kvstore-tool/help.t index d27fddc0844..1f984b11e5f 100644 --- a/src/test/cli/ceph-kvstore-tool/help.t +++ b/src/test/cli/ceph-kvstore-tool/help.t @@ -18,4 +18,5 @@ compact-prefix compact-range destructive-repair (use only as last resort! may corrupt healthy data) + stats diff --git a/src/tools/ceph_kvstore_tool.cc b/src/tools/ceph_kvstore_tool.cc index 6f90876910d..4a4f5214dd1 100644 --- a/src/tools/ceph_kvstore_tool.cc +++ b/src/tools/ceph_kvstore_tool.cc @@ -47,6 +47,7 @@ void usage(const char *pname) << " compact-prefix \n" << " compact-range \n" << " destructive-repair (use only as last resort! may corrupt healthy data)\n" + << " stats\n" << std::endl; } @@ -97,7 +98,8 @@ int main(int argc, const char *argv[]) } bool need_open_db = (cmd != "destructive-repair"); - StoreTool st(type, path, need_open_db); + bool need_stats = (cmd == "stats"); + StoreTool st(type, path, need_open_db, need_stats); if (cmd == "destructive-repair") { int ret = st.destructive_repair(); @@ -343,6 +345,8 @@ int main(int argc, const char *argv[]) string start(url_unescape(argv[5])); string end(url_unescape(argv[6])); st.compact_range(prefix, start, end); + } else if (cmd == "stats") { + st.print_stats(); } else { std::cerr << "Unrecognized command: " << cmd << std::endl; return 1; diff --git a/src/tools/kvstore_tool.cc b/src/tools/kvstore_tool.cc index 7ed6c9e2d09..ed33b29c65e 100644 --- a/src/tools/kvstore_tool.cc +++ b/src/tools/kvstore_tool.cc @@ -10,9 +10,18 @@ #include "include/buffer.h" #include "kv/KeyValueDB.h" -StoreTool::StoreTool(const string& type, const string& path, bool need_open_db) +StoreTool::StoreTool(const string& type, + const string& path, + bool need_open_db, + bool need_stats) : store_path(path) { + + if (need_stats) { + g_conf()->rocksdb_perf = true; + g_conf()->rocksdb_collect_compaction_stats = true; + } + if (type == "bluestore-kv") { #ifdef WITH_BLUESTORE if (load_bluestore(path, need_open_db) != 0) @@ -200,6 +209,25 @@ void StoreTool::print_summary(const uint64_t total_keys, const uint64_t total_si std::cout << " duration " << duration << " seconds" << std::endl; } +int StoreTool::print_stats() const +{ + ostringstream ostr; + Formatter* f = Formatter::create("json-pretty", "json-pretty", "json-pretty"); + int ret = -1; + if (g_conf()->rocksdb_perf) { + db->get_statistics(f); + ostr << "db_statistics "; + f->flush(ostr); + ret = 0; + } else { + ostr << "db_statistics not enabled"; + f->flush(ostr); + } + std::cout << ostr.str() << std::endl; + delete f; + return ret; +} + int StoreTool::copy_store_to(const string& type, const string& other_path, const int num_keys_per_tx, const string& other_type) diff --git a/src/tools/kvstore_tool.h b/src/tools/kvstore_tool.h index 3203024728e..d8c8966130a 100644 --- a/src/tools/kvstore_tool.h +++ b/src/tools/kvstore_tool.h @@ -43,7 +43,8 @@ class StoreTool public: StoreTool(const std::string& type, const std::string& path, - bool need_open_db=true); + bool need_open_db = true, + bool need_stats = false); int load_bluestore(const std::string& path, bool need_open_db); uint32_t traverse(const std::string& prefix, const bool do_crc, @@ -74,4 +75,6 @@ public: const std::string& start, const std::string& end); int destructive_repair(); + + int print_stats() const; }; -- 2.39.5