Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Load correct filter policy into table options #13336

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alanpaxton
Copy link
Contributor

OptionsUtilTest was using a broken assertThat, and a check of the loaded filter policy was not happening. Correcting the test exposed that the filter policy was not being correctly loaded into the Java side BlockBasedTableOptions/BlockBasedTableConfig.

Fix this by constructing the Java Filter (should be renamed FilterPolicy for consistency, but that is too hard) from C++ in the same way as any other Java object via JNI, and installing it in the BlockBasedTableConfig. Subtlety 1 is that the handle for a FilterPolicy is a std::shared_ptr<FilterPolicy> so we need to allocate a new one which shares control block with the shared_ptr stored in corresponding C++ BlockBasedTableOptions

OptionsUtilTest was using a broken assertThat, and a check of the loaded filter policy was not happening. Correcting the test exposed that the filter policy was not being correctly loaded into the Java side `BlockBasedTableOptions`/`BlockBasedTableConfig`.

Fix this by constructing the Java `Filter` (should be renamed `FilterPolicy` for consistency, but that is too hard) from C++ in the same way as any other Java object via JNI, and installing it in the `BlockBasedTableConfig`.
Subtlety 1 is that the handle for a `FilterPolicy` is a `std::shared_ptr<FilterPolicy>` so we need to allocate a new one which shares control block with the shared_ptr stored in corresponding C++ `BlockBasedTableOptions`
@alanpaxton alanpaxton marked this pull request as draft January 27, 2025 17:42
double filter_bits = 0.0;
if (const ROCKSDB_NAMESPACE::BloomLikeFilterPolicy* bloomlike_filter =
dynamic_cast<const BloomLikeFilterPolicy*>(sptr_filter->get())) {
filter_bits = bloomlike_filter->GetMillibitsPerKey() / 1000.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly don't like to store filter_bits in Java when it's also in C++. But I understand that we already have this in code and probably there are reasons. Maybe hashCode & equals methods must be fast in Java and should not cross native code boundary to read filter_bits.

@rhubner
Copy link
Contributor

rhubner commented Jan 29, 2025

Just one comment(maybe opinion).

Otherwise LGTM ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants