You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/08 09:49:55 UTC

[GitHub] [dubbo-go] flycash commented on a change in pull request #1368: Refactor to remove event dispatcher completely

flycash commented on a change in pull request #1368:
URL: https://github.com/apache/dubbo-go/pull/1368#discussion_r704234145



##########
File path: registry/etcdv3/service_discovery.go
##########
@@ -215,31 +216,19 @@ func (e *etcdV3ServiceDiscovery) GetRequestInstances(serviceNames []string, offs
 // see addServiceInstancesChangedListener in Java
 func (e *etcdV3ServiceDiscovery) AddListener(listener registry.ServiceInstancesChangedListener) error {
 	for _, t := range listener.GetServiceNames().Values() {
-		serviceName := t.(string)
-		err := e.registerSreviceWatcher(serviceName)
+		err2 := e.registerServiceInstanceListener(t.(string), listener)
+		if err2 != nil {
+			return err2
+		}
+
+		err := e.registerServiceWatcher(t.(string))

Review comment:
       ```go
   err := e.registerServiceInstanceListener(t.(string), listener)
   // ....
   err = e.registerServiceWatcher(t.(string))
   ```
   looks better?

##########
File path: registry/etcdv3/service_discovery.go
##########
@@ -282,7 +287,15 @@ func (e *etcdV3ServiceDiscovery) DataChange(eventType remoting.Event) bool {
 			instance.ServiceName = ""
 		}
 
-		if err := e.DispatchEventByServiceName(instance.ServiceName); err != nil {
+		// notify instance listener instance change
+		name := instance.ServiceName
+		instances := e.GetInstances(name)
+		for _, lis := range e.instanceListenerMap[instance.ServiceName].Values() {

Review comment:
       I am not sure if we should iterate all listeners even some of them return error.

##########
File path: registry/nacos/service_discovery.go
##########
@@ -210,8 +211,27 @@ func (n *nacosServiceDiscovery) GetRequestInstances(serviceNames []string, offse
 	return res
 }
 
+func (n *nacosServiceDiscovery) registerInstanceListener(listener registry.ServiceInstancesChangedListener) {
+	for _, t := range listener.GetServiceNames().Values() {

Review comment:
       it's not thread safe here. Should we think about `race condition`?




-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org