decompressFunc, boolean isIndex) {
- CacheKey cacheKey = CacheKey.forPosition(file, position, length);
+ CacheKey cacheKey = CacheKey.forPosition(file, position, length, isIndex);
SegmentContainer container = blocks.get(cacheKey);
if (container == null || container.getAccessCount() == CacheManager.REFRESH_COUNT) {
diff --git a/paimon-common/src/main/java/org/apache/paimon/lookup/sort/SortLookupStoreReader.java b/paimon-common/src/main/java/org/apache/paimon/lookup/sort/SortLookupStoreReader.java
index 727589bfd343..39997888ce92 100644
--- a/paimon-common/src/main/java/org/apache/paimon/lookup/sort/SortLookupStoreReader.java
+++ b/paimon-common/src/main/java/org/apache/paimon/lookup/sort/SortLookupStoreReader.java
@@ -38,11 +38,7 @@
import static org.apache.paimon.lookup.sort.SortLookupStoreUtils.crc32c;
import static org.apache.paimon.utils.Preconditions.checkArgument;
-/**
- * A {@link LookupStoreReader} for sort store.
- *
- * TODO separate index cache and block cache.
- */
+/** A {@link LookupStoreReader} for sort store. */
public class SortLookupStoreReader implements LookupStoreReader {
private final Comparator comparator;
@@ -68,7 +64,7 @@ public SortLookupStoreReader(
this.fileInput = PageFileInput.create(file, blockSize, null, fileSize, null);
this.blockCache = new BlockCache(fileInput.file(), cacheManager);
Footer footer = readFooter();
- this.indexBlockIterator = readBlock(footer.getIndexBlockHandle()).iterator();
+ this.indexBlockIterator = readBlock(footer.getIndexBlockHandle(), true).iterator();
BloomFilterHandle handle = footer.getBloomFilterHandle();
if (handle != null) {
this.bloomFilter =
@@ -84,7 +80,7 @@ public SortLookupStoreReader(
private Footer readFooter() throws IOException {
MemorySegment footerData =
blockCache.getBlock(
- fileSize - Footer.ENCODED_LENGTH, Footer.ENCODED_LENGTH, b -> b);
+ fileSize - Footer.ENCODED_LENGTH, Footer.ENCODED_LENGTH, b -> b, true);
return Footer.readFooter(MemorySlice.wrap(footerData).toInput());
}
@@ -111,23 +107,26 @@ public byte[] lookup(byte[] key) throws IOException {
}
private BlockIterator getNextBlock() throws IOException {
+ // index block handle, point to the key, value position.
MemorySlice blockHandle = indexBlockIterator.next().getValue();
- BlockReader dataBlock = openBlock(blockHandle);
+ BlockReader dataBlock =
+ readBlock(BlockHandle.readBlockHandle(blockHandle.toInput()), false);
return dataBlock.iterator();
}
- private BlockReader openBlock(MemorySlice blockEntry) throws IOException {
- BlockHandle blockHandle = BlockHandle.readBlockHandle(blockEntry.toInput());
- return readBlock(blockHandle);
- }
-
- private BlockReader readBlock(BlockHandle blockHandle) {
+ /**
+ * @param blockHandle The block handle.
+ * @param index Whether read the block as an index.
+ * @return The reader of the target block.
+ */
+ private BlockReader readBlock(BlockHandle blockHandle, boolean index) {
// read block trailer
MemorySegment trailerData =
blockCache.getBlock(
blockHandle.offset() + blockHandle.size(),
BlockTrailer.ENCODED_LENGTH,
- b -> b);
+ b -> b,
+ true);
BlockTrailer blockTrailer =
BlockTrailer.readBlockTrailer(MemorySlice.wrap(trailerData).toInput());
@@ -166,7 +165,8 @@ private BlockReader readBlock(BlockHandle blockHandle) {
checkArgument(uncompressedLength == uncompressed.length);
return uncompressed;
}
- });
+ },
+ index);
return new BlockReader(MemorySlice.wrap(unCompressedBlock), comparator);
}
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 3d8751774cd1..ede7a8e3cfe6 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
@@ -55,7 +55,7 @@ public FileBasedBloomFilter(
this.readOffset = readOffset;
this.readLength = readLength;
this.accessCount = 0;
- this.cacheKey = CacheKey.forPosition(input.file(), readOffset, readLength);
+ this.cacheKey = CacheKey.forPosition(input.file(), readOffset, readLength, true);
}
public boolean testHash(int hash) {
diff --git a/paimon-common/src/test/java/org/apache/paimon/io/cache/CacheManagerTest.java b/paimon-common/src/test/java/org/apache/paimon/io/cache/CacheManagerTest.java
index 6f8b4e60e99a..cf8076ac8b80 100644
--- a/paimon-common/src/test/java/org/apache/paimon/io/cache/CacheManagerTest.java
+++ b/paimon-common/src/test/java/org/apache/paimon/io/cache/CacheManagerTest.java
@@ -48,7 +48,7 @@ void testCaffeineCache() throws Exception {
CacheKey key2 = CacheKey.forPageIndex(new RandomAccessFile(file2, "r"), 0, 0);
for (Cache.CacheType cacheType : Cache.CacheType.values()) {
- CacheManager cacheManager = new CacheManager(cacheType, MemorySize.ofBytes(10));
+ CacheManager cacheManager = new CacheManager(cacheType, MemorySize.ofBytes(10), 0.1);
byte[] value = new byte[6];
Arrays.fill(value, (byte) 1);
for (int i = 0; i < 10; i++) {
diff --git a/paimon-common/src/test/java/org/apache/paimon/io/cache/FileBasedRandomInputViewTest.java b/paimon-common/src/test/java/org/apache/paimon/io/cache/FileBasedRandomInputViewTest.java
index 4c88ea343b6b..6486aead8c25 100644
--- a/paimon-common/src/test/java/org/apache/paimon/io/cache/FileBasedRandomInputViewTest.java
+++ b/paimon-common/src/test/java/org/apache/paimon/io/cache/FileBasedRandomInputViewTest.java
@@ -82,7 +82,7 @@ private void innerTest(int len, int maxFileReadCount) throws IOException {
}
File file = writeFile(bytes);
- CacheManager cacheManager = new CacheManager(cacheType, MemorySize.ofKibiBytes(128));
+ CacheManager cacheManager = new CacheManager(cacheType, MemorySize.ofKibiBytes(128), 0);
FileBasedRandomInputView view =
new FileBasedRandomInputView(
PageFileInput.create(file, 1024, null, 0, null), cacheManager);
@@ -117,7 +117,8 @@ private void innerTest(int len, int maxFileReadCount) throws IOException {
// hot key in LRU, should have good cache hit rate
assertThat(cacheManager.fileReadCount()).isLessThan(maxFileReadCount);
- assertThat(cacheManager.cache().asMap().size()).isEqualTo(0);
+ assertThat(cacheManager.dataCache().asMap().size()).isEqualTo(0);
+ assertThat(cacheManager.indexCache().asMap().size()).isEqualTo(0);
}
private File writeFile(byte[] bytes) throws IOException {
diff --git a/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java b/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
index cbec6131d93e..7ba3f8283aea 100644
--- a/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
+++ b/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
@@ -110,7 +110,8 @@ public void testNormal() throws IOException {
assertThat(reader.lookup(toBytes(VALUE_COUNT + 1000))).isNull();
reader.close();
- assertThat(cacheManager.cache().asMap()).isEmpty();
+ assertThat(cacheManager.dataCache().asMap()).isEmpty();
+ assertThat(cacheManager.indexCache().asMap()).isEmpty();
}
@TestTemplate
diff --git a/paimon-common/src/test/java/org/apache/paimon/utils/FileBasedBloomFilterTest.java b/paimon-common/src/test/java/org/apache/paimon/utils/FileBasedBloomFilterTest.java
index 51babc2889cb..d1471fd74afb 100644
--- a/paimon-common/src/test/java/org/apache/paimon/utils/FileBasedBloomFilterTest.java
+++ b/paimon-common/src/test/java/org/apache/paimon/utils/FileBasedBloomFilterTest.java
@@ -64,7 +64,7 @@ public void testProbe() throws IOException {
Arrays.stream(inputs).forEach(i -> builder.addHash(Integer.hashCode(i)));
File file = writeFile(segment.getArray());
- CacheManager cacheManager = new CacheManager(cacheType, MemorySize.ofMebiBytes(1));
+ CacheManager cacheManager = new CacheManager(cacheType, MemorySize.ofMebiBytes(1), 0.1);
FileBasedBloomFilter filter =
new FileBasedBloomFilter(
PageFileInput.create(file, 1024, null, 0, null),
@@ -76,7 +76,8 @@ public void testProbe() throws IOException {
Arrays.stream(inputs)
.forEach(i -> Assertions.assertThat(filter.testHash(Integer.hashCode(i))).isTrue());
filter.close();
- Assertions.assertThat(cacheManager.cache().asMap()).isEmpty();
+ Assertions.assertThat(cacheManager.dataCache().asMap()).isEmpty();
+ Assertions.assertThat(cacheManager.indexCache().asMap()).isEmpty();
Assertions.assertThat(filter.bloomFilter().getMemorySegment()).isNull();
}
diff --git a/paimon-core/src/main/java/org/apache/paimon/operation/MemoryFileStoreWrite.java b/paimon-core/src/main/java/org/apache/paimon/operation/MemoryFileStoreWrite.java
index bbde3fd48580..ff99f06510c9 100644
--- a/paimon-core/src/main/java/org/apache/paimon/operation/MemoryFileStoreWrite.java
+++ b/paimon-core/src/main/java/org/apache/paimon/operation/MemoryFileStoreWrite.java
@@ -78,7 +78,9 @@ public MemoryFileStoreWrite(
options.writeMaxWritersToSpill(),
options.legacyPartitionName());
this.options = options;
- this.cacheManager = new CacheManager(options.lookupCacheMaxMemory());
+ this.cacheManager =
+ new CacheManager(
+ options.lookupCacheMaxMemory(), options.lookupCacheHighPrioPoolRatio());
}
@Override
diff --git a/paimon-core/src/main/java/org/apache/paimon/table/query/LocalTableQuery.java b/paimon-core/src/main/java/org/apache/paimon/table/query/LocalTableQuery.java
index d5b392d9e099..8ff5ce7a6580 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/query/LocalTableQuery.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/query/LocalTableQuery.java
@@ -101,7 +101,9 @@ public LocalTableQuery(FileStoreTable table) {
this.lookupStoreFactory =
LookupStoreFactory.create(
options,
- new CacheManager(options.lookupCacheMaxMemory()),
+ new CacheManager(
+ options.lookupCacheMaxMemory(),
+ options.lookupCacheHighPrioPoolRatio()),
new RowCompactedSerializer(keyType).createSliceComparator());
if (options.needLookup()) {