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 2020/09/16 14:51:16 UTC

[GitHub] [dubbo-go] beiwei30 commented on a change in pull request #758: fix #750. registry center notify with complete address list

beiwei30 commented on a change in pull request #758:
URL: https://github.com/apache/dubbo-go/pull/758#discussion_r489499773



##########
File path: registry/directory/directory.go
##########
@@ -104,44 +104,65 @@ func (dir *RegistryDirectory) subscribe(url *common.URL) {
 }
 
 // Notify monitor changes from registry,and update the cacheServices
-func (dir *RegistryDirectory) Notify(events ...*registry.ServiceEvent) {
-	go dir.refreshInvokers(events...)
+func (dir *RegistryDirectory) Notify(event *registry.ServiceEvent) {
+	if event == nil {
+		return
+	}
+	go dir.refreshInvokers(event)
 }
 
-// refreshInvokers refreshes service's events. It supports two modes: incremental mode and batch mode. If a single
-// service event is passed in, then it is incremental mode, and if an array of service events are passed in, it is
-// batch mode, in this mode, we assume the registry center have the complete list of the service events, therefore
-// in this case, we can safely assume any cached invoker not in the incoming list can be removed. It is necessary
-// since in batch mode, the register center handles the different type of events by itself, then notify the directory
-// a batch of 'Update' events, instead of omit the different type of event one by one.
-func (dir *RegistryDirectory) refreshInvokers(events ...*registry.ServiceEvent) {
-	var oldInvokers []protocol.Invoker
-
-	// in batch mode, it is safe to remove since we have the complete list of events.
-	if len(events) > 1 {
-		dir.cacheInvokersMap.Range(func(k, v interface{}) bool {
-			if !dir.eventMatched(k.(string), events) {
-				if invoker := dir.uncacheInvokerWithKey(k.(string)); invoker != nil {
-					oldInvokers = append(oldInvokers, invoker)
-				}
-			}
-			return true
-		})
+func (dir *RegistryDirectory) NotifyAll(events []*registry.ServiceEvent) {
+	go dir.refreshAllInvokers(events)
+}
+
+// refreshInvokers refreshes service's events.
+func (dir *RegistryDirectory) refreshInvokers(event *registry.ServiceEvent) {
+	logger.Debugf("refresh invokers with %+v", event)
+	var oldInvoker protocol.Invoker
+	if event != nil {
+		oldInvoker, _ = dir.cacheInvokerByEvent(event)
+	}
+	dir.setNewInvokers()
+	if oldInvoker != nil {
+		oldInvoker.Destroy()
 	}
+}
+
+// refreshAllInvokers the argument is the complete list of the service events,  we can safely assume any cached invoker
+// not in the incoming list can be removed.  It will ignore Action of serviceEvent.
+func (dir *RegistryDirectory) refreshAllInvokers(events []*registry.ServiceEvent) {
+	var (
+		oldInvokers []protocol.Invoker
+		addEvents   []*registry.ServiceEvent
+	)
 
+	// get need clear invokers from original invoker list
+	dir.cacheInvokersMap.Range(func(k, v interface{}) bool {
+		if !dir.eventMatched(k.(string), events) {
+			// delete unused invoker from cache
+			if invoker := dir.uncacheInvokerWithKey(k.(string)); invoker != nil {
+				oldInvokers = append(oldInvokers, invoker)
+			}
+		}
+		return true
+	})
+	// get need add invokers from events
 	for _, event := range events {
+		// Is the key (url.Key()) of cacheInvokersMap the best way?

Review comment:
       this is necessary, we should assume (safely) that all events are UPDATE events, otherwise how would you process DELETE events? plus, per the comment on the interface:
   
   ```
   // The argument of events []*ServiceEvent is equal to urls []*URL, because Action of ServiceEvent will be ignored.
   ```




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

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