mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
store: fix modifiedindex in node clone
This commit is contained in:
parent
766e0ad901
commit
9776e6d082
@ -369,10 +369,13 @@ func (n *node) Compare(prevValue string, prevIndex uint64) (ok bool, which int)
|
||||
// If the node is a key-value pair, it will clone the pair.
|
||||
func (n *node) Clone() *node {
|
||||
if !n.IsDir() {
|
||||
return newKV(n.store, n.Path, n.Value, n.CreatedIndex, n.Parent, n.ACL, n.ExpireTime)
|
||||
newkv := newKV(n.store, n.Path, n.Value, n.CreatedIndex, n.Parent, n.ACL, n.ExpireTime)
|
||||
newkv.ModifiedIndex = n.ModifiedIndex
|
||||
return newkv
|
||||
}
|
||||
|
||||
clone := newDir(n.store, n.Path, n.CreatedIndex, n.Parent, n.ACL, n.ExpireTime)
|
||||
clone.ModifiedIndex = n.ModifiedIndex
|
||||
|
||||
for key, child := range n.Children {
|
||||
clone.Children[key] = child.Clone()
|
||||
|
@ -789,9 +789,10 @@ func TestStoreWatchStream(t *testing.T) {
|
||||
// Ensure that the store can recover from a previously saved state.
|
||||
func TestStoreRecover(t *testing.T) {
|
||||
s := newStore()
|
||||
var eidx uint64 = 3
|
||||
var eidx uint64 = 4
|
||||
s.Create("/foo", true, "", false, Permanent)
|
||||
s.Create("/foo/x", false, "bar", false, Permanent)
|
||||
s.Update("/foo/x", "barbar", Permanent)
|
||||
s.Create("/foo/y", false, "baz", false, Permanent)
|
||||
b, err := s.Save()
|
||||
|
||||
@ -799,9 +800,11 @@ func TestStoreRecover(t *testing.T) {
|
||||
s2.Recovery(b)
|
||||
|
||||
e, err := s.Get("/foo/x", false, false)
|
||||
assert.Equal(t, e.Node.CreatedIndex, uint64(2), "")
|
||||
assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
|
||||
assert.Equal(t, e.EtcdIndex, eidx, "")
|
||||
assert.Nil(t, err, "")
|
||||
assert.Equal(t, *e.Node.Value, "bar", "")
|
||||
assert.Equal(t, *e.Node.Value, "barbar", "")
|
||||
|
||||
e, err = s.Get("/foo/y", false, false)
|
||||
assert.Equal(t, e.EtcdIndex, eidx, "")
|
||||
|
Loading…
x
Reference in New Issue
Block a user