From 3f6fbb5bffa809f7665f6adc43971280fcfd974e Mon Sep 17 00:00:00 2001 From: Alexandre Beslic Date: Sun, 31 May 2015 23:17:13 -0700 Subject: [PATCH 1/2] Fix CAS not working for Consul Signed-off-by: Alexandre Beslic --- pkg/store/consul.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/store/consul.go b/pkg/store/consul.go index 8f2c07e495..86825c682d 100644 --- a/pkg/store/consul.go +++ b/pkg/store/consul.go @@ -124,7 +124,10 @@ func (s *Consul) normalize(key string) string { // Get the value at "key", returns the last modified index // to use in conjunction to CAS calls func (s *Consul) Get(key string) (*KVPair, error) { - pair, meta, err := s.client.KV().Get(s.normalize(key), nil) + options := &api.QueryOptions{ + RequireConsistent: true, + } + pair, meta, err := s.client.KV().Get(s.normalize(key), options) if err != nil { return nil, err } @@ -347,14 +350,6 @@ func (s *Consul) AtomicPut(key string, value []byte, previous *KVPair, options * return false, nil, ErrPreviousNotSpecified } - lock, err := s.NewLock(key, nil) - if err != nil { - return false, nil, err - } - - lock.Lock() - defer lock.Unlock() - p := &api.KVPair{Key: s.normalize(key), Value: value, ModifyIndex: previous.LastIndex} if work, _, err := s.client.KV().CAS(p, nil); err != nil { return false, nil, err From 5a4bd67db367d4a3e4129e58977849be067fb019 Mon Sep 17 00:00:00 2001 From: Alexandre Beslic Date: Mon, 1 Jun 2015 09:30:43 -0700 Subject: [PATCH 2/2] Put AllowStale to false in Consul Get op Signed-off-by: Alexandre Beslic --- pkg/store/consul.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/store/consul.go b/pkg/store/consul.go index 86825c682d..dfcbb67ad2 100644 --- a/pkg/store/consul.go +++ b/pkg/store/consul.go @@ -125,6 +125,7 @@ func (s *Consul) normalize(key string) string { // to use in conjunction to CAS calls func (s *Consul) Get(key string) (*KVPair, error) { options := &api.QueryOptions{ + AllowStale: false, RequireConsistent: true, } pair, meta, err := s.client.KV().Get(s.normalize(key), options)