BlockBasedTableConfig Filter policy support RocksJava

As proposed by yhchiang the filter can now be set in Java for
a BlockBasedTableConfig instance.
main
fyrz 10 years ago
parent 0908ddcea5
commit d410b39d59
  1. 1
      java/Makefile
  2. 3
      java/RocksDBSample.java
  3. 24
      java/org/rocksdb/BlockBasedTableConfig.java
  4. 7
      java/rocksjni/table.cc

@ -26,6 +26,7 @@ test: java
javac org/rocksdb/test/*.java javac org/rocksdb/test/*.java
java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.WriteBatchTest java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.WriteBatchTest
java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.BackupableDBTest java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.BackupableDBTest
java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.FilterTest
java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.OptionsTest java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.OptionsTest
java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ReadOptionsTest java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.ReadOptionsTest
java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.StatisticsCollectorTest java -ea -Djava.library.path=.:../ -cp "$(ROCKSDB_JAR):.:./*" org.rocksdb.test.StatisticsCollectorTest

@ -80,9 +80,10 @@ public class RocksDBSample {
10000, 10)); 10000, 10));
options.setRateLimiterConfig(new GenericRateLimiterConfig(10000000)); options.setRateLimiterConfig(new GenericRateLimiterConfig(10000000));
Filter bloomFilter = new BloomFilter(10);
BlockBasedTableConfig table_options = new BlockBasedTableConfig(); BlockBasedTableConfig table_options = new BlockBasedTableConfig();
table_options.setBlockCacheSize(64 * SizeUnit.KB) table_options.setBlockCacheSize(64 * SizeUnit.KB)
.setFilterBitsPerKey(10) .setFilter(bloomFilter)
.setCacheNumShardBits(6) .setCacheNumShardBits(6)
.setBlockSizeDeviation(5) .setBlockSizeDeviation(5)
.setBlockRestartInterval(10) .setBlockRestartInterval(10)

@ -18,7 +18,7 @@ public class BlockBasedTableConfig extends TableFormatConfig {
blockSizeDeviation_ = 10; blockSizeDeviation_ = 10;
blockRestartInterval_ = 16; blockRestartInterval_ = 16;
wholeKeyFiltering_ = true; wholeKeyFiltering_ = true;
bitsPerKey_ = 10; filter_ = null;
cacheIndexAndFilterBlocks_ = false; cacheIndexAndFilterBlocks_ = false;
hashIndexAllowCollision_ = true; hashIndexAllowCollision_ = true;
blockCacheCompressedSize_ = 0; blockCacheCompressedSize_ = 0;
@ -182,11 +182,11 @@ public class BlockBasedTableConfig extends TableFormatConfig {
* *
* Filter instance can be re-used in multiple options instances. * Filter instance can be re-used in multiple options instances.
* *
* @param Filter policy java instance. * @param Filter Filter Policy java instance.
* @return the reference to the current config. * @return the reference to the current config.
*/ */
public BlockBasedTableConfig setFilterBitsPerKey(int bitsPerKey) { public BlockBasedTableConfig setFilter(Filter filter) {
bitsPerKey_ = bitsPerKey; filter_ = filter;
return this; return this;
} }
@ -293,17 +293,23 @@ public class BlockBasedTableConfig extends TableFormatConfig {
} }
@Override protected long newTableFactoryHandle() { @Override protected long newTableFactoryHandle() {
long filterHandle = 0;
if (filter_ != null) {
filterHandle = filter_.nativeHandle_;
}
return newTableFactoryHandle(noBlockCache_, blockCacheSize_, return newTableFactoryHandle(noBlockCache_, blockCacheSize_,
blockCacheNumShardBits_, blockSize_, blockSizeDeviation_, blockCacheNumShardBits_, blockSize_, blockSizeDeviation_,
blockRestartInterval_, wholeKeyFiltering_, bitsPerKey_, blockRestartInterval_, wholeKeyFiltering_,
cacheIndexAndFilterBlocks_, hashIndexAllowCollision_, filterHandle, cacheIndexAndFilterBlocks_,
blockCacheCompressedSize_, blockCacheCompressedNumShardBits_); hashIndexAllowCollision_, blockCacheCompressedSize_,
blockCacheCompressedNumShardBits_);
} }
private native long newTableFactoryHandle( private native long newTableFactoryHandle(
boolean noBlockCache, long blockCacheSize, int blockCacheNumShardBits, boolean noBlockCache, long blockCacheSize, int blockCacheNumShardBits,
long blockSize, int blockSizeDeviation, int blockRestartInterval, long blockSize, int blockSizeDeviation, int blockRestartInterval,
boolean wholeKeyFiltering, int bitsPerKey, boolean wholeKeyFiltering, long filterPolicyHandle,
boolean cacheIndexAndFilterBlocks, boolean hashIndexAllowCollision, boolean cacheIndexAndFilterBlocks, boolean hashIndexAllowCollision,
long blockCacheCompressedSize, int blockCacheCompressedNumShardBits); long blockCacheCompressedSize, int blockCacheCompressedNumShardBits);
@ -315,7 +321,7 @@ public class BlockBasedTableConfig extends TableFormatConfig {
private int blockSizeDeviation_; private int blockSizeDeviation_;
private int blockRestartInterval_; private int blockRestartInterval_;
private boolean wholeKeyFiltering_; private boolean wholeKeyFiltering_;
private int bitsPerKey_; private Filter filter_;
private boolean cacheIndexAndFilterBlocks_; private boolean cacheIndexAndFilterBlocks_;
private boolean hashIndexAllowCollision_; private boolean hashIndexAllowCollision_;
private long blockCacheCompressedSize_; private long blockCacheCompressedSize_;

@ -37,7 +37,7 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
JNIEnv* env, jobject jobj, jboolean no_block_cache, jlong block_cache_size, JNIEnv* env, jobject jobj, jboolean no_block_cache, jlong block_cache_size,
jint block_cache_num_shardbits, jlong block_size, jint block_size_deviation, jint block_cache_num_shardbits, jlong block_size, jint block_size_deviation,
jint block_restart_interval, jboolean whole_key_filtering, jint block_restart_interval, jboolean whole_key_filtering,
jint bits_per_key, jboolean cache_index_and_filter_blocks, jlong jfilterPolicy, jboolean cache_index_and_filter_blocks,
jboolean hash_index_allow_collision, jlong block_cache_compressed_size, jboolean hash_index_allow_collision, jlong block_cache_compressed_size,
jint block_cache_compressd_num_shard_bits) { jint block_cache_compressd_num_shard_bits) {
rocksdb::BlockBasedTableOptions options; rocksdb::BlockBasedTableOptions options;
@ -55,8 +55,9 @@ jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
options.block_size_deviation = block_size_deviation; options.block_size_deviation = block_size_deviation;
options.block_restart_interval = block_restart_interval; options.block_restart_interval = block_restart_interval;
options.whole_key_filtering = whole_key_filtering; options.whole_key_filtering = whole_key_filtering;
if (bits_per_key > 0) { if (jfilterPolicy > 0) {
options.filter_policy.reset(rocksdb::NewBloomFilterPolicy(bits_per_key)); options.filter_policy.reset(
reinterpret_cast<rocksdb::FilterPolicy*>(jfilterPolicy));
} }
options.cache_index_and_filter_blocks = cache_index_and_filter_blocks; options.cache_index_and_filter_blocks = cache_index_and_filter_blocks;
options.hash_index_allow_collision = hash_index_allow_collision; options.hash_index_allow_collision = hash_index_allow_collision;

Loading…
Cancel
Save