MCPcopy Index your code
hub / github.com/CodisLabs/codis / WatchInOrder

Method WatchInOrder

pkg/models/etcd/etcdclient.go:301–345  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

299}
300
301func (c *Client) WatchInOrder(path string) (<-chan struct{}, []string, error) {
302 if err := c.Mkdir(path); err != nil {
303 return nil, nil, err
304 }
305 c.Lock()
306 defer c.Unlock()
307 if c.closed {
308 return nil, nil, errors.Trace(ErrClosedClient)
309 }
310 log.Debugf("etcd watch-inorder node %s", path)
311 cntx, cancel := c.newContext()
312 defer cancel()
313 r, err := c.kapi.Get(cntx, path, &client.GetOptions{Quorum: true, Sort: true})
314 switch {
315 case err != nil:
316 log.Debugf("etcd watch-inorder node %s failed: %s", path, err)
317 return nil, nil, errors.Trace(err)
318 case !r.Node.Dir:
319 log.Debugf("etcd watch-inorder node %s failed: not a dir", path)
320 return nil, nil, errors.Trace(ErrNotDir)
321 }
322 var index = r.Index
323 var paths []string
324 for _, node := range r.Node.Nodes {
325 paths = append(paths, node.Key)
326 }
327 signal := make(chan struct{})
328 go func() {
329 defer close(signal)
330 watch := c.kapi.Watcher(path, &client.WatcherOptions{AfterIndex: index})
331 for {
332 r, err := watch.Next(c.context)
333 switch {
334 case err != nil:
335 log.Debugf("etch watch-inorder node %s failed: %s", path, err)
336 return
337 case r.Action != "get":
338 log.Debugf("etcd watch-inorder node %s update", path)
339 return
340 }
341 }
342 }()
343 log.Debugf("etcd watch-inorder OK")
344 return signal, paths, nil
345}

Callers

nothing calls this directly

Calls 5

MkdirMethod · 0.95
newContextMethod · 0.95
DebugfMethod · 0.80
NextMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected