Skip to content

Commit

Permalink
kv/LevelDBStore: log leveldb to ceph log
Browse files Browse the repository at this point in the history
This greatly eases debugging, and avoids the unbounded growth of
the leveldb LOG file.

Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Dec 15, 2015
1 parent dda6c67 commit 6984239
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ SUBSYS(xio, 1, 5)
SUBSYS(compressor, 1, 5)
SUBSYS(newstore, 1, 5)
SUBSYS(rocksdb, 4, 5)
SUBSYS(leveldb, 4, 5)

OPTION(key, OPT_STR, "")
OPTION(keyfile, OPT_STR, "")
Expand Down Expand Up @@ -747,6 +748,7 @@ OPTION(threadpool_default_timeout, OPT_INT, 60)
// default wait time for an empty queue before pinging the hb timeout
OPTION(threadpool_empty_queue_max_wait, OPT_INT, 2)

OPTION(leveldb_log_to_ceph_log, OPT_BOOL, true)
OPTION(leveldb_write_buffer_size, OPT_U64, 8 *1024*1024) // leveldb write buffer size
OPTION(leveldb_cache_size, OPT_U64, 128 *1024*1024) // leveldb cache size
OPTION(leveldb_block_size, OPT_U64, 0) // leveldb block size
Expand Down
34 changes: 34 additions & 0 deletions src/kv/LevelDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ using std::string;
#include "common/debug.h"
#include "common/perf_counters.h"

#define dout_subsys ceph_subsys_leveldb
#undef dout_prefix
#define dout_prefix *_dout << "leveldb: "

class CephLevelDBLogger : public leveldb::Logger {
CephContext *cct;
public:
CephLevelDBLogger(CephContext *c) : cct(c) {
cct->get();
}
~CephLevelDBLogger() {
cct->put();
}

// Write an entry to the log file with the specified format.
void Logv(const char* format, va_list ap) {
dout(1);
char buf[65536];
vsnprintf(buf, sizeof(buf), format, ap);
*_dout << buf << dendl;
}
};

leveldb::Logger *create_leveldb_ceph_logger()
{
return new CephLevelDBLogger(g_ceph_context);
}

int LevelDBStore::init(string option_str)
{
// init defaults. caller can override these if they want
Expand Down Expand Up @@ -62,6 +90,11 @@ int LevelDBStore::do_open(ostream &out, bool create_if_missing)
ldoptions.paranoid_checks = options.paranoid_checks;
ldoptions.create_if_missing = create_if_missing;

if (g_conf->leveldb_log_to_ceph_log) {
ceph_logger = new CephLevelDBLogger(g_ceph_context);
ldoptions.info_log = ceph_logger;
}

if (options.log_file.length()) {
leveldb::Env *env = leveldb::Env::Default();
env->NewLogger(options.log_file, &ldoptions.info_log);
Expand Down Expand Up @@ -110,6 +143,7 @@ LevelDBStore::~LevelDBStore()
{
close();
delete logger;
delete ceph_logger;

// Ensure db is destroyed before dependent db_cache and filterpolicy
db.reset();
Expand Down
6 changes: 6 additions & 0 deletions src/kv/LevelDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ enum {
l_leveldb_last,
};

extern leveldb::Logger *create_leveldb_ceph_logger();

class CephLevelDBLogger;

/**
* Uses LevelDB to implement the KeyValueDB interface
*/
class LevelDBStore : public KeyValueDB {
CephContext *cct;
PerfCounters *logger;
CephLevelDBLogger *ceph_logger;
string path;
boost::scoped_ptr<leveldb::Cache> db_cache;
#ifdef HAVE_LEVELDB_FILTER_POLICY
Expand Down Expand Up @@ -148,6 +153,7 @@ class LevelDBStore : public KeyValueDB {
LevelDBStore(CephContext *c, const string &path) :
cct(c),
logger(NULL),
ceph_logger(NULL),
path(path),
db_cache(NULL),
#ifdef HAVE_LEVELDB_FILTER_POLICY
Expand Down

0 comments on commit 6984239

Please sign in to comment.