Skip to content

Commit

Permalink
storage/engine: reenable the Seek optimization
Browse files Browse the repository at this point in the history
Primarily affects conditional-put heavy transactions where there is an
existing value.

Fixes #6980.

name                    old time/op  new time/op  delta
Update1_Cockroach-8      356µs ± 2%   348µs ± 1%  -2.42%  (p=0.000 n=10+10)
Update10_Cockroach-8     647µs ± 2%   619µs ± 2%  -4.33%   (p=0.000 n=9+10)
Update100_Cockroach-8   2.92ms ± 2%  2.67ms ± 3%  -8.54%  (p=0.000 n=10+10)
Update1000_Cockroach-8  24.5ms ± 1%  22.3ms ± 2%  -8.91%  (p=0.000 n=10+10)
  • Loading branch information
petermattis committed Jun 2, 2016
1 parent b23d880 commit 70dad71
Showing 1 changed file with 13 additions and 3 deletions.
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

0 comments on commit 70dad71

Please sign in to comment.