wudong5 commented on code in PR #2267:
URL: https://github.com/apache/dubbo-go/pull/2267#discussion_r1156786291
##########
remoting/zookeeper/listener.go:
##########
@@ -238,8 +239,91 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string,
children []string, li
listener.DataChange(remoting.Event{Path: oldNode, Action:
remoting.EventTypeDel})
}
}
-func (l *ZkEventListener) listenDirEvent(conf *common.URL, zkRootPath string,
listener remoting.DataListener) {
+
+// listenerAllDirEvent listen all services when conf.InterfaceKey = "*"
+func (l *ZkEventListener) listenAllDirEvent(conf *common.URL, listener
remoting.DataListener) {
+ var (
+ failTimes int
+ ttl time.Duration
+ )
+ ttl = defaultTTL
+ if conf != nil {
+ timeout, err :=
time.ParseDuration(conf.GetParam(constant.RegistryTTLKey,
constant.DefaultRegTTL))
+ if err == nil {
+ ttl = timeout
+ } else {
+ logger.Warnf("[Zookeeper EventListener][listenDirEvent]
Wrong configuration for registry.ttl, error=%+v, using default value %v
instead", err, defaultTTL)
+ }
+ }
+ if ttl > 20e9 {
+ ttl = 20e9
+ }
+
+ rootPath := path.Join(constant.PathSeparator, constant.Dubbo)
+ for {
+ // get all interfaces
+ children, childEventCh, err := l.Client.GetChildrenW(rootPath)
+ if err != nil {
+ failTimes++
+ if MaxFailTimes <= failTimes {
+ failTimes = MaxFailTimes
+ }
+ logger.Errorf("[Zookeeper
EventListener][listenDirEvent] Get children of path {%s} with watcher failed,
the error is %+v", rootPath, err)
+ // Maybe the zookeeper does not ready yet, sleep
failTimes * ConnDelay senconds to wait
+ after := time.After(timeSecondDuration(failTimes *
ConnDelay))
+ select {
+ case <-after:
+ continue
+ case <-l.exit:
+ return
+ }
+ }
+ failTimes = 0
+ if len(children) == 0 {
+ logger.Debugf("[Zookeeper
EventListener][listenDirEvent] Can not gey any children for the path {%s},
please check if the provider does ready.", rootPath)
+ }
+ for _, c := range children {
+ // Build the children path
+ zkRootPath := path.Join(rootPath,
constant.PathSeparator, url.QueryEscape(c), constant.PathSeparator,
constant.ProvidersCategory)
+ // Save the path to avoid listen repeatedly
+ l.pathMapLock.Lock()
Review Comment:
If use defer, maybe there will be a deadlock, because, the lock() is on a
for loop. Besides,it will increase the range of locks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]