Skip to content

Commit

Permalink
Ensure to release cache during KeyValueStorageRocksDB#closec (#2821)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myasuka authored Oct 16, 2021
1 parent 4dc4260 commit 148bf22
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 148bf22

Please sign in to comment.