store/consul: Watch() should work even if the key doesn't exist.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2015-05-15 03:52:16 -07:00
parent c77f7332a0
commit 2cdca520d9
1 changed files with 4 additions and 10 deletions

View File

@ -151,18 +151,16 @@ func (s *Consul) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, erro
return return
default: default:
} }
pair, meta, err := kv.Get(key, opts) pair, meta, err := kv.Get(key, opts)
if err != nil { if err != nil {
log.WithField("backend", "consul").Error(err) log.WithField("backend", "consul").Error(err)
return return
} }
if pair == nil {
log.WithField("backend", "consul").Errorf("Key %s does not exist", key)
return
}
opts.WaitIndex = meta.LastIndex opts.WaitIndex = meta.LastIndex
watchCh <- &KVPair{pair.Key, pair.Value, pair.ModifyIndex} // FIXME: What happens when a key is deleted?
if pair != nil {
watchCh <- &KVPair{pair.Key, pair.Value, pair.ModifyIndex}
}
} }
}() }()
@ -193,10 +191,6 @@ func (s *Consul) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVP
log.WithField("name", "consul").Error(err) log.WithField("name", "consul").Error(err)
return return
} }
if len(pairs) == 0 {
log.WithField("name", "consul").Errorf("Key %s does not exist", prefix)
return
}
kv := []*KVPair{} kv := []*KVPair{}
for _, pair := range pairs { for _, pair := range pairs {
if pair.Key == prefix { if pair.Key == prefix {