Skip to content

Commit c06a553

Browse files
[kv] full options support for shared block cache
1 parent a8277fb commit c06a553

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

fluss-common/src/main/java/com/alibaba/fluss/config/ConfigOptions.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,25 @@ public class ConfigOptions {
15481548
.defaultValue(MemorySize.parse("4gb"))
15491549
.withDescription("The size of the shared block cache if enabled.");
15501550

1551+
public static final ConfigOption<Boolean> KV_SHARED_BLOCK_CACHE_STRICT_CAPACITY_LIMIT =
1552+
key("kv.rocksdb.shared-block-cache.strict-capacity-limit")
1553+
.booleanType()
1554+
.defaultValue(false)
1555+
.withDescription("Whether to strictly limit the shared block cache capacity.");
1556+
1557+
public static final ConfigOption<Integer> KV_SHARED_BLOCK_CACHE_NUM_SHARD_BITS =
1558+
key("kv.rocksdb.shared-block-cache.num-shard-bits")
1559+
.intType()
1560+
.defaultValue(-1)
1561+
.withDescription(
1562+
"Number of bits for shard count (8 means 256 shards) in the shared block cache.");
1563+
1564+
public static final ConfigOption<Double> KV_SHARED_BLOCK_CACHE_HIGH_PRI_POOL_RATIO =
1565+
key("kv.rocksdb.shared-block-cache.high-pri-pool-ratio")
1566+
.doubleType()
1567+
.defaultValue(0.0)
1568+
.withDescription("Ratio of high priority pool in the shared block cache.");
1569+
15511570
public static final ConfigOption<Boolean> KV_USE_BLOOM_FILTER =
15521571
key("kv.rocksdb.use-bloom-filter")
15531572
.booleanType()

fluss-server/src/main/java/com/alibaba/fluss/server/kv/rocksdb/RocksDBSharedResource.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
* released
4848
* </ul>
4949
*
50-
* <p>Closeable state determination: When reference count is 0, it's in closeable state, no
51-
* additional state variables needed.
50+
* <p>Closeable state determination: When reference count is 0, it's in closeable state.
5251
*
5352
* <p>Note: This class is thread-safe and can be used concurrently across multiple threads.
5453
*/
@@ -145,8 +144,6 @@ public int release() {
145144
LOG.debug("Released RocksDBSharedResource, reference count: {}", newCount);
146145

147146
if (newCount == 0) {
148-
// When reference count is 0, don't release resources, just enter closeable state
149-
LOG.debug("RocksDBSharedResource transitioned to closeable state");
150147
// Wake up any waiting close() method
151148
lock.notifyAll();
152149
} else if (newCount < 0) {
@@ -242,6 +239,12 @@ private void createSharedBlockCache() {
242239
}
243240

244241
long cacheSize = configuration.get(ConfigOptions.KV_SHARED_BLOCK_CACHE_SIZE).getBytes();
242+
int cacheNumShardBits =
243+
configuration.get(ConfigOptions.KV_SHARED_BLOCK_CACHE_NUM_SHARD_BITS);
244+
boolean strictCapacityLimit =
245+
configuration.get(ConfigOptions.KV_SHARED_BLOCK_CACHE_STRICT_CAPACITY_LIMIT);
246+
double highPriPoolRatio =
247+
configuration.get(ConfigOptions.KV_SHARED_BLOCK_CACHE_HIGH_PRI_POOL_RATIO);
245248

246249
// Load RocksDB native library if needed, this operation is idempotent
247250
RocksDB.loadLibrary();
@@ -252,9 +255,15 @@ private void createSharedBlockCache() {
252255
// - numShardBits: number of bits for shard count (8 means 256 shards)
253256
// - strictCapacityLimit: whether to strictly limit capacity
254257
// - highPriPoolRatio: ratio of high priority pool
255-
sharedBlockCache = new LRUCache(cacheSize, 8, true, 0.5);
256-
257-
LOG.info("Created shared block cache with size: {} bytes", cacheSize);
258+
sharedBlockCache =
259+
new LRUCache(cacheSize, cacheNumShardBits, strictCapacityLimit, highPriPoolRatio);
260+
261+
LOG.info(
262+
"Created shared block cache with size: {} bytes, numShardBits: {}, strictCapacityLimit: {}, highPriPoolRatio: {}",
263+
cacheSize,
264+
cacheNumShardBits,
265+
strictCapacityLimit,
266+
highPriPoolRatio);
258267
}
259268

260269
/** Close shared resources. */

0 commit comments

Comments
 (0)