Skip to content

Commit

Permalink
kv/RocksDBStore: allow cache_size to be specified explicitly
Browse files Browse the repository at this point in the history
(Not via a config option)

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Jun 9, 2017
1 parent c746418 commit d94fce0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/kv/KeyValueDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ class KeyValueDB {
return -EOPNOTSUPP;
}

virtual int set_cache_size(uint64_t) {
return -EOPNOTSUPP;
}

virtual ~KeyValueDB() {}

/// compact the underlying store
Expand Down
11 changes: 7 additions & 4 deletions src/kv/RocksDBStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,14 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing)
}

std::shared_ptr<rocksdb::Cache> 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
Expand All @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions src/kv/RocksDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -435,6 +437,10 @@ class RocksDBStore : public KeyValueDB {
return total_size;
}

int set_cache_size(uint64_t s) override {
cache_size = s;
return 0;
}

protected:
WholeSpaceIterator _get_iterator() override;
Expand Down

0 comments on commit d94fce0

Please sign in to comment.