This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 2a927ce3 Reduce the block cache configurations into a single one 
(#1549)
2a927ce3 is described below

commit 2a927ce3f033d07e6c9b9467d88cba62fec569f4
Author: Hauru <[email protected]>
AuthorDate: Sun Jul 9 15:12:40 2023 +0800

    Reduce the block cache configurations into a single one (#1549)
---
 kvrocks.conf           | 20 ++++----------------
 src/config/config.cc   |  1 +
 src/config/config.h    |  1 +
 src/storage/storage.cc | 16 +++++++---------
 4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/kvrocks.conf b/kvrocks.conf
index 106f0d85..6e703edc 100644
--- a/kvrocks.conf
+++ b/kvrocks.conf
@@ -530,22 +530,10 @@ migrate-sequence-gap 10000
 
 ################################ ROCKSDB #####################################
 
-# 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
-
-# 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
-
-# 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
+# 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
 
 # A global cache for table-level rows in RocksDB. If almost always point
 # lookups, enlarging row cache may improve read performance. Otherwise,
diff --git a/src/config/config.cc b/src/config/config.cc
index 599bfa49..e278aebf 100644
--- a/src/config/config.cc
+++ b/src/config/config.cc
@@ -186,6 +186,7 @@ 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, 0, 0, INT_MAX)},
       {"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,
diff --git a/src/config/config.h b/src/config/config.h
index 3a06300b..3eabc3be 100644
--- a/src/config/config.h
+++ b/src/config/config.h
@@ -156,6 +156,7 @@ struct Config {
   struct RocksDB {
     int block_size;
     bool cache_index_and_filter_blocks;
+    int block_cache_size;
     int metadata_block_cache_size;
     int subkey_block_cache_size;
     bool share_metadata_and_subkey_block_cache;
diff --git a/src/storage/storage.cc b/src/storage/storage.cc
index 65906b6f..b2b6757f 100644
--- a/src/storage/storage.cc
+++ b/src/storage/storage.cc
@@ -235,23 +235,22 @@ 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;
   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;
+  if (block_cache_size == 0) {
+    block_cache_size = metadata_block_cache_size + subkey_block_cache_size;
+  }
 
   rocksdb::Options options = InitRocksDBOptions();
   if (auto s = CreateColumnFamilies(options); !s.IsOK()) {
     return s.Prefixed("failed to create column families");
   }
 
-  std::shared_ptr<rocksdb::Cache> shared_block_cache;
-  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);
-  }
+  std::shared_ptr<rocksdb::Cache> shared_block_cache = 
rocksdb::NewLRUCache(block_cache_size, -1, false, 0.75);
 
   rocksdb::BlockBasedTableOptions metadata_table_opts = InitTableOptions();
-  metadata_table_opts.block_cache =
-      shared_block_cache ? shared_block_cache : 
rocksdb::NewLRUCache(metadata_block_cache_size, -1, false, 0.75);
+  metadata_table_opts.block_cache = shared_block_cache;
   metadata_table_opts.pin_l0_filter_and_index_blocks_in_cache = true;
   metadata_table_opts.cache_index_and_filter_blocks = 
cache_index_and_filter_blocks;
   metadata_table_opts.cache_index_and_filter_blocks_with_high_priority = true;
@@ -268,8 +267,7 @@ Status Storage::Open(bool read_only) {
   SetBlobDB(&metadata_opts);
 
   rocksdb::BlockBasedTableOptions subkey_table_opts = InitTableOptions();
-  subkey_table_opts.block_cache =
-      shared_block_cache ? shared_block_cache : 
rocksdb::NewLRUCache(subkey_block_cache_size, -1, false, 0.75);
+  subkey_table_opts.block_cache = shared_block_cache;
   subkey_table_opts.pin_l0_filter_and_index_blocks_in_cache = true;
   subkey_table_opts.cache_index_and_filter_blocks = 
cache_index_and_filter_blocks;
   subkey_table_opts.cache_index_and_filter_blocks_with_high_priority = true;

Reply via email to