diff --git a/java/org/rocksdb/BloomFilter.java b/java/org/rocksdb/BloomFilter.java index 9c4913a8c..21915ed66 100644 --- a/java/org/rocksdb/BloomFilter.java +++ b/java/org/rocksdb/BloomFilter.java @@ -6,32 +6,114 @@ package org.rocksdb; /** - * This class creates a new filter policy that uses a bloom filter - * with approximately the specified number of bits per key. - * A good value for bitsPerKey is 10, which yields a filter - * with ~ 1% false positive rate. - * - * Default value of bits per key is 10. + * BloomFilter */ public class BloomFilter extends Filter { + private static final int DEFAULT_BITS_PER_KEY = 10; + private static final boolean DEFAULT_MODE = true; private final int bitsPerKey_; + private final boolean useBlockBasedMode_; + /** + * Bloom filter policy that uses a bloom filter with approximately + * the specified number of bits per key. + * + *
+ * bits_per_key: bits per key in bloom filter. A good value for bits_per_key + * is 10, which yields a filter with ~ 1% false positive rate. + *
default bits_per_key: 10
+ * + *use_block_based_builder: use block based filter rather than full filter. + * If you want to builder full filter, it needs to be set to false. + *
+ *default mode: block based filter
+ *+ * Callers must delete the result after any database that is using the + * result has been closed.
+ *+ * Note: if you are using a custom comparator that ignores some parts + * of the keys being compared, you must not use this {@code BloomFilter} + * and must provide your own FilterPolicy that also ignores the + * corresponding parts of the keys. For example, if the comparator + * ignores trailing spaces, it would be incorrect to use a + * FilterPolicy (like {@code BloomFilter}) that does not ignore + * trailing spaces in keys.
+ */ public BloomFilter() { - this(DEFAULT_BITS_PER_KEY); + this(DEFAULT_BITS_PER_KEY, DEFAULT_MODE); } + /** + * Bloom filter policy that uses a bloom filter with approximately + * the specified number of bits per key. + * + *+ * bits_per_key: bits per key in bloom filter. A good value for bits_per_key + * is 10, which yields a filter with ~ 1% false positive rate. + *
+ *use_block_based_builder: use block based filter rather than full filter. + * If you want to builder full filter, it needs to be set to false. + *
+ *default mode: block based filter
+ *+ * Callers must delete the result after any database that is using the + * result has been closed.
+ *+ * Note: if you are using a custom comparator that ignores some parts + * of the keys being compared, you must not use this {@code BloomFilter} + * and must provide your own FilterPolicy that also ignores the + * corresponding parts of the keys. For example, if the comparator + * ignores trailing spaces, it would be incorrect to use a + * FilterPolicy (like {@code BloomFilter}) that does not ignore + * trailing spaces in keys.
+ * + * @param bitsPerKey number of bits to use + */ public BloomFilter(int bitsPerKey) { + this(bitsPerKey, DEFAULT_MODE); + } + + /** + * Bloom filter policy that uses a bloom filter with approximately + * the specified number of bits per key. + * + *+ * bits_per_key: bits per key in bloom filter. A good value for bits_per_key + * is 10, which yields a filter with ~ 1% false positive rate. + *
default bits_per_key: 10
+ * + *use_block_based_builder: use block based filter rather than full filter. + * If you want to builder full filter, it needs to be set to false. + *
+ *default mode: block based filter
+ *+ * Callers must delete the result after any database that is using the + * result has been closed.
+ *+ * Note: if you are using a custom comparator that ignores some parts + * of the keys being compared, you must not use this {@code BloomFilter} + * and must provide your own FilterPolicy that also ignores the + * corresponding parts of the keys. For example, if the comparator + * ignores trailing spaces, it would be incorrect to use a + * FilterPolicy (like {@code BloomFilter}) that does not ignore + * trailing spaces in keys.
+ * + * @param bitsPerKey number of bits to use + * @param useBlockBasedMode use block based mode or full filter mode + */ + public BloomFilter(int bitsPerKey, boolean useBlockBasedMode) { super(); bitsPerKey_ = bitsPerKey; - + useBlockBasedMode_ = useBlockBasedMode; createNewFilter(); } @Override protected void createNewFilter() { - createNewFilter0(bitsPerKey_); + createNewBloomFilter(bitsPerKey_, useBlockBasedMode_); } - private native void createNewFilter0(int bitsKeyKey); + private native void createNewBloomFilter(int bitsKeyKey, + boolean useBlockBasedMode); } diff --git a/java/org/rocksdb/test/FilterTest.java b/java/org/rocksdb/test/FilterTest.java index 7475d2c34..00214d033 100644 --- a/java/org/rocksdb/test/FilterTest.java +++ b/java/org/rocksdb/test/FilterTest.java @@ -22,6 +22,10 @@ public class FilterTest { blockConfig = new BlockBasedTableConfig(); blockConfig.setFilter(new BloomFilter()); options.setTableFormatConfig(blockConfig); + blockConfig.setFilter(new BloomFilter(10)); + options.setTableFormatConfig(blockConfig); + blockConfig.setFilter(new BloomFilter(10, false)); + options.setTableFormatConfig(blockConfig); System.out.println("Filter test passed"); } } diff --git a/java/rocksjni/filter.cc b/java/rocksjni/filter.cc index 572b4a66d..1b5d368b6 100644 --- a/java/rocksjni/filter.cc +++ b/java/rocksjni/filter.cc @@ -18,12 +18,14 @@ /* * Class: org_rocksdb_BloomFilter - * Method: createNewFilter0 - * Signature: (I)V + * Method: createBloomFilter + * Signature: (IZ)V */ -void Java_org_rocksdb_BloomFilter_createNewFilter0( - JNIEnv* env, jobject jobj, jint bits_per_key) { - const rocksdb::FilterPolicy* fp = rocksdb::NewBloomFilterPolicy(bits_per_key); +void Java_org_rocksdb_BloomFilter_createNewBloomFilter( + JNIEnv* env, jobject jobj, jint bits_per_key, + jboolean use_block_base_builder) { + const rocksdb::FilterPolicy* fp = rocksdb::NewBloomFilterPolicy(bits_per_key, + use_block_base_builder); rocksdb::FilterJni::setHandle(env, jobj, fp); }