Skip to content

Commit aa2680d

Browse files
authored
OAK-12047 - CachingSegmentArchiveReader#readSegment should check if archive contains segment before looking up in the PersistentCache (#2672)
1 parent 3604217 commit aa2680d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingSegmentArchiveReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public CachingSegmentArchiveReader(
4646
@Override
4747
@Nullable
4848
public Buffer readSegment(long msb, long lsb) throws IOException {
49-
return persistentCache.readSegment(msb, lsb, () -> delegate.readSegment(msb, lsb));
49+
if (delegate.containsSegment(msb, lsb)) {
50+
return persistentCache.readSegment(msb, lsb, () -> delegate.readSegment(msb, lsb));
51+
} else {
52+
return null;
53+
}
5054
}
5155

5256
@Override

oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingSegmentArchiveReaderTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public void containsSegmentDoesNotUsePersistentDiskCache() throws IOException {
7979
SegmentArchiveReader tar2 = cachingArchiveManager.open(archive2Name);
8080
assertEquals(Buffer.wrap(data2), tar2.readSegment(msb2, lsb2));
8181

82+
// Both segments are cached
83+
// Now check that each tar file only contains its own segment, that is, when searching for a segment that is
84+
// not in the archive, it should not be retrieved from the cache
85+
assertNull(tar1.readSegment(msb2, lsb2));
86+
assertNull(tar2.readSegment(msb1, lsb1));
87+
88+
// Check that contains also respects archive boundaries
8289
assertTrue(tar1.containsSegment(msb1, lsb1));
8390
assertFalse(tar1.containsSegment(msb2, lsb2));
8491
assertFalse(tar2.containsSegment(msb1, lsb1));

0 commit comments

Comments
 (0)