From 710da6479e4b3cb4081eed88600cf63406f74be7 Mon Sep 17 00:00:00 2001 From: Alexandre Beslic Date: Wed, 3 Jun 2015 13:10:44 -0700 Subject: [PATCH] fix zookeeper single Key watch Signed-off-by: Alexandre Beslic --- pkg/store/zookeeper.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/store/zookeeper.go b/pkg/store/zookeeper.go index d7d977ac8d..acf7053595 100644 --- a/pkg/store/zookeeper.go +++ b/pkg/store/zookeeper.go @@ -121,7 +121,7 @@ func (s *Zookeeper) Exists(key string) (bool, error) { // Providing a non-nil stopCh can be used to stop watching. func (s *Zookeeper) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, error) { fkey := normalize(key) - resp, meta, eventCh, err := s.client.GetW(fkey) + pair, err := s.Get(key) if err != nil { return nil, err } @@ -131,9 +131,13 @@ func (s *Zookeeper) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, e go func() { defer close(watchCh) - // GetW returns the current value before setting the watch. - watchCh <- &KVPair{key, resp, uint64(meta.Version)} + // Get returns the current value before setting the watch. + watchCh <- pair for { + _, _, eventCh, err := s.client.GetW(fkey) + if err != nil { + return + } select { case e := <-eventCh: if e.Type == zk.EventNodeDataChanged {