Skip to content

Commit

Permalink
storage/engine: fix pebbleIterator.SeekReverse when past last key
Browse files Browse the repository at this point in the history
It's surprising that no tests caught this. Do we have any tests in
this area? The only one I see is `TestIterBounds`, which doesn't
test Pebble.

Release note (<category, see below>): <what> <show> <why>
  • Loading branch information
nvanbenschoten committed Nov 6, 2019
1 parent e1f1ad4 commit 79b4c77
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/storage/engine/pebble_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,16 @@ func (p *pebbleIterator) SeekReverse(key MVCCKey) {
// Do a SeekGE, not a SeekLT. This is because SeekReverse seeks to the
// greatest key that's less than or equal to the specified key.
p.Seek(key)
p.keyBuf = EncodeKeyToBuf(p.keyBuf[:0], key)

// The seek key may have been past the last key. If so, position the
// iterator at the last key.
if !p.iter.Valid() && !p.iter.Last() {
return
}

// The new key could either be greater or equal to the supplied key.
// Backtrack one step if it is greater.
p.keyBuf = EncodeKeyToBuf(p.keyBuf[:0], key)
comp := MVCCKeyCompare(p.keyBuf, p.iter.Key())
if comp < 0 && p.iter.Valid() {
p.Prev()
Expand Down

0 comments on commit 79b4c77

Please sign in to comment.