diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java index 1120db2ce8a..bda82725586 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java @@ -65,6 +65,7 @@ public class KeyValueStorageRocksDB implements KeyValueStorage { private final WriteOptions optionSync; private final WriteOptions optionDontSync; + private final Cache cache; private final ReadOptions optionCache; private final ReadOptions optionDontCache; @@ -139,7 +140,7 @@ public KeyValueStorageRocksDB(String basePath, String subPath, DbConfigType dbCo options.setTargetFileSizeBase(sstSizeMB * 1024 * 1024); options.setDeleteObsoleteFilesPeriodMicros(TimeUnit.HOURS.toMicros(1)); - final Cache cache = new LRUCache(blockCacheSize); + this.cache = new LRUCache(blockCacheSize); BlockBasedTableConfig tableOptions = new BlockBasedTableConfig(); tableOptions.setBlockSize(blockSize); tableOptions.setBlockCache(cache); @@ -154,6 +155,8 @@ public KeyValueStorageRocksDB(String basePath, String subPath, DbConfigType dbCo options.setLevelCompactionDynamicLevelBytes(true); options.setTableFormatConfig(tableOptions); + } else { + this.cache = null; } // Configure file path @@ -210,6 +213,9 @@ public KeyValueStorageRocksDB(String basePath, String subPath, DbConfigType dbCo @Override public void close() throws IOException { db.close(); + if (cache != null) { + cache.close(); + } optionSync.close(); optionDontSync.close(); optionCache.close();