mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
Objects: lmdb iterator find first fix
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user