mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #6869 from sinsharat/mvcc_remove_unused_restore_method
mvcc: remove unused restore method
This commit is contained in:
commit
2acf0806fb
@ -25,7 +25,6 @@ type index interface {
|
|||||||
Get(key []byte, atRev int64) (rev, created revision, ver int64, err error)
|
Get(key []byte, atRev int64) (rev, created revision, ver int64, err error)
|
||||||
Range(key, end []byte, atRev int64) ([][]byte, []revision)
|
Range(key, end []byte, atRev int64) ([][]byte, []revision)
|
||||||
Put(key []byte, rev revision)
|
Put(key []byte, rev revision)
|
||||||
Restore(key []byte, created, modified revision, ver int64)
|
|
||||||
Tombstone(key []byte, rev revision) error
|
Tombstone(key []byte, rev revision) error
|
||||||
RangeSince(key, end []byte, rev int64) []revision
|
RangeSince(key, end []byte, rev int64) []revision
|
||||||
Compact(rev int64) map[revision]struct{}
|
Compact(rev int64) map[revision]struct{}
|
||||||
@ -59,21 +58,6 @@ func (ti *treeIndex) Put(key []byte, rev revision) {
|
|||||||
okeyi.put(rev.main, rev.sub)
|
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) {
|
func (ti *treeIndex) Get(key []byte, atRev int64) (modified, created revision, ver int64, err error) {
|
||||||
keyi := &keyIndex{key: key}
|
keyi := &keyIndex{key: key}
|
||||||
|
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,6 +17,8 @@ package mvcc
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/btree"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIndexGet(t *testing.T) {
|
func TestIndexGet(t *testing.T) {
|
||||||
@ -225,13 +227,13 @@ func TestIndexCompact(t *testing.T) {
|
|||||||
for i := int64(1); i < maxRev; i++ {
|
for i := int64(1); i < maxRev; i++ {
|
||||||
am := ti.Compact(i)
|
am := ti.Compact(i)
|
||||||
|
|
||||||
wti := newTreeIndex()
|
wti := &treeIndex{tree: btree.New(32)}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if _, ok := am[tt.rev]; ok || tt.rev.GreaterThan(revision{main: i}) {
|
if _, ok := am[tt.rev]; ok || tt.rev.GreaterThan(revision{main: i}) {
|
||||||
if tt.remove {
|
if tt.remove {
|
||||||
wti.Tombstone(tt.key, tt.rev)
|
wti.Tombstone(tt.key, tt.rev)
|
||||||
} else {
|
} 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)
|
am := ti.Compact(i)
|
||||||
|
|
||||||
wti := newTreeIndex()
|
wti := &treeIndex{tree: btree.New(32)}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if _, ok := am[tt.rev]; ok || tt.rev.GreaterThan(revision{main: i}) {
|
if _, ok := am[tt.rev]; ok || tt.rev.GreaterThan(revision{main: i}) {
|
||||||
if tt.remove {
|
if tt.remove {
|
||||||
wti.Tombstone(tt.key, tt.rev)
|
wti.Tombstone(tt.key, tt.rev)
|
||||||
} else {
|
} 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) {
|
func restore(ti *treeIndex, key []byte, created, modified revision, ver int64) {
|
||||||
key := []byte("foo")
|
keyi := &keyIndex{key: key}
|
||||||
|
|
||||||
tests := []struct {
|
ti.Lock()
|
||||||
created revision
|
defer ti.Unlock()
|
||||||
modified revision
|
item := ti.tree.Get(keyi)
|
||||||
ver int64
|
if item == nil {
|
||||||
}{
|
keyi.restore(created, modified, ver)
|
||||||
{revision{1, 0}, revision{1, 0}, 1},
|
ti.tree.ReplaceOrInsert(keyi)
|
||||||
{revision{1, 0}, revision{1, 1}, 2},
|
return
|
||||||
{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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
okeyi := item.(*keyIndex)
|
||||||
|
okeyi.put(modified.main, modified.sub)
|
||||||
}
|
}
|
||||||
|
@ -655,9 +655,6 @@ func (i *fakeIndex) Range(key, end []byte, atRev int64) ([][]byte, []revision) {
|
|||||||
func (i *fakeIndex) Put(key []byte, rev revision) {
|
func (i *fakeIndex) Put(key []byte, rev revision) {
|
||||||
i.Recorder.Record(testutil.Action{Name: "put", Params: []interface{}{key, rev}})
|
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 {
|
func (i *fakeIndex) Tombstone(key []byte, rev revision) error {
|
||||||
i.Recorder.Record(testutil.Action{Name: "tombstone", Params: []interface{}{key, rev}})
|
i.Recorder.Record(testutil.Action{Name: "tombstone", Params: []interface{}{key, rev}})
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user