Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1478,13 +1478,24 @@ void PikaServer::InitStorageOptions() {

storage_options_.table_options.pin_l0_filter_and_index_blocks_in_cache =
g_pika_conf->pin_l0_filter_and_index_blocks_in_cache();
if (storage_options_.block_cache_size == 0) {
// 禁用 block_cache
storage_options_.table_options.no_block_cache = true;
storage_options_.table_options.block_cache.reset();
} else if (storage_options_.share_block_cache) {
if (!g_pika_conf->share_block_cache()) {
assert(false && "shared_block_cache_ must be initialized before InitStorageOptions()");
}

if (storage_options_.block_cache_size == 0) {
storage_options_.table_options.no_block_cache = true;
} else if (storage_options_.share_block_cache) {
storage_options_.table_options.block_cache =
rocksdb::NewLRUCache(storage_options_.block_cache_size, static_cast<int>(g_pika_conf->num_shard_bits()));
}
storage_options_.table_options.no_block_cache = false;

storage_options_.table_options.block_cache = 0;
} else {
Comment on lines +1485 to +1493
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Shared cache branch never attaches the shared cache

When share_block_cache is enabled we still leave block_cache as nullptr. RocksDB will silently fall back to its default per-instance cache instead of reusing the intended global cache, so the “shared” mode never actually shares anything. The guard also re-checks the config flag instead of validating that shared_block_cache_ has been initialized.

Wire the shared cache through (and assert it exists) before we flip no_block_cache off:

-    } else if (storage_options_.share_block_cache) {
-        if (!g_pika_conf->share_block_cache()) {
-            assert(false && "shared_block_cache_ must be initialized before InitStorageOptions()");
-        }
-
-        storage_options_.table_options.no_block_cache = false;
-
-        storage_options_.table_options.block_cache = 0;
+    } else if (storage_options_.share_block_cache) {
+        storage_options_.table_options.no_block_cache = false;
+        assert(shared_block_cache_ && "shared_block_cache_ must be initialized before InitStorageOptions()");
+        storage_options_.table_options.block_cache = shared_block_cache_;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (storage_options_.share_block_cache) {
if (!g_pika_conf->share_block_cache()) {
assert(false && "shared_block_cache_ must be initialized before InitStorageOptions()");
}
if (storage_options_.block_cache_size == 0) {
storage_options_.table_options.no_block_cache = true;
} else if (storage_options_.share_block_cache) {
storage_options_.table_options.block_cache =
rocksdb::NewLRUCache(storage_options_.block_cache_size, static_cast<int>(g_pika_conf->num_shard_bits()));
}
storage_options_.table_options.no_block_cache = false;
storage_options_.table_options.block_cache = 0;
} else {
} else if (storage_options_.share_block_cache) {
storage_options_.table_options.no_block_cache = false;
assert(shared_block_cache_ && "shared_block_cache_ must be initialized before InitStorageOptions()");
storage_options_.table_options.block_cache = shared_block_cache_;
} else {
🤖 Prompt for AI Agents
In src/pika_server.cc around lines 1485-1493, the shared-cache branch flips
table_options.no_block_cache to false but leaves table_options.block_cache as
nullptr and re-checks g_pika_conf instead of validating the actual
shared_block_cache_ object; update this branch to assert that
shared_block_cache_ is initialized (not the config flag) and assign the shared
cache to storage_options_.table_options.block_cache before clearing
no_block_cache so RocksDB uses the intended global cache.

storage_options_.table_options.no_block_cache = false;
storage_options_.table_options.block_cache =
rocksdb::NewLRUCache(storage_options_.block_cache_size,
static_cast<int>(g_pika_conf->num_shard_bits()));
}
storage_options_.options.rate_limiter =
std::shared_ptr<rocksdb::RateLimiter>(
rocksdb::NewGenericRateLimiter(
Expand Down
Loading