Skip to content

Commit

Permalink
Merge pull request #8213 from heyitsanthony/nil-endrev
Browse files Browse the repository at this point in the history
mvcc: don't allocate end revision while computing range
  • Loading branch information
Anthony Romano authored Jul 7, 2017
2 parents 91dbebf + e9d096a commit 97f37e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
13 changes: 0 additions & 13 deletions mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,3 @@ func appendMarkTombstone(b []byte) []byte {
func isTombstone(b []byte) bool {
return len(b) == markedRevBytesLen && b[markBytePosition] == markTombstone
}

// revBytesRange returns the range of revision bytes at
// the given revision.
func revBytesRange(rev revision) (start, end []byte) {
start = newRevBytes()
revToBytes(rev, start)

end = newRevBytes()
endRev := revision{main: rev.main, sub: rev.sub + 1}
revToBytes(endRev, end)

return start, end
}
5 changes: 3 additions & 2 deletions mvcc/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ func TestStoreRange(t *testing.T) {
t.Errorf("#%d: rev = %d, want %d", i, ret.Rev, wrev)
}

wstart, wend := revBytesRange(tt.idxr.revs[0])
wstart := newRevBytes()
revToBytes(tt.idxr.revs[0], wstart)
wact := []testutil.Action{
{"range", []interface{}{keyBucketName, wstart, wend, int64(0)}},
{"range", []interface{}{keyBucketName, wstart, []byte(nil), int64(0)}},
}
if g := b.tx.Action(); !reflect.DeepEqual(g, wact) {
t.Errorf("#%d: tx action = %+v, want %+v", i, g, wact)
Expand Down
22 changes: 11 additions & 11 deletions mvcc/kvstore_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions
return &RangeResult{KVs: nil, Count: len(revpairs), Rev: curRev}, nil
}

var kvs []mvccpb.KeyValue
for _, revpair := range revpairs {
start, end := revBytesRange(revpair)
_, vs := tr.tx.UnsafeRange(keyBucketName, start, end, 0)
limit := int(ro.Limit)
if limit <= 0 || limit > len(revpairs) {
limit = len(revpairs)
}

kvs := make([]mvccpb.KeyValue, limit)
revBytes := newRevBytes()
for i, revpair := range revpairs[:len(kvs)] {
revToBytes(revpair, revBytes)
_, vs := tr.tx.UnsafeRange(keyBucketName, revBytes, nil, 0)
if len(vs) != 1 {
plog.Fatalf("range cannot find rev (%d,%d)", revpair.main, revpair.sub)
}

var kv mvccpb.KeyValue
if err := kv.Unmarshal(vs[0]); err != nil {
if err := kvs[i].Unmarshal(vs[0]); err != nil {
plog.Fatalf("cannot unmarshal event: %v", err)
}
kvs = append(kvs, kv)
if ro.Limit > 0 && len(kvs) >= int(ro.Limit) {
break
}
}
return &RangeResult{KVs: kvs, Count: len(revpairs), Rev: curRev}, nil
}
Expand Down

0 comments on commit 97f37e4

Please sign in to comment.