]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools/ceph-kvstore-tool: command to show RocksDB compaction stats.
authorIgor Fedotov <ifedotov@suse.com>
Mon, 25 Mar 2019 15:42:00 +0000 (18:42 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Tue, 26 Mar 2019 17:07:39 +0000 (20:07 +0300)
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 <ifedotov@suse.com>
src/test/cli/ceph-kvstore-tool/help.t
src/tools/ceph_kvstore_tool.cc
src/tools/kvstore_tool.cc
src/tools/kvstore_tool.h

index d27fddc08446b65ba90d09561a0194efbf93762a..1f984b11e5fe086a77144e749104029bd9ffe0ed 100644 (file)
@@ -18,4 +18,5 @@
     compact-prefix <prefix>
     compact-range <prefix> <start> <end>
     destructive-repair  (use only as last resort! may corrupt healthy data)
+    stats
   
index 6f90876910de2d86a19dde14a31699cb8c6d8f98..4a4f5214dd1661e0b2820b1169bc0af644fe9de3 100644 (file)
@@ -47,6 +47,7 @@ void usage(const char *pname)
     << "  compact-prefix <prefix>\n"
     << "  compact-range <prefix> <start> <end>\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;
index 7ed6c9e2d09ea5bcf8b2667461b52fe413f7043e..ed33b29c65e60f7c6a85955f253328dd0122d547 100644 (file)
 #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)
index 3203024728e9836ae57fa06e9df5703080a392c9..d8c8966130aac69703e386ffd4eca76b022af4da 100644 (file)
@@ -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;
 };