1
1
mirror of https://github.com/MarginaliaSearch/MarginaliaSearch.git synced 2025-10-05 21:22:39 +02:00

(pool) Fix bug in exceptionally rare edge case leading to incorrect reads

This commit is contained in:
Viktor Lofgren
2025-08-13 14:28:50 +02:00
parent 6fe6de766d
commit aa7679d6ce
2 changed files with 42 additions and 0 deletions

View File

@@ -90,6 +90,7 @@ public class SkipListReader {
}
else if (bv == pv) {
data.retainAndAdvance();
currentBlockIdx++;
continue outer;
}
}
@@ -117,6 +118,8 @@ public class SkipListReader {
if (!data.hasMore()) {
currentBlock += SkipListConstants.BLOCK_SIZE;
currentBlockOffset = 0;
currentBlockIdx = 0;
}
else {
long nextBlock = currentBlock + (long) SkipListConstants.BLOCK_SIZE;
@@ -158,6 +161,8 @@ public class SkipListReader {
if (!data.hasMore()) {
currentBlock += SkipListConstants.BLOCK_SIZE;
currentBlockOffset = 0;
currentBlockIdx = 0;
}
else {
long nextBlock = currentBlock + (long) SkipListConstants.BLOCK_SIZE;
@@ -244,6 +249,8 @@ public class SkipListReader {
if (pos >= keys.length) {
currentBlock += SkipListConstants.BLOCK_SIZE;
currentBlockOffset = 0;
currentBlockIdx = 0;
}
else {
long nextBlock = currentBlock + (long) SkipListConstants.BLOCK_SIZE;
@@ -298,6 +305,7 @@ public class SkipListReader {
}
else if (bv == pv) {
data.rejectAndAdvance();
currentBlockIdx++;
continue outer;
}
}
@@ -324,6 +332,8 @@ public class SkipListReader {
}
if (!data.hasMore()) {
currentBlockOffset = 0;
currentBlockIdx = 0;
currentBlock += SkipListConstants.BLOCK_SIZE;
}
else {
@@ -365,6 +375,8 @@ public class SkipListReader {
break;
}
if (!data.hasMore()) {
currentBlockOffset = 0;
currentBlockIdx = 0;
currentBlock += SkipListConstants.BLOCK_SIZE;
}
else {

View File

@@ -102,6 +102,36 @@ public class SkipListReaderTest {
}
}
@Test
public void testRetainBug() throws IOException {
long[] keys = LongStream.range(0, 30000).map(v -> v).toArray();
long[] vals = LongStream.range(0, 30000).map(v -> -v).toArray();
long start;
try (var writer = new SkipListWriter(docsFile)) {
writer.padDocuments(512);
start = writer.writeList(createArray(keys, vals), 0, keys.length);
}
try (var pool = new BufferPool(docsFile, SkipListConstants.BLOCK_SIZE, 8)) {
var reader = new SkipListReader(pool, start);
long[] values = LongStream.range(0, 4059).toArray();
LongQueryBuffer lqb = new LongQueryBuffer(values, values.length);
reader.retainData(lqb);
lqb.finalizeFiltering();
System.out.println(Arrays.toString(lqb.copyData()));
values = LongStream.range(4060, 4070).toArray();
lqb = new LongQueryBuffer(values, values.length);
reader.retainData(lqb);
lqb.finalizeFiltering();
System.out.println(Arrays.toString(lqb.copyData()));
}
}
@Test
public void testRetainFuzz() throws IOException {