]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
MonitorDBStore : make monitor transaction more readable on dump 4896/head
authorxinxin shu <xinxin.shu@intel.com>
Mon, 8 Jun 2015 00:30:08 +0000 (08:30 +0800)
committerxinxin shu <xinxin.shu@intel.com>
Wed, 15 Jul 2015 00:34:30 +0000 (08:34 +0800)
Signed-off-by: xinxin shu <xinxin.shu@intel.com>
src/common/config_opts.h
src/mon/MonitorDBStore.h

index d762a2c9de3667b63dd1d0a1cb27718c0eeb53be..a89b4411820f7d39d23dc43311bc34ff47746895 100644 (file)
@@ -258,6 +258,7 @@ OPTION(mon_mds_force_trim_to, OPT_INT, 0)   // force mon to trim mdsmaps to this
 
 // dump transactions
 OPTION(mon_debug_dump_transactions, OPT_BOOL, false)
+OPTION(mon_debug_dump_json, OPT_BOOL, false)
 OPTION(mon_debug_dump_location, OPT_STR, "/var/log/ceph/$cluster-$name.tdump")
 OPTION(mon_inject_transaction_delay_max, OPT_DOUBLE, 10.0)      // seconds
 OPTION(mon_inject_transaction_delay_probability, OPT_DOUBLE, 0) // range [0, 1]
index d00d3607960b0a408c1a37f18ce21cee78e9bf62..81bb556609466028ebe7c8c06e85e911ddc6872b 100644 (file)
@@ -20,6 +20,7 @@
 #include <string>
 #include <boost/scoped_ptr.hpp>
 #include <sstream>
+#include <fstream>
 #include "os/KeyValueDB.h"
 
 #include "include/assert.h"
@@ -31,7 +32,10 @@ class MonitorDBStore
 {
   boost::scoped_ptr<KeyValueDB> db;
   bool do_dump;
-  int dump_fd;
+  int dump_fd_binary;
+  std::ofstream dump_fd_json;
+  JSONFormatter dump_fmt;
+  
 
   Finisher io_work;
 
@@ -255,9 +259,15 @@ class MonitorDBStore
     KeyValueDB::Transaction dbt = db->get_transaction();
 
     if (do_dump) {
-      bufferlist bl;
-      t->encode(bl);
-      bl.write_fd(dump_fd);
+      if (!g_conf->mon_debug_dump_json) {
+        bufferlist bl;
+        t->encode(bl);
+        bl.write_fd(dump_fd_binary);
+      } else {
+        t->dump(&dump_fmt, true);
+        dump_fmt.flush(dump_fd_json);
+        dump_fd_json.flush();
+      }
     }
 
     list<pair<string, pair<string,string> > > compact;
@@ -614,7 +624,8 @@ class MonitorDBStore
   MonitorDBStore(const string& path)
     : db(0),
       do_dump(false),
-      dump_fd(-1),
+      dump_fd_binary(-1),
+      dump_fmt(true),
       io_work(g_ceph_context, "monstore"),
       is_open(false) {
     string::const_reverse_iterator rit;
@@ -639,21 +650,35 @@ class MonitorDBStore
     db.reset(db_ptr);
 
     if (g_conf->mon_debug_dump_transactions) {
-      do_dump = true;
-      dump_fd = ::open(
-       g_conf->mon_debug_dump_location.c_str(),
-       O_CREAT|O_APPEND|O_WRONLY, 0644);
-      if (!dump_fd) {
-       dump_fd = -errno;
-       derr << "Could not open log file, got "
-            << cpp_strerror(dump_fd) << dendl;
+      if (!g_conf->mon_debug_dump_json) {
+        dump_fd_binary = ::open(
+          g_conf->mon_debug_dump_location.c_str(),
+          O_CREAT|O_APPEND|O_WRONLY, 0644);
+        if (!dump_fd_binary) {
+          dump_fd_binary = -errno;
+          derr << "Could not open log file, got "
+               << cpp_strerror(dump_fd_binary) << dendl;
+        }
+      } else {
+        dump_fmt.reset();
+        dump_fmt.open_array_section("dump");
+        dump_fd_json.open(g_conf->mon_debug_dump_location.c_str());
       }
+      do_dump = true;
     }
   }
   ~MonitorDBStore() {
     assert(!is_open);
-    if (do_dump)
-      ::close(dump_fd);
+    if (do_dump) {
+      if (!g_conf->mon_debug_dump_json) {
+        ::close(dump_fd_binary);
+      } else {
+        dump_fmt.close_section();
+        dump_fmt.flush(dump_fd_json);
+        dump_fd_json.flush();
+        dump_fd_json.close();
+      }
+    }
   }
 
 };