Skip to content

Commit

Permalink
Merge pull request #8428 from heyitsanthony/mvcc-revisions
Browse files Browse the repository at this point in the history
mvcc: Revisions() method for index to avoid key allocation
  • Loading branch information
Anthony Romano authored Aug 21, 2017
2 parents 02c6f0d + f58c0cf commit 0bf4046
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions mvcc/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
type index interface {
Get(key []byte, atRev int64) (rev, created revision, ver int64, err error)
Range(key, end []byte, atRev int64) ([][]byte, []revision)
Revisions(key, end []byte, atRev int64) []revision
Put(key []byte, rev revision)
Tombstone(key []byte, rev revision) error
RangeSince(key, end []byte, rev int64) []revision
Expand Down Expand Up @@ -84,6 +85,18 @@ func (ti *treeIndex) keyIndex(keyi *keyIndex) *keyIndex {
return nil
}

func (ti *treeIndex) Revisions(key, end []byte, atRev int64) (revs []revision) {
if end == nil {
rev, _, _, err := ti.Get(key, atRev)
if err != nil {
return nil
}
return []revision{rev}
}
_, rev := ti.Range(key, end, atRev)
return rev
}

func (ti *treeIndex) Range(key, end []byte, atRev int64) (keys [][]byte, revs []revision) {
if end == nil {
rev, _, _, err := ti.Get(key, atRev)
Expand Down
5 changes: 5 additions & 0 deletions mvcc/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ type fakeIndex struct {
indexCompactRespc chan map[revision]struct{}
}

func (i *fakeIndex) Revisions(key, end []byte, atRev int64) []revision {
_, rev := i.Range(key, end, atRev)
return rev
}

func (i *fakeIndex) Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) {
i.Recorder.Record(testutil.Action{Name: "get", Params: []interface{}{key, atRev}})
r := <-i.indexGetRespc
Expand Down
2 changes: 1 addition & 1 deletion mvcc/kvstore_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions
return &RangeResult{KVs: nil, Count: -1, Rev: 0}, ErrCompacted
}

_, revpairs := tr.s.kvindex.Range(key, end, int64(rev))
revpairs := tr.s.kvindex.Revisions(key, end, int64(rev))
if len(revpairs) == 0 {
return &RangeResult{KVs: nil, Count: 0, Rev: curRev}, nil
}
Expand Down

0 comments on commit 0bf4046

Please sign in to comment.