diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/FileBasedBloomFilter.java b/paimon-common/src/main/java/org/apache/paimon/utils/FileBasedBloomFilter.java index f80ba301ed1a..7b885a5e6f7a 100644 --- a/paimon-common/src/main/java/org/apache/paimon/utils/FileBasedBloomFilter.java +++ b/paimon-common/src/main/java/org/apache/paimon/utils/FileBasedBloomFilter.java @@ -20,6 +20,7 @@ import org.apache.paimon.annotation.VisibleForTesting; import org.apache.paimon.io.PageFileInput; +import org.apache.paimon.io.cache.CacheCallback; import org.apache.paimon.io.cache.CacheKey; import org.apache.paimon.io.cache.CacheManager; import org.apache.paimon.memory.MemorySegment; @@ -62,7 +63,7 @@ public boolean testHash(int hash) { cacheManager.getPage( CacheKey.forPosition(input.file(), readOffset, readLength), key -> input.readPosition(readOffset, readLength), - key -> filter.unsetMemorySegment()); + new BloomFilterCallBack(filter)); filter.setMemorySegment(segment, 0); accessCount = 0; } @@ -73,4 +74,19 @@ public boolean testHash(int hash) { BloomFilter bloomFilter() { return filter; } + + /** Call back for cache manager. */ + private static class BloomFilterCallBack implements CacheCallback { + + private final BloomFilter bloomFilter; + + private BloomFilterCallBack(BloomFilter bloomFilter) { + this.bloomFilter = bloomFilter; + } + + @Override + public void onRemoval(CacheKey key) { + this.bloomFilter.unsetMemorySegment(); + } + } }