// 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]
#include <string>
#include <boost/scoped_ptr.hpp>
#include <sstream>
+#include <fstream>
#include "os/KeyValueDB.h"
#include "include/assert.h"
{
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;
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;
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;
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();
+ }
+ }
}
};