]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/RocksDBStore: log to ceph log
authorSage Weil <sage@redhat.com>
Mon, 16 Nov 2015 20:43:09 +0000 (15:43 -0500)
committerSage Weil <sage@redhat.com>
Tue, 15 Dec 2015 02:03:05 +0000 (21:03 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/config_opts.h
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index fff089736ffb2fafaf55da625540d01e5ba05f3a..9781da67d980b8f2032421ec65fe69b1c3a40203 100644 (file)
@@ -137,6 +137,7 @@ SUBSYS(refs, 0, 0)
 SUBSYS(xio, 1, 5)
 SUBSYS(compressor, 1, 5)
 SUBSYS(newstore, 1, 5)
+SUBSYS(rocksdb, 4, 5)
 
 OPTION(key, OPT_STR, "")
 OPTION(keyfile, OPT_STR, "")
@@ -763,6 +764,7 @@ OPTION(kinetic_hmac_key, OPT_STR, "asdfasdf") // kinetic key to authenticate wit
 OPTION(kinetic_use_ssl, OPT_BOOL, false) // whether to secure kinetic traffic with TLS
 
 
+OPTION(rocksdb_log_to_ceph_log, OPT_BOOL, true)  // log to ceph log
 // rocksdb options that will be used for keyvaluestore(if backend is rocksdb)
 OPTION(keyvaluestore_rocksdb_options, OPT_STR, "")
 // rocksdb options that will be used for omap(if omap_backend is rocksdb)
index a6d071e48aaf6f467bff5ec53aac8fbeb0aaa5f2..561b065ed9bf9d967ea060e9697804750aff3ebf 100644 (file)
@@ -25,6 +25,46 @@ using std::string;
 #include "KeyValueDB.h"
 #include "RocksDBStore.h"
 
+#include "common/debug.h"
+
+#define dout_subsys ceph_subsys_rocksdb
+#undef dout_prefix
+#define dout_prefix *_dout << "rocksdb: "
+
+class CephRocksdbLogger : public rocksdb::Logger {
+  CephContext *cct;
+public:
+  CephRocksdbLogger(CephContext *c) : cct(c) {
+    cct->get();
+  }
+  ~CephRocksdbLogger() {
+    cct->put();
+  }
+
+  // Write an entry to the log file with the specified format.
+  void Logv(const char* format, va_list ap) {
+    Logv(rocksdb::INFO_LEVEL, format, ap);
+  }
+
+  // Write an entry to the log file with the specified log level
+  // and format.  Any log with level under the internal log level
+  // of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be
+  // printed.
+  void Logv(const rocksdb::InfoLogLevel log_level, const char* format,
+           va_list ap) {
+    int v = rocksdb::NUM_INFO_LOG_LEVELS - log_level - 1;
+    dout(v);
+    char buf[65536];
+    vsnprintf(buf, sizeof(buf), format, ap);
+    *_dout << buf << dendl;
+  }
+};
+
+rocksdb::Logger *create_rocksdb_ceph_logger()
+{
+  return new CephRocksdbLogger(g_ceph_context);
+}
+
 int string2bool(string val, bool &b_val)
 {
   if (strcasecmp(val.c_str(), "false") == 0) {
@@ -142,6 +182,10 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing)
   opt.create_if_missing = create_if_missing;
   opt.wal_dir = path + ".wal";
 
+  if (g_conf->rocksdb_log_to_ceph_log) {
+    opt.info_log.reset(new CephRocksdbLogger(g_ceph_context));
+  }
+
   status = rocksdb::DB::Open(opt, path, &db);
   if (!status.ok()) {
     derr << status.ToString() << dendl;
index eb2f157feba31a46f5e5fae9d23043a9456808b7..45278e068230d3cbfa5c7583c35bf47f71317f43 100644 (file)
@@ -44,8 +44,12 @@ namespace rocksdb{
   class Slice;
   class WriteBatch;
   class Iterator;
+  class Logger;
   struct Options;
 }
+
+extern rocksdb::Logger *create_rocksdb_ceph_logger();
+
 /**
  * Uses RocksDB to implement the KeyValueDB interface
  */