Repository navigation
Fix Bloom filter bit addressing past 2^32 bits - #823
Open
jaideeppyne wants to merge 1 commit into
Open
jaideeppyne wants to merge 1 commit into
jaideeppyne wants to merge 1 commit into
Conversation
(int) index >>> n casts before the shift, so every bit index at or above 2^32 aliases a bit in the low 32-bit range. A filter larger than 512MiB then behaves as a 2^32-bit filter and its false positive rate is higher than requested. Shift first. The on-heap word index is narrowed after the shift, and the direct byte offset stays a long.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #822.
HeapBitArrayand both direct bit arrays computed the word or byte index with(int) index >>> n. The cast binds tighter than the shift, so the index is narrowed to 32 bits first. Every bit at or above 2^32 then aliases a bit in the low 32-bit range.A filter built with
createByAccuracyfor more than 2^32 bits (about 512MiB) therefore only uses the low 2^32 bits. Inserts into the upper half collide with the lower half, and the observed false positive rate is higher than the one requested. Filters at or below 2^32 bits are unchanged.The shift now happens first. The on-heap word index is cast to
intonly after>>> 6(it still fits, becauseMAX_BITS / 64isInteger.MAX_VALUE). The direct byte offset stays along.Tests:
HeapBitArrayTest.wordIndexKeepsBitsAtOrAbove2To32Distinctchecks the index math: bit 2^32 is word 2^26, not word 0.HeapBitArrayTest.bitAtOrAbove2To32DoesNotAliasLowBitschecks that an out-of-range index no longer writes bit 0, and that an in-range bit at 2^32+5 does not alias bit 5. The in-range case allocates a 512MiB filter and is skipped only when the heap is under 1.2GB.DirectBitArrayTest.bitAtOrAbove2To32DoesNotWrapToTheFirstBytechecks the writable and read-only direct arrays.On unpatched main those two behavior tests fail (
Expected ArrayIndexOutOfBoundsException/Expected IndexOutOfBoundsException, because the wrapped index hits byte 0). With this patch,mvn test -Dtest=HeapBitArrayTest,DirectBitArrayTest,DirectBitArrayRTestis 36 tests, 0 failures. The in-range 512MiB case ran (it was not skipped).