From dd5be75e2cea78cf3dc25cbc4a2d1cdc206c2bf1 Mon Sep 17 00:00:00 2001 From: Yun Tang Date: Wed, 13 Oct 2021 17:19:25 +0800 Subject: [PATCH] Ensure to release cache during KeyValueStorageRocksDB#closec --- .../bookie/storage/ldb/KeyValueStorageRocksDB.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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();