From: xinxin shu Date: Mon, 8 Jun 2015 00:30:08 +0000 (+0800) Subject: MonitorDBStore : make monitor transaction more readable on dump X-Git-Tag: v9.1.0~260^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6e0498da19406acc96eca39d86991e1e559908d2;p=ceph.git MonitorDBStore : make monitor transaction more readable on dump Signed-off-by: xinxin shu --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index d762a2c9de3..a89b4411820 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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] diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index d00d3607960..81bb5566094 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "os/KeyValueDB.h" #include "include/assert.h" @@ -31,7 +32,10 @@ class MonitorDBStore { boost::scoped_ptr 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 > > 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(); + } + } } };