|
@@ -72,7 +72,7 @@ func TestStorePut(t *testing.T) {
|
|
|
indexGetResp{revision{}, revision{}, 0, ErrRevisionNotFound},
|
|
indexGetResp{revision{}, revision{}, 0, ErrRevisionNotFound},
|
|
|
nil,
|
|
nil,
|
|
|
|
|
|
|
|
- revision{1, 1},
|
|
|
|
|
|
|
+ revision{2, 0},
|
|
|
newTestKeyBytes(revision{2, 0}, false),
|
|
newTestKeyBytes(revision{2, 0}, false),
|
|
|
mvccpb.KeyValue{
|
|
mvccpb.KeyValue{
|
|
|
Key: []byte("foo"),
|
|
Key: []byte("foo"),
|
|
@@ -89,8 +89,8 @@ func TestStorePut(t *testing.T) {
|
|
|
indexGetResp{revision{2, 0}, revision{2, 0}, 1, nil},
|
|
indexGetResp{revision{2, 0}, revision{2, 0}, 1, nil},
|
|
|
&rangeResp{[][]byte{newTestKeyBytes(revision{2, 1}, false)}, [][]byte{kvb}},
|
|
&rangeResp{[][]byte{newTestKeyBytes(revision{2, 1}, false)}, [][]byte{kvb}},
|
|
|
|
|
|
|
|
- revision{1, 2},
|
|
|
|
|
- newTestKeyBytes(revision{2, 1}, false),
|
|
|
|
|
|
|
+ revision{2, 0},
|
|
|
|
|
+ newTestKeyBytes(revision{2, 0}, false),
|
|
|
mvccpb.KeyValue{
|
|
mvccpb.KeyValue{
|
|
|
Key: []byte("foo"),
|
|
Key: []byte("foo"),
|
|
|
Value: []byte("bar"),
|
|
Value: []byte("bar"),
|
|
@@ -99,14 +99,14 @@ func TestStorePut(t *testing.T) {
|
|
|
Version: 2,
|
|
Version: 2,
|
|
|
Lease: 2,
|
|
Lease: 2,
|
|
|
},
|
|
},
|
|
|
- revision{2, 1},
|
|
|
|
|
|
|
+ revision{2, 0},
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
revision{2, 0},
|
|
revision{2, 0},
|
|
|
indexGetResp{revision{2, 1}, revision{2, 0}, 2, nil},
|
|
indexGetResp{revision{2, 1}, revision{2, 0}, 2, nil},
|
|
|
&rangeResp{[][]byte{newTestKeyBytes(revision{2, 1}, false)}, [][]byte{kvb}},
|
|
&rangeResp{[][]byte{newTestKeyBytes(revision{2, 1}, false)}, [][]byte{kvb}},
|
|
|
|
|
|
|
|
- revision{2, 1},
|
|
|
|
|
|
|
+ revision{3, 0},
|
|
|
newTestKeyBytes(revision{3, 0}, false),
|
|
newTestKeyBytes(revision{3, 0}, false),
|
|
|
mvccpb.KeyValue{
|
|
mvccpb.KeyValue{
|
|
|
Key: []byte("foo"),
|
|
Key: []byte("foo"),
|
|
@@ -124,14 +124,13 @@ func TestStorePut(t *testing.T) {
|
|
|
b := s.b.(*fakeBackend)
|
|
b := s.b.(*fakeBackend)
|
|
|
fi := s.kvindex.(*fakeIndex)
|
|
fi := s.kvindex.(*fakeIndex)
|
|
|
|
|
|
|
|
- s.currentRev = tt.rev
|
|
|
|
|
- s.tx = b.BatchTx()
|
|
|
|
|
|
|
+ s.currentRev = tt.rev.main
|
|
|
fi.indexGetRespc <- tt.r
|
|
fi.indexGetRespc <- tt.r
|
|
|
if tt.rr != nil {
|
|
if tt.rr != nil {
|
|
|
b.tx.rangeRespc <- *tt.rr
|
|
b.tx.rangeRespc <- *tt.rr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- s.put([]byte("foo"), []byte("bar"), lease.LeaseID(i+1))
|
|
|
|
|
|
|
+ s.Put([]byte("foo"), []byte("bar"), lease.LeaseID(i+1))
|
|
|
|
|
|
|
|
data, err := tt.wkv.Marshal()
|
|
data, err := tt.wkv.Marshal()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -158,7 +157,7 @@ func TestStorePut(t *testing.T) {
|
|
|
if g := fi.Action(); !reflect.DeepEqual(g, wact) {
|
|
if g := fi.Action(); !reflect.DeepEqual(g, wact) {
|
|
|
t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
|
|
t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
|
|
|
}
|
|
}
|
|
|
- if s.currentRev != tt.wrev {
|
|
|
|
|
|
|
+ if s.currentRev != tt.wrev.main {
|
|
|
t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
|
|
t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -179,7 +178,6 @@ func TestStoreRange(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- currev := revision{1, 1}
|
|
|
|
|
wrev := int64(2)
|
|
wrev := int64(2)
|
|
|
|
|
|
|
|
tests := []struct {
|
|
tests := []struct {
|
|
@@ -195,25 +193,26 @@ func TestStoreRange(t *testing.T) {
|
|
|
rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ ro := RangeOptions{Limit: 1, Rev: 0, Count: false}
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
s := newFakeStore()
|
|
s := newFakeStore()
|
|
|
b := s.b.(*fakeBackend)
|
|
b := s.b.(*fakeBackend)
|
|
|
fi := s.kvindex.(*fakeIndex)
|
|
fi := s.kvindex.(*fakeIndex)
|
|
|
|
|
|
|
|
- s.currentRev = currev
|
|
|
|
|
- s.tx = b.BatchTx()
|
|
|
|
|
|
|
+ s.currentRev = 2
|
|
|
b.tx.rangeRespc <- tt.r
|
|
b.tx.rangeRespc <- tt.r
|
|
|
fi.indexRangeRespc <- tt.idxr
|
|
fi.indexRangeRespc <- tt.idxr
|
|
|
|
|
|
|
|
- kvs, _, rev, err := s.rangeKeys([]byte("foo"), []byte("goo"), 1, 0, false)
|
|
|
|
|
|
|
+ ret, err := s.Range([]byte("foo"), []byte("goo"), ro)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Errorf("#%d: err = %v, want nil", i, err)
|
|
t.Errorf("#%d: err = %v, want nil", i, err)
|
|
|
}
|
|
}
|
|
|
- if w := []mvccpb.KeyValue{kv}; !reflect.DeepEqual(kvs, w) {
|
|
|
|
|
- t.Errorf("#%d: kvs = %+v, want %+v", i, kvs, w)
|
|
|
|
|
|
|
+ if w := []mvccpb.KeyValue{kv}; !reflect.DeepEqual(ret.KVs, w) {
|
|
|
|
|
+ t.Errorf("#%d: kvs = %+v, want %+v", i, ret.KVs, w)
|
|
|
}
|
|
}
|
|
|
- if rev != wrev {
|
|
|
|
|
- t.Errorf("#%d: rev = %d, want %d", i, rev, wrev)
|
|
|
|
|
|
|
+ if ret.Rev != wrev {
|
|
|
|
|
+ t.Errorf("#%d: rev = %d, want %d", i, ret.Rev, wrev)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
wstart, wend := revBytesRange(tt.idxr.revs[0])
|
|
wstart, wend := revBytesRange(tt.idxr.revs[0])
|
|
@@ -229,8 +228,8 @@ func TestStoreRange(t *testing.T) {
|
|
|
if g := fi.Action(); !reflect.DeepEqual(g, wact) {
|
|
if g := fi.Action(); !reflect.DeepEqual(g, wact) {
|
|
|
t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
|
|
t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
|
|
|
}
|
|
}
|
|
|
- if s.currentRev != currev {
|
|
|
|
|
- t.Errorf("#%d: current rev = %+v, want %+v", i, s.currentRev, currev)
|
|
|
|
|
|
|
+ if s.currentRev != 2 {
|
|
|
|
|
+ t.Errorf("#%d: current rev = %+v, want %+v", i, s.currentRev, 2)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
s.Close()
|
|
s.Close()
|
|
@@ -267,32 +266,21 @@ func TestStoreDeleteRange(t *testing.T) {
|
|
|
rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
|
|
|
|
|
|
newTestKeyBytes(revision{3, 0}, true),
|
|
newTestKeyBytes(revision{3, 0}, true),
|
|
|
- revision{2, 1},
|
|
|
|
|
|
|
+ revision{3, 0},
|
|
|
2,
|
|
2,
|
|
|
revision{3, 0},
|
|
revision{3, 0},
|
|
|
},
|
|
},
|
|
|
- {
|
|
|
|
|
- revision{2, 1},
|
|
|
|
|
- indexRangeResp{[][]byte{[]byte("foo")}, []revision{{2, 0}}},
|
|
|
|
|
- rangeResp{[][]byte{key}, [][]byte{kvb}},
|
|
|
|
|
-
|
|
|
|
|
- newTestKeyBytes(revision{3, 1}, true),
|
|
|
|
|
- revision{2, 2},
|
|
|
|
|
- 3,
|
|
|
|
|
- revision{3, 1},
|
|
|
|
|
- },
|
|
|
|
|
}
|
|
}
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
s := newFakeStore()
|
|
s := newFakeStore()
|
|
|
b := s.b.(*fakeBackend)
|
|
b := s.b.(*fakeBackend)
|
|
|
fi := s.kvindex.(*fakeIndex)
|
|
fi := s.kvindex.(*fakeIndex)
|
|
|
|
|
|
|
|
- s.currentRev = tt.rev
|
|
|
|
|
- s.tx = b.BatchTx()
|
|
|
|
|
|
|
+ s.currentRev = tt.rev.main
|
|
|
fi.indexRangeRespc <- tt.r
|
|
fi.indexRangeRespc <- tt.r
|
|
|
b.tx.rangeRespc <- tt.rr
|
|
b.tx.rangeRespc <- tt.rr
|
|
|
|
|
|
|
|
- n := s.deleteRange([]byte("foo"), []byte("goo"))
|
|
|
|
|
|
|
+ n, _ := s.DeleteRange([]byte("foo"), []byte("goo"))
|
|
|
if n != 1 {
|
|
if n != 1 {
|
|
|
t.Errorf("#%d: n = %d, want 1", i, n)
|
|
t.Errorf("#%d: n = %d, want 1", i, n)
|
|
|
}
|
|
}
|
|
@@ -316,7 +304,7 @@ func TestStoreDeleteRange(t *testing.T) {
|
|
|
if g := fi.Action(); !reflect.DeepEqual(g, wact) {
|
|
if g := fi.Action(); !reflect.DeepEqual(g, wact) {
|
|
|
t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
|
|
t.Errorf("#%d: index action = %+v, want %+v", i, g, wact)
|
|
|
}
|
|
}
|
|
|
- if s.currentRev != tt.wrev {
|
|
|
|
|
|
|
+ if s.currentRev != tt.wrev.main {
|
|
|
t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
|
|
t.Errorf("#%d: rev = %+v, want %+v", i, s.currentRev, tt.wrev)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -328,7 +316,7 @@ func TestStoreCompact(t *testing.T) {
|
|
|
b := s.b.(*fakeBackend)
|
|
b := s.b.(*fakeBackend)
|
|
|
fi := s.kvindex.(*fakeIndex)
|
|
fi := s.kvindex.(*fakeIndex)
|
|
|
|
|
|
|
|
- s.currentRev = revision{3, 0}
|
|
|
|
|
|
|
+ s.currentRev = 3
|
|
|
fi.indexCompactRespc <- map[revision]struct{}{{1, 0}: {}}
|
|
fi.indexCompactRespc <- map[revision]struct{}{{1, 0}: {}}
|
|
|
key1 := newTestKeyBytes(revision{1, 0}, false)
|
|
key1 := newTestKeyBytes(revision{1, 0}, false)
|
|
|
key2 := newTestKeyBytes(revision{2, 0}, false)
|
|
key2 := newTestKeyBytes(revision{2, 0}, false)
|
|
@@ -393,9 +381,8 @@ func TestStoreRestore(t *testing.T) {
|
|
|
if s.compactMainRev != 3 {
|
|
if s.compactMainRev != 3 {
|
|
|
t.Errorf("compact rev = %d, want 5", s.compactMainRev)
|
|
t.Errorf("compact rev = %d, want 5", s.compactMainRev)
|
|
|
}
|
|
}
|
|
|
- wrev := revision{5, 0}
|
|
|
|
|
- if !reflect.DeepEqual(s.currentRev, wrev) {
|
|
|
|
|
- t.Errorf("current rev = %v, want %v", s.currentRev, wrev)
|
|
|
|
|
|
|
+ if s.currentRev != 5 {
|
|
|
|
|
+ t.Errorf("current rev = %v, want 5", s.currentRev)
|
|
|
}
|
|
}
|
|
|
wact := []testutil.Action{
|
|
wact := []testutil.Action{
|
|
|
{"range", []interface{}{metaBucketName, finishedCompactKeyName, []byte(nil), int64(0)}},
|
|
{"range", []interface{}{metaBucketName, finishedCompactKeyName, []byte(nil), int64(0)}},
|
|
@@ -479,18 +466,12 @@ func TestTxnPut(t *testing.T) {
|
|
|
defer cleanup(s, b, tmpPath)
|
|
defer cleanup(s, b, tmpPath)
|
|
|
|
|
|
|
|
for i := 0; i < sliceN; i++ {
|
|
for i := 0; i < sliceN; i++ {
|
|
|
- id := s.TxnBegin()
|
|
|
|
|
|
|
+ txn := s.Write()
|
|
|
base := int64(i + 2)
|
|
base := int64(i + 2)
|
|
|
-
|
|
|
|
|
- rev, err := s.TxnPut(id, keys[i], vals[i], lease.NoLease)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- t.Error("txn put error")
|
|
|
|
|
- }
|
|
|
|
|
- if rev != base {
|
|
|
|
|
|
|
+ if rev := txn.Put(keys[i], vals[i], lease.NoLease); rev != base {
|
|
|
t.Errorf("#%d: rev = %d, want %d", i, rev, base)
|
|
t.Errorf("#%d: rev = %d, want %d", i, rev, base)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- s.TxnEnd(id)
|
|
|
|
|
|
|
+ txn.End()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -499,7 +480,7 @@ func TestTxnBlockBackendForceCommit(t *testing.T) {
|
|
|
s := NewStore(b, &lease.FakeLessor{}, nil)
|
|
s := NewStore(b, &lease.FakeLessor{}, nil)
|
|
|
defer os.Remove(tmpPath)
|
|
defer os.Remove(tmpPath)
|
|
|
|
|
|
|
|
- id := s.TxnBegin()
|
|
|
|
|
|
|
+ txn := s.Read()
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
done := make(chan struct{})
|
|
|
go func() {
|
|
go func() {
|
|
@@ -512,7 +493,7 @@ func TestTxnBlockBackendForceCommit(t *testing.T) {
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- s.TxnEnd(id)
|
|
|
|
|
|
|
+ txn.End()
|
|
|
select {
|
|
select {
|
|
|
case <-done:
|
|
case <-done:
|
|
|
case <-time.After(5 * time.Second): // wait 5 seconds for CI with slow IO
|
|
case <-time.After(5 * time.Second): // wait 5 seconds for CI with slow IO
|
|
@@ -562,15 +543,17 @@ func newFakeStore() *store {
|
|
|
indexRangeEventsRespc: make(chan indexRangeEventsResp, 1),
|
|
indexRangeEventsRespc: make(chan indexRangeEventsResp, 1),
|
|
|
indexCompactRespc: make(chan map[revision]struct{}, 1),
|
|
indexCompactRespc: make(chan map[revision]struct{}, 1),
|
|
|
}
|
|
}
|
|
|
- return &store{
|
|
|
|
|
|
|
+ s := &store{
|
|
|
b: b,
|
|
b: b,
|
|
|
le: &lease.FakeLessor{},
|
|
le: &lease.FakeLessor{},
|
|
|
kvindex: fi,
|
|
kvindex: fi,
|
|
|
- currentRev: revision{},
|
|
|
|
|
|
|
+ currentRev: 0,
|
|
|
compactMainRev: -1,
|
|
compactMainRev: -1,
|
|
|
fifoSched: schedule.NewFIFOScheduler(),
|
|
fifoSched: schedule.NewFIFOScheduler(),
|
|
|
stopc: make(chan struct{}),
|
|
stopc: make(chan struct{}),
|
|
|
}
|
|
}
|
|
|
|
|
+ s.ReadView, s.WriteView = &readView{s}, &writeView{s}
|
|
|
|
|
+ return s
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type rangeResp struct {
|
|
type rangeResp struct {
|
|
@@ -611,6 +594,7 @@ type fakeBackend struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
|
|
func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
|
|
|
|
|
+func (b *fakeBackend) ReadTx() backend.ReadTx { return b.tx }
|
|
|
func (b *fakeBackend) Hash(ignores map[backend.IgnoreKey]struct{}) (uint32, error) { return 0, nil }
|
|
func (b *fakeBackend) Hash(ignores map[backend.IgnoreKey]struct{}) (uint32, error) { return 0, nil }
|
|
|
func (b *fakeBackend) Size() int64 { return 0 }
|
|
func (b *fakeBackend) Size() int64 { return 0 }
|
|
|
func (b *fakeBackend) Snapshot() backend.Snapshot { return nil }
|
|
func (b *fakeBackend) Snapshot() backend.Snapshot { return nil }
|