From 803e70160655f93a51df483a3c0fe7d418e46ae6 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 27 Jun 2017 08:15:03 -0500 Subject: [PATCH] kv/RocksDBStore: explicitly disable block_cache when set to 0. Signed-off-by: Mark Nelson --- src/kv/RocksDBStore.cc | 32 ++++++++++++++++++++------------ src/kv/RocksDBStore.h | 2 ++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index aad274f5c71f5..01c2369ca6f0f 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -298,23 +298,31 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing) } // caches - if (!cache_size) { + if (!set_cache_flag) { cache_size = g_conf->rocksdb_cache_size; } uint64_t row_cache_size = cache_size * g_conf->rocksdb_cache_row_ratio; uint64_t block_cache_size = cache_size - row_cache_size; - if (g_conf->rocksdb_cache_type == "lru") { - bbt_opts.block_cache = rocksdb::NewLRUCache( - block_cache_size, - g_conf->rocksdb_cache_shard_bits); - } else if (g_conf->rocksdb_cache_type == "clock") { - bbt_opts.block_cache = rocksdb::NewClockCache( - block_cache_size, - g_conf->rocksdb_cache_shard_bits); + + if (block_cache_size == 0) { + // disable block cache + dout(10) << __func__ << " block_cache_size " << block_cache_size + << ", setting no_block_cache " << dendl; + bbt_opts.no_block_cache = true; } else { - derr << "unrecognized rocksdb_cache_type '" << g_conf->rocksdb_cache_type - << "'" << dendl; - return -EINVAL; + if (g_conf->rocksdb_cache_type == "lru") { + bbt_opts.block_cache = rocksdb::NewLRUCache( + block_cache_size, + g_conf->rocksdb_cache_shard_bits); + } else if (g_conf->rocksdb_cache_type == "clock") { + bbt_opts.block_cache = rocksdb::NewClockCache( + block_cache_size, + g_conf->rocksdb_cache_shard_bits); + } else { + derr << "unrecognized rocksdb_cache_type '" << g_conf->rocksdb_cache_type + << "'" << dendl; + return -EINVAL; + } } bbt_opts.block_size = g_conf->rocksdb_block_size; diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index c437badebabbb..321653448973f 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -76,6 +76,7 @@ class RocksDBStore : public KeyValueDB { string options_str; uint64_t cache_size = 0; + bool set_cache_flag = false; int do_open(ostream &out, bool create_if_missing); @@ -439,6 +440,7 @@ err: int set_cache_size(uint64_t s) override { cache_size = s; + set_cache_flag = true; return 0; } -- 2.39.5