Closed VannaDii closed 4 years ago
Following LevelDB logic, forwards seeks land on the target, or the key after it. In reverse mode, we reversed that logic: a backwards seek lands on the target or the key before it.
@vweevers that makes sense, however, it also makes assumption 1 - items are stored in the order received. It seems problematic to impose this storage rule on the underlying persistence layer, no?
Also, in this case, the key provided to seek
doesn't exist at all, it was never put
.
Also, in this case, the key provided to seek doesn't exist at all, it was never put.
I'll rephrase: seeks land on the target or - if that key does not exist - the key after/before it.
Items are sorted lexicographically. In this case, the inserted keys one
, two
, three
sort as one
, three
, two
. If you imagine the key three!
in between them, they sort as one
, three
, three!
, two
. Seeking backwards to three!
would land on three!
if that key existed, but it doesn't, so it lands on three
.
Ahhh, I see now. Thank you for that explanation. This might be a good explanation to add to the iterator documentation? I'll close this issue. Sorry for the trouble.
No trouble at all.
Wait, but doesn't limit: 1
mean that only two
would be retrieved in reverse
landing the seek on undefined
?
The limit applies to the total number of items retrieved, not to what's on disk. It does a seek first, then from it where landed, retrieves items until the limit is reached.
It seems the test for
iterator#seek() on reverse iterator
is invalid. This test usesmake
which batches three items with keysone, two, three
, then creates aniterator
with{ reverse: true, limit: 1 }
, then attempts toseek
to keythree!
expecting to find it and for the key to bethree
.Possibly invalid assumptions:
{ reverse: true, limit: 1 }
three!
!=three
but does start withthree
Possible changes:
{ limit: 1 }
to seek all items in reverse and tolerate the subset matchseek('three!')
call to beseek('three')
If both changes are made then this test passes. Am I missing some reason why this is a valid test?