mark4z commented on a change in pull request #367:
URL: https://github.com/apache/dubbo-go-pixiu/pull/367#discussion_r812601408



##########
File path: 
pkg/adapter/springcloud/servicediscovery/zookeeper/application_listener.go
##########
@@ -124,29 +119,43 @@ func (z *zkAppListener) watchEventHandle(children 
[]string, e <-chan zk.Event) b
 }
 
 func (z *zkAppListener) handleEvent(children []string) {
+
        fetchChildren, err := z.ds.getClient().GetChildren(z.servicesPath)
+
        if err != nil {
-               logger.Warnf("Error when retrieving newChildren in path: %s, 
Error:%s", z.servicesPath, err.Error())
+               // todo refactor gost zk, make it return the definite err
+               if strings.Contains(err.Error(), "none children") {
+                       logger.Debugf("%s get nodes from zookeeper fail: %s", 
common.ZKLogDiscovery, err.Error())
+               } else {
+                       logger.Warnf("Error when retrieving newChildren in 
path: %s, Error:%s", z.servicesPath, err.Error())
+               }
        }
 
        discovery := z.ds
+       serviceMap := discovery.getServiceMap()
+
+       // del services
+       for sn, _ := range serviceMap {
 
-       del := func() {
-               keys := Keys(discovery.getServiceMap())
-               diff := Diff(keys, fetchChildren)
-               if diff != nil {
-                       logger.Debugf("Del the service %s", diff)
-                       for _, sn := range diff {
-                               for _, instance := range 
discovery.getServiceMap()[sn] {
-                                       discovery.delServiceInstance(instance)
-                               }
+               if !contains(fetchChildren, sn) {

Review comment:
       fix this.

##########
File path: 
pkg/adapter/springcloud/servicediscovery/zookeeper/application_listener.go
##########
@@ -124,29 +119,43 @@ func (z *zkAppListener) watchEventHandle(children 
[]string, e <-chan zk.Event) b
 }
 
 func (z *zkAppListener) handleEvent(children []string) {
+
        fetchChildren, err := z.ds.getClient().GetChildren(z.servicesPath)
+
        if err != nil {
-               logger.Warnf("Error when retrieving newChildren in path: %s, 
Error:%s", z.servicesPath, err.Error())
+               // todo refactor gost zk, make it return the definite err
+               if strings.Contains(err.Error(), "none children") {
+                       logger.Debugf("%s get nodes from zookeeper fail: %s", 
common.ZKLogDiscovery, err.Error())
+               } else {
+                       logger.Warnf("Error when retrieving newChildren in 
path: %s, Error:%s", z.servicesPath, err.Error())
+               }
        }
 
        discovery := z.ds
+       serviceMap := discovery.getServiceMap()
+
+       // del services
+       for sn, _ := range serviceMap {
 
-       del := func() {
-               keys := Keys(discovery.getServiceMap())
-               diff := Diff(keys, fetchChildren)
-               if diff != nil {
-                       logger.Debugf("Del the service %s", diff)
-                       for _, sn := range diff {
-                               for _, instance := range 
discovery.getServiceMap()[sn] {
-                                       discovery.delServiceInstance(instance)
-                               }
+               if !contains(fetchChildren, sn) {
+
+                       // service zk event listener
+                       serviceNodePath := 
strings.Join([]string{z.servicesPath, sn}, constant.PathSlash)
+                       z.svcListeners.RemoveListener(serviceNodePath)
+
+                       // service cluster
+                       for _, instance := range serviceMap[sn] {
+                               _, _ = discovery.delServiceInstance(instance)
                        }
                }
        }
-       del()
 
        for _, serviceName := range fetchChildren {
                serviceNodePath := strings.Join([]string{z.servicesPath, 
serviceName}, constant.PathSlash)
+               instances := serviceMap[serviceName]
+               if instances == nil || len(instances) == 0 {
+                       z.svcListeners.RemoveListener(serviceNodePath)

Review comment:
       Same




-- 
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]

Reply via email to