Skip to content

Commit

Permalink
[core] Introduce refreshCount to refresh cache in LRU
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Jan 24, 2024
1 parent 547093b commit 3d8f14b
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
/** Util to apply a built bloom filter . */
public class FileBasedBloomFilter {

private static final int FORCE_REFRESH_CACHE = 30;

private final RandomAccessFile file;
private final CacheManager cacheManager;
private final BloomFilter filter;
private final long readOffset;
private final int readLength;

private int refreshCount;

public FileBasedBloomFilter(
RandomAccessFile file,
CacheManager cacheManager,
Expand All @@ -49,17 +53,22 @@ public FileBasedBloomFilter(
this.filter = new BloomFilter(numRecords, readLength);
this.readOffset = readOffset;
this.readLength = readLength;
this.refreshCount = 0;
}

public boolean testHash(int hash) {
if (filter.getMemorySegment() == null) {
refreshCount++;
// we should refresh cache in LRU, but we cannot refresh everytime, it is costly.
// so we introduce a refresh count to reduce refresh
if (refreshCount == FORCE_REFRESH_CACHE || filter.getMemorySegment() == null) {
MemorySegment segment =
cacheManager.getPage(
file,
readOffset,
readLength,
(position, length) -> filter.unsetMemorySegment());
filter.setMemorySegment(segment, 0);
refreshCount = 0;
}
return filter.testHash(hash);
}
Expand Down

0 comments on commit 3d8f14b

Please sign in to comment.