Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osd,mon: log leveldb and rocksdb to ceph log #6921

Merged
merged 2 commits into from
Dec 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ SUBSYS(refs, 0, 0)
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 @@ -746,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 All @@ -763,6 +766,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)
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
44 changes: 44 additions & 0 deletions src/kv/RocksDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/kv/RocksDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down