diff --git a/server/src/main/java/org/opensearch/index/codec/fuzzy/BloomFilter.java b/server/src/main/java/org/opensearch/index/codec/fuzzy/BloomFilter.java index edff33e9dd580..a18641e18d8cc 100644 --- a/server/src/main/java/org/opensearch/index/codec/fuzzy/BloomFilter.java +++ b/server/src/main/java/org/opensearch/index/codec/fuzzy/BloomFilter.java @@ -60,8 +60,9 @@ public class BloomFilter extends AbstractFuzzySet { BloomFilter(long maxDocs, double maxFpp, CheckedSupplier, IOException> fieldIteratorProvider) throws IOException { int setSize = (int) Math.ceil((maxDocs * Math.log(maxFpp)) / Math.log(1 / Math.pow(2, Math.log(2)))); setSize = getNearestSetSize(setSize < Integer.MAX_VALUE / 2 ? 2 * setSize : Integer.MAX_VALUE); + System.out.println("final set: " + setSize); int optimalK = (int) Math.round(((double) setSize / maxDocs) * Math.log(2)); - this.bitset = new LongArrayBackedBitSet(setSize + 1); + this.bitset = new LongArrayBackedBitSet(setSize); this.setSize = setSize; this.hashCount = optimalK; addAll(fieldIteratorProvider); diff --git a/server/src/main/java/org/opensearch/index/codec/fuzzy/LongArrayBackedBitSet.java b/server/src/main/java/org/opensearch/index/codec/fuzzy/LongArrayBackedBitSet.java index 714be24d28e00..bd4936aeec366 100644 --- a/server/src/main/java/org/opensearch/index/codec/fuzzy/LongArrayBackedBitSet.java +++ b/server/src/main/java/org/opensearch/index/codec/fuzzy/LongArrayBackedBitSet.java @@ -32,7 +32,7 @@ class LongArrayBackedBitSet implements Accountable, Closeable { */ LongArrayBackedBitSet(long capacity) { // Since the bitset is backed by a long array, we only need 1 element for every 64 bits in the underlying array. - underlyingArrayLength = ((capacity - 1L) >> 6) + 1; + underlyingArrayLength = (capacity >> 6) + 1L; this.longArray = BigArrays.NON_RECYCLING_INSTANCE.withCircuitBreaking().newLongArray(underlyingArrayLength); } diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java index 9adcafc21dba3..9b00149e936b6 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java @@ -653,6 +653,9 @@ protected Settings featureFlagSettings() { } // Enabling Telemetry setting by default featureSettings.put(FeatureFlags.TELEMETRY_SETTING.getKey(), true); + + // Enabling fuzzy set for tests by default + featureSettings.put(FeatureFlags.DOC_ID_FUZZY_SET_SETTING.getKey(), true); return featureSettings.build(); }