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

Compare commits

...

3 Commits

Author SHA1 Message Date
Viktor Lofgren
827aadafcd (uring) Reintroduce auto-slicing of excessively long read batches 2025-08-13 14:33:35 +02:00
Viktor Lofgren
aa7679d6ce (pool) Fix bug in exceptionally rare edge case leading to incorrect reads 2025-08-13 14:28:50 +02:00
Viktor Lofgren
6fe6de766d (pool) Fix SegmentMemoryPage storage 2025-08-13 13:17:14 +02:00
4 changed files with 51 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ public class BufferPool implements AutoCloseable {
throw new RuntimeException(e);
}
this.arena = Arena.ofShared();
this.pages = new UnsafeMemoryPage[poolSize];
this.pages = new MemoryPage[poolSize];
MemorySegment memoryArea = arena.allocate((long) pageSizeBytes*poolSize, 4096);
for (int i = 0; i < pages.length; i++) {

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 {

View File

@@ -66,9 +66,14 @@ public class UringFileReader implements AutoCloseable {
}
}
else {
// We *could* break the task into multiple submissions, but this leads to some
// very unpredictable read latencies
throw new IllegalArgumentException("Submission size exceeds queue size!");
for (int i = 0; i < destinations.size(); i+=QUEUE_SIZE) {
var destSlice = destinations.subList(i, Math.min(destinations.size(), i+QUEUE_SIZE));
var offSlice = offsets.subList(i, Math.min(offsets.size(), i+QUEUE_SIZE));
int ret = ring.readBatch(destSlice, offSlice, direct);
if (ret != offSlice.size()) {
throw new RuntimeException("Read failed, rv=" + ret);
}
}
}
}