From 43078d3ced0e94bbd647d6726bae2ab26cac697b Mon Sep 17 00:00:00 2001 From: sharat Date: Fri, 18 Nov 2016 15:43:55 +0530 Subject: [PATCH] mvcc: remove unused restore method --- mvcc/index.go | 16 --------- mvcc/index_bench_test.go | 41 ----------------------- mvcc/index_test.go | 71 ++++++++++------------------------------ mvcc/kvstore_test.go | 3 -- 4 files changed, 17 insertions(+), 114 deletions(-) delete mode 100644 mvcc/index_bench_test.go diff --git a/mvcc/index.go b/mvcc/index.go index 3ff53710d..397098a7b 100644 --- a/mvcc/index.go +++ b/mvcc/index.go @@ -25,7 +25,6 @@ type index interface { Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) Range(key, end []byte, atRev int64) ([][]byte, []revision) Put(key []byte, rev revision) - Restore(key []byte, created, modified revision, ver int64) Tombstone(key []byte, rev revision) error RangeSince(key, end []byte, rev int64) []revision Compact(rev int64) map[revision]struct{} @@ -59,21 +58,6 @@ func (ti *treeIndex) Put(key []byte, rev revision) { okeyi.put(rev.main, rev.sub) } -func (ti *treeIndex) Restore(key []byte, created, modified revision, ver int64) { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - keyi.restore(created, modified, ver) - ti.tree.ReplaceOrInsert(keyi) - return - } - okeyi := item.(*keyIndex) - okeyi.put(modified.main, modified.sub) -} - func (ti *treeIndex) Get(key []byte, atRev int64) (modified, created revision, ver int64, err error) { keyi := &keyIndex{key: key} diff --git a/mvcc/index_bench_test.go b/mvcc/index_bench_test.go deleted file mode 100644 index 70882b3c9..000000000 --- a/mvcc/index_bench_test.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "fmt" - "testing" -) - -func BenchmarkIndexRestore(b *testing.B) { - var ( - keys = make([][]byte, b.N) - createds = make([]revision, b.N) - modifieds = make([]revision, b.N) - ver int64 = 1 - ) - for i := 0; i < b.N; i++ { - keys[i] = []byte(fmt.Sprintf("foo%d", i)) - createds[i] = revision{int64(i), 0} - modifieds[i] = revision{int64(i), 1} - } - - kvindex := newTreeIndex() - - b.ResetTimer() - for i := 0; i < b.N; i++ { - kvindex.Restore(keys[i], createds[i], modifieds[i], ver) - } -} diff --git a/mvcc/index_test.go b/mvcc/index_test.go index 9f2bc59b2..ef8df88fb 100644 --- a/mvcc/index_test.go +++ b/mvcc/index_test.go @@ -17,6 +17,8 @@ package mvcc import ( "reflect" "testing" + + "github.com/google/btree" ) func TestIndexGet(t *testing.T) { @@ -225,13 +227,13 @@ func TestIndexCompact(t *testing.T) { for i := int64(1); i < maxRev; i++ { am := ti.Compact(i) - wti := newTreeIndex() + wti := &treeIndex{tree: btree.New(32)} for _, tt := range tests { if _, ok := am[tt.rev]; ok || tt.rev.GreaterThan(revision{main: i}) { if tt.remove { wti.Tombstone(tt.key, tt.rev) } else { - wti.Restore(tt.key, tt.created, tt.rev, tt.ver) + restore(wti, tt.key, tt.created, tt.rev, tt.ver) } } } @@ -252,13 +254,13 @@ func TestIndexCompact(t *testing.T) { } am := ti.Compact(i) - wti := newTreeIndex() + wti := &treeIndex{tree: btree.New(32)} for _, tt := range tests { if _, ok := am[tt.rev]; ok || tt.rev.GreaterThan(revision{main: i}) { if tt.remove { wti.Tombstone(tt.key, tt.rev) } else { - wti.Restore(tt.key, tt.created, tt.rev, tt.ver) + restore(wti, tt.key, tt.created, tt.rev, tt.ver) } } } @@ -268,56 +270,17 @@ func TestIndexCompact(t *testing.T) { } } -func TestIndexRestore(t *testing.T) { - key := []byte("foo") +func restore(ti *treeIndex, key []byte, created, modified revision, ver int64) { + keyi := &keyIndex{key: key} - tests := []struct { - created revision - modified revision - ver int64 - }{ - {revision{1, 0}, revision{1, 0}, 1}, - {revision{1, 0}, revision{1, 1}, 2}, - {revision{1, 0}, revision{2, 0}, 3}, - } - - // Continuous Restore - ti := newTreeIndex() - for i, tt := range tests { - ti.Restore(key, tt.created, tt.modified, tt.ver) - - modified, created, ver, err := ti.Get(key, tt.modified.main) - if modified != tt.modified { - t.Errorf("#%d: modified = %v, want %v", i, modified, tt.modified) - } - if created != tt.created { - t.Errorf("#%d: created = %v, want %v", i, created, tt.created) - } - if ver != tt.ver { - t.Errorf("#%d: ver = %d, want %d", i, ver, tt.ver) - } - if err != nil { - t.Errorf("#%d: err = %v, want nil", i, err) - } - } - - // Once Restore - for i, tt := range tests { - ti := newTreeIndex() - ti.Restore(key, tt.created, tt.modified, tt.ver) - - modified, created, ver, err := ti.Get(key, tt.modified.main) - if modified != tt.modified { - t.Errorf("#%d: modified = %v, want %v", i, modified, tt.modified) - } - if created != tt.created { - t.Errorf("#%d: created = %v, want %v", i, created, tt.created) - } - if ver != tt.ver { - t.Errorf("#%d: ver = %d, want %d", i, ver, tt.ver) - } - if err != nil { - t.Errorf("#%d: err = %v, want nil", i, err) - } + ti.Lock() + defer ti.Unlock() + item := ti.tree.Get(keyi) + if item == nil { + keyi.restore(created, modified, ver) + ti.tree.ReplaceOrInsert(keyi) + return } + okeyi := item.(*keyIndex) + okeyi.put(modified.main, modified.sub) } diff --git a/mvcc/kvstore_test.go b/mvcc/kvstore_test.go index 195429417..816a1b66d 100644 --- a/mvcc/kvstore_test.go +++ b/mvcc/kvstore_test.go @@ -655,9 +655,6 @@ func (i *fakeIndex) Range(key, end []byte, atRev int64) ([][]byte, []revision) { func (i *fakeIndex) Put(key []byte, rev revision) { i.Recorder.Record(testutil.Action{Name: "put", Params: []interface{}{key, rev}}) } -func (i *fakeIndex) Restore(key []byte, created, modified revision, ver int64) { - i.Recorder.Record(testutil.Action{Name: "restore", Params: []interface{}{key, created, modified, ver}}) -} func (i *fakeIndex) Tombstone(key []byte, rev revision) error { i.Recorder.Record(testutil.Action{Name: "tombstone", Params: []interface{}{key, rev}}) return nil