Removed redundant comments and unit test
This commit is contained in:
parent
1503d63595
commit
a6b7e66e9a
|
@ -429,8 +429,6 @@ func (s *Store) kvsDeleteTreeTxn(tx *memdb.Txn, idx uint64, prefix string) error
|
||||||
return fmt.Errorf("failed recursive deleting kvs entry: %s", err)
|
return fmt.Errorf("failed recursive deleting kvs entry: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the index if the delete was successful.
|
|
||||||
// Missing prefixes don't result in an index update
|
|
||||||
if deleted {
|
if deleted {
|
||||||
if err := s.kvsGraveyard.InsertTxn(tx, prefix, idx); err != nil {
|
if err := s.kvsGraveyard.InsertTxn(tx, prefix, idx); err != nil {
|
||||||
return fmt.Errorf("failed adding to graveyard: %s", err)
|
return fmt.Errorf("failed adding to graveyard: %s", err)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -1081,7 +1080,6 @@ func TestStateStore_Watches_PrefixDelete(t *testing.T) {
|
||||||
t.Fatalf("bad index: %d, expected %d", got, wantIndex)
|
t.Fatalf("bad index: %d, expected %d", got, wantIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = memdb.NewWatchSet()
|
|
||||||
// Set a different key to bump the index. This shouldn't fire the
|
// Set a different key to bump the index. This shouldn't fire the
|
||||||
// watch since there's a different prefix.
|
// watch since there's a different prefix.
|
||||||
testSetKey(t, s, 8, "some/other/key", "")
|
testSetKey(t, s, 8, "some/other/key", "")
|
||||||
|
@ -1089,6 +1087,7 @@ func TestStateStore_Watches_PrefixDelete(t *testing.T) {
|
||||||
// Now ask for the index for a node within the prefix that was deleted
|
// Now ask for the index for a node within the prefix that was deleted
|
||||||
// We expect to get the max index in the tree
|
// We expect to get the max index in the tree
|
||||||
wantIndex = 8
|
wantIndex = 8
|
||||||
|
ws = memdb.NewWatchSet()
|
||||||
got, _, err = s.KVSList(ws, "foo/bar/baz")
|
got, _, err = s.KVSList(ws, "foo/bar/baz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -1110,81 +1109,6 @@ func TestStateStore_Watches_PrefixDelete(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStateStore_KVSDeleteTreePrefix(t *testing.T) {
|
|
||||||
s := testStateStore(t)
|
|
||||||
|
|
||||||
// Create kvs entries in the state store.
|
|
||||||
for i := 0; i < 120; i++ {
|
|
||||||
ind := uint64(i + 1)
|
|
||||||
key := "foo/bar" + fmt.Sprintf("%d", ind)
|
|
||||||
testSetKey(t, s, ind, key, "bar")
|
|
||||||
}
|
|
||||||
testSetKey(t, s, 121, "foo/zorp", "zorp")
|
|
||||||
|
|
||||||
// Calling tree deletion which affects nothing does not
|
|
||||||
// modify the table index.
|
|
||||||
if err := s.KVSDeleteTree(129, "bar"); err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
if idx := s.maxIndex("kvs"); idx != 121 {
|
|
||||||
t.Fatalf("bad index: %d", idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call tree deletion with a nested prefix.
|
|
||||||
if err := s.KVSDeleteTree(122, "foo/bar"); err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that all the matching keys were deleted
|
|
||||||
tx := s.db.Txn(false)
|
|
||||||
defer tx.Abort()
|
|
||||||
|
|
||||||
entries, err := tx.Get("kvs", "id")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
num := 0
|
|
||||||
for entry := entries.Next(); entry != nil; entry = entries.Next() {
|
|
||||||
if entry.(*structs.DirEntry).Key != "foo/zorp" {
|
|
||||||
t.Fatalf("unexpected kvs entry: %#v", entry)
|
|
||||||
}
|
|
||||||
num++
|
|
||||||
}
|
|
||||||
|
|
||||||
if num != 1 {
|
|
||||||
t.Fatalf("expected 1 key, got: %d", num)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Index should be updated if modifications are made
|
|
||||||
if idx := s.maxIndex("kvs"); idx != 122 {
|
|
||||||
t.Fatalf("bad index: %d", idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that the tombstones ware created and that prevents the index
|
|
||||||
// from sliding backwards.
|
|
||||||
idx, _, err := s.KVSList(nil, "foo")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
if idx != 122 {
|
|
||||||
t.Fatalf("bad index: %d", idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now reap the tombstones and watch the index revert to the remaining
|
|
||||||
// foo/zorp key's index.
|
|
||||||
if err := s.ReapTombstones(122); err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
idx, _, err = s.KVSList(nil, "foo")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
if idx != 121 {
|
|
||||||
t.Fatalf("bad index: %d", idx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStateStore_KVSLockDelay(t *testing.T) {
|
func TestStateStore_KVSLockDelay(t *testing.T) {
|
||||||
s := testStateStore(t)
|
s := testStateStore(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue