Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage/engine: reenable the Seek optimization #7016

Merged
merged 1 commit into from
Jun 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions storage/engine/rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,16 @@ func (r *rocksDBBatch) flushMutations() {
if err := r.ApplyBatchRepr(r.builder.Finish()); err != nil {
panic(err)
}
// Force a seek of the underlying iterator on the next Seek/ReverseSeek.
r.prefixIter.reseek = true
r.normalIter.reseek = true
}

type rocksDBIterator struct {
engine Reader
iter *C.DBIterator
valid bool
reseek bool
key C.DBKey
value C.DBSlice
}
Expand Down Expand Up @@ -733,9 +737,10 @@ func (r *rocksDBIterator) Seek(key MVCCKey) {
// to access start[0] in an explicit seek.
r.setState(C.DBIterSeekToFirst(r.iter))
} else {
// It's tempting to avoid seeking if we're already at the desired key,
// but it may already have changed on the underlying engine, so we
// must seek again.
// We can avoid seeking if we're already at the key we seek.
if r.valid && !r.reseek && key.Equal(r.unsafeKey()) {
return
}
r.setState(C.DBIterSeek(r.iter, goToCKey(key)))
}
}
Expand All @@ -745,6 +750,10 @@ func (r *rocksDBIterator) SeekReverse(key MVCCKey) {
if len(key.Key) == 0 {
r.setState(C.DBIterSeekToLast(r.iter))
} else {
// We can avoid seeking if we're already at the key we seek.
if r.valid && !r.reseek && key.Equal(r.unsafeKey()) {
return
}
r.setState(C.DBIterSeek(r.iter, goToCKey(key)))
// Maybe the key sorts after the last key in RocksDB.
if !r.Valid() {
Expand Down Expand Up @@ -820,6 +829,7 @@ func (r *rocksDBIterator) Less(key MVCCKey) bool {

func (r *rocksDBIterator) setState(state C.DBIterState) {
r.valid = bool(state.valid)
r.reseek = false
r.key = state.key
r.value = state.value
}
Expand Down