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

Reduce the block cache configurations into a single one #1549

Merged
merged 13 commits into from
Jul 9, 2023
20 changes: 17 additions & 3 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -530,22 +530,36 @@ migrate-sequence-gap 10000

################################ ROCKSDB #####################################

# Specify the capacity of column family block cache. A larger block cache
# may make requests faster while more keys would be cached. Max Size is 400*1024.
# Default: 4096MB
rocksdb.block_cache_size 4096

# If this configuration is set to yes, the following block cache settings
# (rocksdb.metadata_block_cache_size, rocksdb.subkey_block_cache_size,
# rocksdb.share_metadata_and_subkey_block_cache) will be ignored, only using
# rocksdb.block_cache_size to configure.
# If this configuration is set to no, the following block cache settings
# should be set. (deprecated)
# Default: yes
rocksdb.set_block_cache_size yes

# Specify the capacity of metadata column family block cache. A larger block cache
# may make requests faster while more keys would be cached. Max Size is 200*1024.
# Default: 2048MB
rocksdb.metadata_block_cache_size 2048
#rocksdb.metadata_block_cache_size 2048 (deprecated)
git-hulk marked this conversation as resolved.
Show resolved Hide resolved

# Specify the capacity of subkey column family block cache. A larger block cache
# may make requests faster while more keys would be cached. Max Size is 200*1024.
# Default: 2048MB
rocksdb.subkey_block_cache_size 2048
#rocksdb.subkey_block_cache_size 2048 (deprecated)

# Metadata column family and subkey column family will share a single block cache
# if set 'yes'. The capacity of shared block cache is
# metadata_block_cache_size + subkey_block_cache_size
#
# Default: yes
rocksdb.share_metadata_and_subkey_block_cache yes
#rocksdb.share_metadata_and_subkey_block_cache yes (deprecated)

# A global cache for table-level rows in RocksDB. If almost always point
# lookups, enlarging row cache may improve read performance. Otherwise,
Expand Down
4 changes: 3 additions & 1 deletion src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ Config::Config() {
{"rocksdb.enable_pipelined_write", true, new YesNoField(&rocks_db.enable_pipelined_write, false)},
{"rocksdb.stats_dump_period_sec", false, new IntField(&rocks_db.stats_dump_period_sec, 0, 0, INT_MAX)},
{"rocksdb.cache_index_and_filter_blocks", true, new YesNoField(&rocks_db.cache_index_and_filter_blocks, false)},
{"rocksdb.block_cache_size", true, new IntField(&rocks_db.block_cache_size, 4096, 0, INT_MAX)},
{"rocksdb.set_block_cache_size", true, new YesNoField(&rocks_db.set_block_cache_size, true)},
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
{"rocksdb.subkey_block_cache_size", true, new IntField(&rocks_db.subkey_block_cache_size, 2048, 0, INT_MAX)},
{"rocksdb.metadata_block_cache_size", true, new IntField(&rocks_db.metadata_block_cache_size, 2048, 0, INT_MAX)},
{"rocksdb.share_metadata_and_subkey_block_cache", true,
new YesNoField(&rocks_db.share_metadata_and_subkey_block_cache, true)},
new YesNoField(&rocks_db.share_metadata_and_subkey_block_cache, false)},
{"rocksdb.row_cache_size", true, new IntField(&rocks_db.row_cache_size, 0, 0, INT_MAX)},
{"rocksdb.compaction_readahead_size", false,
new IntField(&rocks_db.compaction_readahead_size, 2 * MiB, 0, 64 * MiB)},
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ struct Config {
struct RocksDB {
int block_size;
bool cache_index_and_filter_blocks;
int block_cache_size;
bool set_block_cache_size;
int metadata_block_cache_size;
int subkey_block_cache_size;
bool share_metadata_and_subkey_block_cache;
Expand Down
5 changes: 4 additions & 1 deletion src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Status Storage::Open(bool read_only) {
db_closing_ = false;

bool cache_index_and_filter_blocks = config_->rocks_db.cache_index_and_filter_blocks;
size_t block_cache_size = config_->rocks_db.block_cache_size * MiB;
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
size_t metadata_block_cache_size = config_->rocks_db.metadata_block_cache_size * MiB;
size_t subkey_block_cache_size = config_->rocks_db.subkey_block_cache_size * MiB;

Expand All @@ -244,7 +245,9 @@ Status Storage::Open(bool read_only) {
}

std::shared_ptr<rocksdb::Cache> shared_block_cache;
if (config_->rocks_db.share_metadata_and_subkey_block_cache) {
if (config_->rocks_db.set_block_cache_size) {
shared_block_cache = rocksdb::NewLRUCache(block_cache_size, -1, false, 0.75);
} else if (config_->rocks_db.share_metadata_and_subkey_block_cache) {
size_t shared_block_cache_size = metadata_block_cache_size + subkey_block_cache_size;
shared_block_cache = rocksdb::NewLRUCache(shared_block_cache_size, -1, false, 0.75);
}
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down