From c92c58f84dff863ea0e41db2c31de3ae9d75a539 Mon Sep 17 00:00:00 2001 From: Jermy Li Date: Mon, 24 Jun 2019 11:32:45 -0700 Subject: [PATCH] JNI: Do not create 8M block cache for negative blockCacheSize values (#5465) Summary: As [BlockBasedTableConfig setBlockCacheSize()](https://github.com/facebook/rocksdb/blob/1966a7c055f6e182d627275051f5c09441aa922d/java/src/main/java/org/rocksdb/BlockBasedTableConfig.java#L728) said, If cacheSize is non-positive, then cache will not be used. but when we configure a negative number or 0, there is an unexpected result: the block cache becomes 8M. - Allow 0 as a valid size. When block cache size is 0, an 8MB block cache is created, as it is the default C++ API behavior. Also updated the comment. - Set no_block_cache true if negative value is passed to block cache size, and no block cache will be created. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5465 Differential Revision: D15968788 Pulled By: sagar0 fbshipit-source-id: ee02d6e95841c9e2c316a64bfdf192d46ff5638a --- java/rocksjni/table.cc | 5 ++++- java/src/main/java/org/rocksdb/BlockBasedTableConfig.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/java/rocksjni/table.cc b/java/rocksjni/table.cc index 1ccc550ab..a4504d917 100644 --- a/java/rocksjni/table.cc +++ b/java/rocksjni/table.cc @@ -85,7 +85,7 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle( std::shared_ptr *pCache = reinterpret_cast *>(jblock_cache_handle); options.block_cache = *pCache; - } else if (jblock_cache_size > 0) { + } else if (jblock_cache_size >= 0) { if (jblock_cache_num_shard_bits > 0) { options.block_cache = rocksdb::NewLRUCache( static_cast(jblock_cache_size), @@ -94,6 +94,9 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle( options.block_cache = rocksdb::NewLRUCache( static_cast(jblock_cache_size)); } + } else { + options.no_block_cache = true; + options.block_cache = nullptr; } } if (jpersistent_cache_handle > 0) { diff --git a/java/src/main/java/org/rocksdb/BlockBasedTableConfig.java b/java/src/main/java/org/rocksdb/BlockBasedTableConfig.java index 4c88a0224..bf5c0c1a9 100644 --- a/java/src/main/java/org/rocksdb/BlockBasedTableConfig.java +++ b/java/src/main/java/org/rocksdb/BlockBasedTableConfig.java @@ -725,7 +725,7 @@ public class BlockBasedTableConfig extends TableFormatConfig { /** * Set the size of the cache in bytes that will be used by RocksDB. - * If cacheSize is non-positive, then cache will not be used. + * If cacheSize is negative, then cache will not be used. * DEFAULT: 8M * * @param blockCacheSize block cache size in bytes