From c87a7a039e3fad6f5e9d9bde8f38ea297c47bc4f Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 14 Oct 2013 12:57:35 -0700 Subject: [PATCH] feat test both of the condidtion --- store/store.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/store/store.go b/store/store.go index ade44acd9..2ce2fc902 100644 --- a/store/store.go +++ b/store/store.go @@ -162,7 +162,9 @@ func (s *Store) TestAndSet(nodePath string, prevValue string, prevIndex uint64, return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, index, term) } - if n.Value == prevValue || n.ModifiedIndex == prevIndex { + // If both of the prevValue and prevIndex are given, we will test both of them. + // Command will be executed, only if both of the tests are successful. + if (prevValue == "" || n.Value == prevValue) && (prevIndex == 0 || n.ModifiedIndex == prevIndex) { e := newEvent(TestAndSet, nodePath, index, term) e.PrevValue = n.Value