diff options
author | Sage Weil <sage@inktank.com> | 2013-05-30 14:57:42 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-06-02 14:09:51 -0700 |
commit | 85d629a5f8e1deef9a562d9a7b371707d90c5ba1 (patch) | |
tree | 85eeb47f896264bde41784401a30a3e2445f90ee | |
parent | 0109fa8ae70671c2d8ca19bcc95662d5f41cac66 (diff) | |
download | ceph-85d629a5f8e1deef9a562d9a7b371707d90c5ba1.tar.gz |
os/LevelDBStore: add perfcounters
Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit 7802292e0a49be607d7ba139b44d5ea1f98e07e6)
-rw-r--r-- | src/mon/MonitorDBStore.h | 2 | ||||
-rw-r--r-- | src/os/FileStore.cc | 2 | ||||
-rw-r--r-- | src/os/LevelDBStore.cc | 70 | ||||
-rw-r--r-- | src/os/LevelDBStore.h | 57 |
4 files changed, 96 insertions, 35 deletions
diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 6fa7dcac354..a4aadc7161a 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -521,7 +521,7 @@ class MonitorDBStore os << path.substr(0, path.size() - pos) << "/store.db"; string full_path = os.str(); - LevelDBStore *db_ptr = new LevelDBStore(full_path); + LevelDBStore *db_ptr = new LevelDBStore(g_ceph_context, full_path); if (!db_ptr) { std::cout << __func__ << " error initializing level db back storage in " << full_path << std::endl; diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 140289babc4..fec058edd17 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -1648,7 +1648,7 @@ int FileStore::mount() } { - LevelDBStore *omap_store = new LevelDBStore(omap_dir); + LevelDBStore *omap_store = new LevelDBStore(g_ceph_context, omap_dir); omap_store->options.write_buffer_size = g_conf->osd_leveldb_write_buffer_size; omap_store->options.cache_size = g_conf->osd_leveldb_cache_size; diff --git a/src/os/LevelDBStore.cc b/src/os/LevelDBStore.cc index 31807141c78..d883797f75d 100644 --- a/src/os/LevelDBStore.cc +++ b/src/os/LevelDBStore.cc @@ -8,6 +8,7 @@ #include <tr1/memory> #include <errno.h> using std::string; +#include "common/perf_counters.h" int LevelDBStore::init(ostream &out, bool create_if_missing) { @@ -55,8 +56,60 @@ int LevelDBStore::init(ostream &out, bool create_if_missing) if (!status.ok()) { out << status.ToString() << std::endl; return -EINVAL; - } else - return 0; + } + + PerfCountersBuilder plb(g_ceph_context, "leveldb", l_leveldb_first, l_leveldb_last); + plb.add_u64_counter(l_leveldb_gets, "leveldb_get"); + plb.add_u64_counter(l_leveldb_txns, "leveldb_transaction"); + plb.add_u64_counter(l_leveldb_compact, "leveldb_compact"); + plb.add_u64_counter(l_leveldb_compact_range, "leveldb_compact_range"); + plb.add_u64_counter(l_leveldb_compact_queue_merge, "leveldb_compact_queue_merge"); + plb.add_u64(l_leveldb_compact_queue_len, "leveldb_compact_queue_len"); + logger = plb.create_perf_counters(); + cct->get_perfcounters_collection()->add(logger); + return 0; +} + +LevelDBStore::~LevelDBStore() +{ + close(); + delete logger; +} + +void LevelDBStore::close() +{ + // stop compaction thread + compact_queue_lock.Lock(); + if (compact_thread.is_started()) { + compact_queue_stop = true; + compact_queue_cond.Signal(); + compact_queue_lock.Unlock(); + compact_thread.join(); + } else { + compact_queue_lock.Unlock(); + } + + cct->get_perfcounters_collection()->remove(logger); +} + +int LevelDBStore::submit_transaction(KeyValueDB::Transaction t) +{ + LevelDBTransactionImpl * _t = + static_cast<LevelDBTransactionImpl *>(t.get()); + leveldb::Status s = db->Write(leveldb::WriteOptions(), &(_t->bat)); + logger->inc(l_leveldb_txns); + return s.ok() ? 0 : -1; +} + +int LevelDBStore::submit_transaction_sync(KeyValueDB::Transaction t) +{ + LevelDBTransactionImpl * _t = + static_cast<LevelDBTransactionImpl *>(t.get()); + leveldb::WriteOptions options; + options.sync = true; + leveldb::Status s = db->Write(options, &(_t->bat)); + logger->inc(l_leveldb_txns); + return s.ok() ? 0 : -1; } void LevelDBStore::LevelDBTransactionImpl::set( @@ -109,6 +162,7 @@ int LevelDBStore::get( } else if (!it->valid()) break; } + logger->inc(l_leveldb_gets); return 0; } @@ -141,6 +195,13 @@ int LevelDBStore::split_key(leveldb::Slice in, string *prefix, string *key) return 0; } +void LevelDBStore::compact() +{ + logger->inc(l_leveldb_compact); + db->CompactRange(NULL, NULL); +} + + void LevelDBStore::compact_thread_entry() { compact_queue_lock.Lock(); @@ -148,7 +209,9 @@ void LevelDBStore::compact_thread_entry() while (!compact_queue.empty()) { pair<string,string> range = compact_queue.front(); compact_queue.pop_front(); + logger->set(l_leveldb_compact_queue_len, compact_queue.size()); compact_queue_lock.Unlock(); + logger->inc(l_leveldb_compact_range); compact_range(range.first, range.second); compact_queue_lock.Lock(); continue; @@ -174,11 +237,13 @@ void LevelDBStore::compact_range_async(const string& start, const string& end) // merge with existing range to the right compact_queue.push_back(make_pair(start, p->second)); compact_queue.erase(p); + logger->inc(l_leveldb_compact_queue_merge); break; } else if (p->second >= start && p->second < end) { // merge with existing range to the left compact_queue.push_back(make_pair(p->first, end)); compact_queue.erase(p); + logger->inc(l_leveldb_compact_queue_merge); break; } else { ++p; @@ -187,6 +252,7 @@ void LevelDBStore::compact_range_async(const string& start, const string& end) if (p == compact_queue.end()) { // no merge, new entry. compact_queue.push_back(make_pair(start, end)); + logger->set(l_leveldb_compact_queue_len, compact_queue.size()); } compact_queue_cond.Signal(); if (!compact_thread.is_started()) { diff --git a/src/os/LevelDBStore.h b/src/os/LevelDBStore.h index 556ba0388ee..f3809cf3496 100644 --- a/src/os/LevelDBStore.h +++ b/src/os/LevelDBStore.h @@ -20,10 +20,27 @@ #include "leveldb/filter_policy.h" #endif +#include "common/ceph_context.h" + +class PerfCounters; + +enum { + l_leveldb_first = 34300, + l_leveldb_gets, + l_leveldb_txns, + l_leveldb_compact, + l_leveldb_compact_range, + l_leveldb_compact_queue_merge, + l_leveldb_compact_queue_len, + l_leveldb_last, +}; + /** * Uses LevelDB to implement the KeyValueDB interface */ class LevelDBStore : public KeyValueDB { + CephContext *cct; + PerfCounters *logger; string path; boost::scoped_ptr<leveldb::DB> db; boost::scoped_ptr<leveldb::Cache> db_cache; @@ -60,9 +77,7 @@ class LevelDBStore : public KeyValueDB { public: /// compact the underlying leveldb store - void compact() { - db->CompactRange(NULL, NULL); - } + void compact(); /// compact leveldb for all keys with a given prefix void compact_prefix(const string& prefix) { @@ -117,7 +132,9 @@ public: {} } options; - LevelDBStore(const string &path) : + LevelDBStore(CephContext *c, const string &path) : + cct(c), + logger(NULL), path(path), db_cache(NULL), #ifdef HAVE_LEVELDB_FILTER_POLICY @@ -129,17 +146,7 @@ public: options() {} - ~LevelDBStore() { - compact_queue_lock.Lock(); - if (compact_thread.is_started()) { - compact_queue_stop = true; - compact_queue_cond.Signal(); - compact_queue_lock.Unlock(); - compact_thread.join(); - } else { - compact_queue_lock.Unlock(); - } - } + ~LevelDBStore(); /// Opens underlying db int open(ostream &out) { @@ -150,6 +157,8 @@ public: return init(out, true); } + void close(); + class LevelDBTransactionImpl : public KeyValueDB::TransactionImpl { public: leveldb::WriteBatch bat; @@ -175,22 +184,8 @@ public: new LevelDBTransactionImpl(this)); } - int submit_transaction(KeyValueDB::Transaction t) { - LevelDBTransactionImpl * _t = - static_cast<LevelDBTransactionImpl *>(t.get()); - leveldb::Status s = db->Write(leveldb::WriteOptions(), &(_t->bat)); - return s.ok() ? 0 : -1; - } - - int submit_transaction_sync(KeyValueDB::Transaction t) { - LevelDBTransactionImpl * _t = - static_cast<LevelDBTransactionImpl *>(t.get()); - leveldb::WriteOptions options; - options.sync = true; - leveldb::Status s = db->Write(options, &(_t->bat)); - return s.ok() ? 0 : -1; - } - + int submit_transaction(KeyValueDB::Transaction t); + int submit_transaction_sync(KeyValueDB::Transaction t); int get( const string &prefix, const std::set<string> &key, |