Skip to content

Batch Bloom filter lookups for measurements on one device - #1143

Merged
ColinLeeo merged 4 commits into
apache:developfrom
ColinLeeo:perf/batch-bloom-filter-develop
Dec 1, 2026
Merged

ColinLeeo merged 4 commits into
apache:developfrom
ColinLeeo:perf/batch-bloom-filter-develop

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add BloomFilter.mightContainBatch(IDeviceID device, Collection<String> measurements) for callers that probe several measurements on one device, such as IoTDB's aligned time-series metadata cache. The returned BitSet follows the input's iteration order. A clear bit rules out the path. A set bit means the path may exist.

For UTF-8 paths, the implementation reuses the hash state for complete 16-byte blocks of the device prefix within a single call. Other default charsets use the existing full-path lookup. Both paths work with filters written by existing TsFile versions.

Example

IDeviceID device = IDeviceID.Factory.DEFAULT_FACTORY.create("root.factory.d1");
BloomFilter filter = BloomFilter.getEmptyBloomFilter(0.05, 100);
filter.add(new FullPath(device, "temperature"));

BitSet matches =
    filter.mightContainBatch(device, Arrays.asList("temperature", "pressure", "temperature"));

Bits 0 and 2 are set for the inserted measurement. Bit 1 has the same value as the individual lookup for pressure. Passing an empty measurement name probes the device's time column.

Performance

The benchmark measures the time to produce a candidate BitSet for one device with a preloaded Bloom filter and prepared inputs. On develop (5db3d0c5), the caller loops over contains(Path) with each full path string already cached. This PR (154ce991) calls mightContainBatch(device, measurements) once per request. Both produce identical bitsets.

Measurements in file Measurements requested develop (µs/request) This PR (µs/request) Speedup
20 700 40.61 16.01 2.54×
100 700 54.75 20.95 2.61×
700 700 74.02 37.66 1.97×
700 20 2.17 1.20 1.80×
700 100 12.62 5.52 2.29×

Times are medians of the per-request means from five independent JVM runs on macOS arm64 with OpenJDK 25.0.1, G1 and a fixed 1 GiB heap.

Tests

Regression tests compare batch results with individual lookups, cover block boundaries and non-ASCII names, and read bit patterns from existing writer versions. This is a Java SDK API for in-memory filters and requires no new CLI option.

Local validation on the new base passed:

  • Maven clean verify -P with-java,with-python -Denable.lzma2=ON and the all-language Spotless check.
  • C++ validated all 1,672 files generated by Java. Java validated all 1,626 files generated by C++.

Supersedes #1142. The change applies directly to develop.

Probe measurements of one device together and return matches in input order. Reuse complete Murmur hash blocks from the device prefix while preserving compatibility with existing filters. This SDK lookup operates on an in-memory filter and requires no CLI option.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Batch Bloom-filter lookups can falsely exclude stored measurements for empty device IDs, while eager prefix hashing adds unnecessary work for small negative batches.

2 open issues
What changed in this PR

Adds a Java SDK API for batch Bloom-filter checks across measurements on one device, without changing the on-disk filter format.

Changes:

  • Returns membership candidates in a BitSet matching input iteration order.
  • Reuses UTF-8 device-prefix hash state, with a fallback for other default charsets.
  • Adds regression tests and Java SDK usage guidance.
File Description
skills/​tsfile/​references/​java.md Documents batch lookup usage and result interpretation.
java/​tsfile/​src/​test/​java/​org/​apache/​tsfile/​utils/​BloomFilterTest.java Adds ordering, boundary, non-ASCII, and existing-filter compatibility tests.
java/​tsfile/​src/​main/​java/​org/​apache/​tsfile/​utils/​Murmur128Hash.java Refactors hashing to support reusable prefix state.
java/​tsfile/​src/​main/​java/​org/​apache/​tsfile/​utils/​BloomFilter.java Adds batch membership checks and shared bit-index calculation.

Review effort: Max

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Successively longer measurement names trigger repeated buffer allocations and copying of the shared device prefix, undermining buffer reuse and adding avoidable overhead.

3 open issues

Review effort: Max

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
3 resolved since last review

Review effort: Lite

@JackieTien97 JackieTien97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall the batch lookup semantics, UTF-8 prefix boundary handling, empty-device fallback, and on-disk compatibility look solid. Left a few inline comments on Murmur128Hash.innerHash slice semantics / prefix buffer layout, null-argument consistency, hot-path allocations, and docs/tests.

Comment thread skills/tsfile/references/java.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues blocking the batch Bloom filter lookup change.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@JackieTien97 JackieTien97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for the updates!

@ColinLeeo
ColinLeeo merged commit 86daa70 into apache:develop Dec 1, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants