Objects: lmdb iterator find first fix

This commit is contained in:
2025-03-16 00:08:05 +01:00
parent 1b0af6e883
commit 842bd49246
2 changed files with 13 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
package com.usatiuk.dhfs.objects.stores;
import com.google.protobuf.ByteString;
import com.usatiuk.dhfs.objects.iterators.CloseableKvIterator;
import com.usatiuk.dhfs.objects.JObjectKey;
import com.usatiuk.dhfs.objects.iterators.CloseableKvIterator;
import com.usatiuk.dhfs.objects.iterators.IteratorStart;
import com.usatiuk.dhfs.objects.iterators.KeyPredicateKvIterator;
import com.usatiuk.dhfs.objects.iterators.ReversibleKvIterator;
@@ -147,7 +147,10 @@ public class LmdbObjectPersistentStore implements ObjectPersistentStore {
});
verifyReady();
if (!_cursor.get(key.toByteBuffer(), GetOp.MDB_SET_RANGE)) {
if (key.toByteBuffer().remaining() == 0) {
if (!_cursor.first())
return;
} else if (!_cursor.get(key.toByteBuffer(), GetOp.MDB_SET_RANGE)) {
return;
}

View File

@@ -38,7 +38,14 @@ public class LmdbKvIteratorTest {
), -1, Runnable::run
);
var iterator = store.getIterator(IteratorStart.LE, JObjectKey.of(Long.toString(3)));
var iterator = store.getIterator(IteratorStart.GE, JObjectKey.of(""));
Just.checkIterator(iterator, List.of(Pair.of(JObjectKey.of(Long.toString(1)), ByteString.copyFrom(new byte[]{2})),
Pair.of(JObjectKey.of(Long.toString(2)), ByteString.copyFrom(new byte[]{3})),
Pair.of(JObjectKey.of(Long.toString(3)), ByteString.copyFrom(new byte[]{4}))));
Assertions.assertFalse(iterator.hasNext());
iterator.close();
iterator = store.getIterator(IteratorStart.LE, JObjectKey.of(Long.toString(3)));
Just.checkIterator(iterator, Pair.of(JObjectKey.of(Long.toString(3)), ByteString.copyFrom(new byte[]{4})));
Assertions.assertFalse(iterator.hasNext());
iterator.close();