From d94fce028680176be11b8acd1d02632eeabc16df Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Jun 2017 12:14:39 -0400 Subject: [PATCH] kv/RocksDBStore: allow cache_size to be specified explicitly (Not via a config option) Signed-off-by: Sage Weil --- src/kv/KeyValueDB.h | 4 ++++ src/kv/RocksDBStore.cc | 11 +++++++---- src/kv/RocksDBStore.h | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/kv/KeyValueDB.h b/src/kv/KeyValueDB.h index 9f454ac973a..37a78480f14 100644 --- a/src/kv/KeyValueDB.h +++ b/src/kv/KeyValueDB.h @@ -304,6 +304,10 @@ public: return -EOPNOTSUPP; } + virtual int set_cache_size(uint64_t) { + return -EOPNOTSUPP; + } + virtual ~KeyValueDB() {} /// compact the underlying store diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index c6d3e5e553f..db985f0aa6e 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -298,11 +298,14 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing) } std::shared_ptr cache; + if (!cache_size) { + cache_size = g_conf->rocksdb_cache_size; + } if (g_conf->rocksdb_cache_type == "lru") { - cache = rocksdb::NewLRUCache(g_conf->rocksdb_cache_size, + cache = rocksdb::NewLRUCache(cache_size, g_conf->rocksdb_cache_shard_bits); } else if (g_conf->rocksdb_cache_type == "clock") { - cache = rocksdb::NewClockCache(g_conf->rocksdb_cache_size, + cache = rocksdb::NewClockCache(cache_size, g_conf->rocksdb_cache_shard_bits); } else { derr << "unrecognized rocksdb_cache_type '" << g_conf->rocksdb_cache_type @@ -320,8 +323,8 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing) } opt.table_factory.reset(rocksdb::NewBlockBasedTableFactory(bbt_opts)); dout(10) << __func__ << " set block size to " << g_conf->rocksdb_block_size - << " cache size to " << g_conf->rocksdb_cache_size - << " num of cache shards to " + << ", cache size to " << prettybyte_t(cache_size) + << ", cache shards to " << (1 << g_conf->rocksdb_cache_shard_bits) << dendl; opt.merge_operator.reset(new MergeOperatorRouter(*this)); diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 4d25408a5f0..c437badebab 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -75,6 +75,8 @@ class RocksDBStore : public KeyValueDB { rocksdb::BlockBasedTableOptions bbt_opts; string options_str; + uint64_t cache_size = 0; + int do_open(ostream &out, bool create_if_missing); // manage async compactions @@ -435,6 +437,10 @@ err: return total_size; } + int set_cache_size(uint64_t s) override { + cache_size = s; + return 0; + } protected: WholeSpaceIterator _get_iterator() override;