mirror of https://github.com/docker/docs.git
store: Use KVEntry in Get() for consistency with GetRange()
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
d4bdb10d35
commit
93ad39c079
|
|
@ -81,15 +81,15 @@ 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) (value []byte, lastIndex uint64, err error) {
|
||||
func (s *Consul) Get(key string) (*KVEntry, error) {
|
||||
pair, meta, err := s.client.KV().Get(s.normalize(key), nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil, err
|
||||
}
|
||||
if pair == nil {
|
||||
return nil, 0, ErrKeyNotFound
|
||||
return nil, ErrKeyNotFound
|
||||
}
|
||||
return pair.Value, meta.LastIndex, nil
|
||||
return &KVEntry{pair.Key, pair.Value, meta.LastIndex}, nil
|
||||
}
|
||||
|
||||
// Put a value at "key"
|
||||
|
|
@ -110,7 +110,7 @@ func (s *Consul) Delete(key string) error {
|
|||
|
||||
// Exists checks that the key exists inside the store
|
||||
func (s *Consul) Exists(key string) (bool, error) {
|
||||
_, _, err := s.Get(key)
|
||||
_, err := s.Get(key)
|
||||
if err != nil && err == ErrKeyNotFound {
|
||||
return false, err
|
||||
}
|
||||
|
|
@ -158,13 +158,13 @@ func (s *Consul) Watch(key string, heartbeat time.Duration, callback WatchCallba
|
|||
|
||||
for _ = range eventChan {
|
||||
log.WithField("name", "consul").Debug("Key watch triggered")
|
||||
entry, index, err := s.Get(key)
|
||||
entry, err := s.Get(key)
|
||||
if err != nil {
|
||||
log.Error("Cannot refresh the key: ", fkey, ", cancelling watch")
|
||||
s.watches[fkey] = nil
|
||||
return err
|
||||
}
|
||||
callback(&KVEntry{key, entry, index})
|
||||
callback(entry)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -84,18 +84,18 @@ func (s *Etcd) createDirectory(path string) error {
|
|||
|
||||
// Get the value at "key", returns the last modified index
|
||||
// to use in conjunction to CAS calls
|
||||
func (s *Etcd) Get(key string) (value []byte, lastIndex uint64, err error) {
|
||||
func (s *Etcd) Get(key string) (*KVEntry, error) {
|
||||
result, err := s.client.Get(normalize(key), false, false)
|
||||
if err != nil {
|
||||
if etcdError, ok := err.(*etcd.EtcdError); ok {
|
||||
// Not a Directory or Not a file
|
||||
if etcdError.ErrorCode == 102 || etcdError.ErrorCode == 104 {
|
||||
return nil, 0, ErrKeyNotFound
|
||||
return nil, ErrKeyNotFound
|
||||
}
|
||||
}
|
||||
return nil, 0, err
|
||||
return nil, err
|
||||
}
|
||||
return []byte(result.Node.Value), result.Node.ModifiedIndex, nil
|
||||
return &KVEntry{result.Node.Key, []byte(result.Node.Value), result.Node.ModifiedIndex}, nil
|
||||
}
|
||||
|
||||
// Put a value at "key"
|
||||
|
|
@ -125,9 +125,9 @@ func (s *Etcd) Delete(key string) error {
|
|||
|
||||
// Exists checks if the key exists inside the store
|
||||
func (s *Etcd) Exists(key string) (bool, error) {
|
||||
value, _, err := s.Get(key)
|
||||
entry, err := s.Get(key)
|
||||
if err != nil {
|
||||
if err == ErrKeyNotFound || value == nil {
|
||||
if err == ErrKeyNotFound || entry.Value == nil {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
|
|
@ -149,13 +149,13 @@ func (s *Etcd) Watch(key string, _ time.Duration, callback WatchCallback) error
|
|||
|
||||
for _ = range watchChan {
|
||||
log.WithField("name", "etcd").Debug("Discovery watch triggered")
|
||||
entry, index, err := s.Get(key)
|
||||
entry, err := s.Get(key)
|
||||
if err != nil {
|
||||
log.Error("Cannot refresh the key: ", key, ", cancelling watch")
|
||||
s.watches[key] = nil
|
||||
return err
|
||||
}
|
||||
callback(&KVEntry{key, entry, index})
|
||||
callback(entry)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type Store interface {
|
|||
Put(key string, value []byte) error
|
||||
|
||||
// Get a value given its key
|
||||
Get(key string) (value []byte, lastIndex uint64, err error)
|
||||
Get(key string) (*KVEntry, error)
|
||||
|
||||
// Delete the value at the specified key
|
||||
Delete(key string) error
|
||||
|
|
|
|||
|
|
@ -47,15 +47,15 @@ func (s *Zookeeper) setTimeout(time time.Duration) {
|
|||
|
||||
// Get the value at "key", returns the last modified index
|
||||
// to use in conjunction to CAS calls
|
||||
func (s *Zookeeper) Get(key string) (value []byte, lastIndex uint64, err error) {
|
||||
func (s *Zookeeper) Get(key string) (*KVEntry, error) {
|
||||
resp, meta, err := s.client.Get(normalize(key))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil, err
|
||||
}
|
||||
if resp == nil {
|
||||
return nil, 0, ErrKeyNotFound
|
||||
return nil, ErrKeyNotFound
|
||||
}
|
||||
return resp, uint64(meta.Mzxid), nil
|
||||
return &KVEntry{key, resp, uint64(meta.Mzxid)}, nil
|
||||
}
|
||||
|
||||
// Create the entire path for a directory that does not exist
|
||||
|
|
@ -116,9 +116,9 @@ func (s *Zookeeper) Watch(key string, _ time.Duration, callback WatchCallback) e
|
|||
for e := range eventChan {
|
||||
if e.Type == zk.EventNodeChildrenChanged {
|
||||
log.WithField("name", "zk").Debug("Discovery watch triggered")
|
||||
entry, index, err := s.Get(key)
|
||||
entry, err := s.Get(key)
|
||||
if err == nil {
|
||||
callback(&KVEntry{key, []byte(entry), index})
|
||||
callback(entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue