From 420d51b9a0bcbb7185056c855dbb968de0beb0ac Mon Sep 17 00:00:00 2001
From: Peter Dillinger
Date: Tue, 15 Feb 2022 12:17:45 -0800
Subject: [PATCH] Update Java API for FilterPolicy changes (#9569)
Summary:
Obsolete block-based filter no longer in public API, from https://github.com/facebook/rocksdb/issues/9535
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9569
Test Plan: existing tests
Reviewed By: jay-zhuang
Differential Revision: D34243579
Pulled By: pdillinger
fbshipit-source-id: ec5127d9bb9cc3f70501c531829a735bffdd1418
---
HISTORY.md | 2 +-
java/rocksjni/filter.cc | 9 ++++-----
.../src/main/java/org/rocksdb/BloomFilter.java | 18 ++++++------------
3 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/HISTORY.md b/HISTORY.md
index 5c95c807c..337981cfc 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -29,7 +29,7 @@
* Removed timestamp from WriteOptions. Accordingly, added to DB APIs Put, Delete, SingleDelete, etc. accepting an additional argument 'timestamp'. Added Put, Delete, SingleDelete, etc to WriteBatch accepting an additional argument 'timestamp'. Removed WriteBatch::AssignTimestamps(vector) API. Renamed WriteBatch::AssignTimestamp() to WriteBatch::UpdateTimestamps() with clarified comments.
* Significant updates to FilterPolicy-related APIs and configuration:
* Remove public API support for deprecated, inefficient block-based filter (use_block_based_builder=true).
- * Old code and configuration strings that would enable it now quietly enable full filters instead, though any built-in FilterPolicy can still read block-based filters.
+ * Old code and configuration strings that would enable it now quietly enable full filters instead, though any built-in FilterPolicy can still read block-based filters. This includes changing the longstanding default behavior of the Java API.
* Remove deprecated FilterPolicy::CreateFilter() and FilterPolicy::KeyMayMatch()
* Remove `rocksdb_filterpolicy_create()` from C API, as the only C API support for custom filter policies is now obsolete.
* If temporary memory usage in full filter creation is a problem, consider using partitioned filters, smaller SST files, or setting reserve_table_builder_memory=true.
diff --git a/java/rocksjni/filter.cc b/java/rocksjni/filter.cc
index 4143fc96f..c0a86a1b1 100644
--- a/java/rocksjni/filter.cc
+++ b/java/rocksjni/filter.cc
@@ -21,13 +21,12 @@
* Method: createBloomFilter
* Signature: (DZ)J
*/
-jlong Java_org_rocksdb_BloomFilter_createNewBloomFilter(
- JNIEnv* /*env*/, jclass /*jcls*/, jdouble bits_per_key,
- jboolean use_block_base_builder) {
+jlong Java_org_rocksdb_BloomFilter_createNewBloomFilter(JNIEnv* /*env*/,
+ jclass /*jcls*/,
+ jdouble bits_per_key) {
auto* sptr_filter =
new std::shared_ptr(
- ROCKSDB_NAMESPACE::NewBloomFilterPolicy(bits_per_key,
- use_block_base_builder));
+ ROCKSDB_NAMESPACE::NewBloomFilterPolicy(bits_per_key));
return reinterpret_cast(sptr_filter);
}
diff --git a/java/src/main/java/org/rocksdb/BloomFilter.java b/java/src/main/java/org/rocksdb/BloomFilter.java
index 0a119878a..8aff715b7 100644
--- a/java/src/main/java/org/rocksdb/BloomFilter.java
+++ b/java/src/main/java/org/rocksdb/BloomFilter.java
@@ -21,7 +21,6 @@ package org.rocksdb;
public class BloomFilter extends Filter {
private static final double DEFAULT_BITS_PER_KEY = 10.0;
- private static final boolean DEFAULT_MODE = true;
/**
* BloomFilter constructor
@@ -31,7 +30,7 @@ public class BloomFilter extends Filter {
* result has been closed.
*/
public BloomFilter() {
- this(DEFAULT_BITS_PER_KEY, DEFAULT_MODE);
+ this(DEFAULT_BITS_PER_KEY);
}
/**
@@ -48,7 +47,7 @@ public class BloomFilter extends Filter {
* @param bitsPerKey number of bits to use
*/
public BloomFilter(final double bitsPerKey) {
- this(bitsPerKey, DEFAULT_MODE);
+ super(createNewBloomFilter(bitsPerKey));
}
/**
@@ -59,21 +58,16 @@ public class BloomFilter extends Filter {
* 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.
*
* @param bitsPerKey number of bits to use
- * @param useBlockBasedMode use block based mode or full filter mode
+ * @param IGNORED_useBlockBasedMode obsolete, ignored parameter
*/
- public BloomFilter(final double bitsPerKey, final boolean useBlockBasedMode) {
- super(createNewBloomFilter(bitsPerKey, useBlockBasedMode));
+ public BloomFilter(final double bitsPerKey, final boolean IGNORED_useBlockBasedMode) {
+ this(bitsPerKey);
}
- private native static long createNewBloomFilter(final double bitsKeyKey,
- final boolean useBlockBasedMode);
+ private native static long createNewBloomFilter(final double bitsKeyKey);
}