Merge pull request #881 from abronan/consul_cas_fix

store: Fix CAS returning ErrKeyModified because of Lock in Consul
This commit is contained in:
Andrea Luzzardi
2015-06-04 11:44:21 -07:00

View File

@@ -124,7 +124,11 @@ 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{
AllowStale: false,
RequireConsistent: true,
}
pair, meta, err := s.client.KV().Get(s.normalize(key), options)
if err != nil {
return nil, err
}
@@ -347,14 +351,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