JNI: Do not create 8M block cache for negative blockCacheSize values (#5465)
Summary:
As [BlockBasedTableConfig setBlockCacheSize()](1966a7c055/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
This commit is contained in:
parent
68980df89c
commit
c92c58f84d
@ -85,7 +85,7 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
|
|||||||
std::shared_ptr<rocksdb::Cache> *pCache =
|
std::shared_ptr<rocksdb::Cache> *pCache =
|
||||||
reinterpret_cast<std::shared_ptr<rocksdb::Cache> *>(jblock_cache_handle);
|
reinterpret_cast<std::shared_ptr<rocksdb::Cache> *>(jblock_cache_handle);
|
||||||
options.block_cache = *pCache;
|
options.block_cache = *pCache;
|
||||||
} else if (jblock_cache_size > 0) {
|
} else if (jblock_cache_size >= 0) {
|
||||||
if (jblock_cache_num_shard_bits > 0) {
|
if (jblock_cache_num_shard_bits > 0) {
|
||||||
options.block_cache = rocksdb::NewLRUCache(
|
options.block_cache = rocksdb::NewLRUCache(
|
||||||
static_cast<size_t>(jblock_cache_size),
|
static_cast<size_t>(jblock_cache_size),
|
||||||
@ -94,6 +94,9 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
|
|||||||
options.block_cache = rocksdb::NewLRUCache(
|
options.block_cache = rocksdb::NewLRUCache(
|
||||||
static_cast<size_t>(jblock_cache_size));
|
static_cast<size_t>(jblock_cache_size));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
options.no_block_cache = true;
|
||||||
|
options.block_cache = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jpersistent_cache_handle > 0) {
|
if (jpersistent_cache_handle > 0) {
|
||||||
|
@ -725,7 +725,7 @@ public class BlockBasedTableConfig extends TableFormatConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the size of the cache in bytes that will be used by RocksDB.
|
* 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
|
* DEFAULT: 8M
|
||||||
*
|
*
|
||||||
* @param blockCacheSize block cache size in bytes
|
* @param blockCacheSize block cache size in bytes
|
||||||
|
Loading…
Reference in New Issue
Block a user