You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by la...@apache.org on 2021/09/24 05:07:01 UTC

[dubbo-go] branch hsf-go-dependency updated: Add uncache invoker event's service merge reference url. (#1480)

This is an automated email from the ASF dual-hosted git repository.

laurence pushed a commit to branch hsf-go-dependency
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/hsf-go-dependency by this push:
     new 00e03e3  Add uncache invoker event's service merge reference url. (#1480)
00e03e3 is described below

commit 00e03e3b815455856480313d7c7d2066c389c954
Author: Laurence <45...@users.noreply.github.com>
AuthorDate: Fri Sep 24 13:06:57 2021 +0800

    Add uncache invoker event's service merge reference url. (#1480)
    
    * fix: pb stub function bug
    
    * ftr: add gracefulshutdown callback
    
    * fix: remove client metadata report
    
    * fix: add registry dir event reference config overide
    
    * fix: add comment
---
 registry/directory/directory.go | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/registry/directory/directory.go b/registry/directory/directory.go
index 602ea57..508c617 100644
--- a/registry/directory/directory.go
+++ b/registry/directory/directory.go
@@ -250,6 +250,7 @@ func (dir *RegistryDirectory) setNewInvokers() {
 // cacheInvokerByEvent caches invokers from the service event
 func (dir *RegistryDirectory) cacheInvokerByEvent(event *registry.ServiceEvent) (protocol.Invoker, error) {
 	// judge is override or others
+	logger.Infof("get service update event %+v", *event)
 	if event != nil {
 		switch event.Action {
 		case remoting.EventTypeAdd, remoting.EventTypeUpdate:
@@ -262,7 +263,8 @@ func (dir *RegistryDirectory) cacheInvokerByEvent(event *registry.ServiceEvent)
 			return dir.cacheInvoker(u, event), nil
 		case remoting.EventTypeDel:
 			logger.Infof("selector delete service url{%s}", event.Service)
-			return dir.uncacheInvoker(event), nil
+			u := dir.convertUrl(event)
+			return dir.uncacheInvoker(u, event), nil
 		default:
 			return nil, fmt.Errorf("illegal event type: %v", event.Action)
 		}
@@ -324,7 +326,16 @@ func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {
 }
 
 // uncacheInvoker will return abandoned Invoker, if no Invoker to be abandoned, return nil
-func (dir *RegistryDirectory) uncacheInvoker(event *registry.ServiceEvent) protocol.Invoker {
+func (dir *RegistryDirectory) uncacheInvoker(url *common.URL, event *registry.ServiceEvent) protocol.Invoker {
+	dir.overrideUrl(dir.GetDirectoryUrl())
+	referenceUrl := dir.GetDirectoryUrl().SubURL
+	if url == nil {
+		logger.Error("URL is nil ,pls check if event %v is uncached successfully!", *event)
+		return nil
+	}
+	newUrl := common.MergeUrl(url, referenceUrl)
+	dir.overrideUrl(newUrl)
+	event.Update(newUrl)
 	return dir.uncacheInvokerWithKey(event.Key())
 }
 
@@ -335,6 +346,13 @@ func (dir *RegistryDirectory) uncacheInvokerWithKey(key string) protocol.Invoker
 		dir.cacheInvokersMap.Delete(key)
 		return cacheInvoker.(protocol.Invoker)
 	}
+	allExistKey := make([]string, 0)
+	dir.cacheInvokersMap.Range(func(key, value interface{}) bool {
+		allExistKey = append(allExistKey, key.(string))
+		return true
+	})
+	logger.Warnf("unexpected invoker key = %s, the exist keys are %s, which would result in invoking not exist provider, "+
+		"no exists provider, and the tcp conn timeout would occurs in the future", key, allExistKey)
 	return nil
 }
 
@@ -367,7 +385,7 @@ func (dir *RegistryDirectory) cacheInvoker(url *common.URL, event *registry.Serv
 func (dir *RegistryDirectory) doCacheInvoker(newUrl *common.URL, event *registry.ServiceEvent) (protocol.Invoker, bool) {
 	key := event.Key()
 	if cacheInvoker, ok := dir.cacheInvokersMap.Load(key); !ok {
-		logger.Debugf("service will be added in cache invokers: invokers url is  %s!", newUrl)
+		logger.Debugf("service will be added in cache invokers: invokers url is  %s!, cache map key is %s", newUrl, key)
 		newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(newUrl)
 		if newInvoker != nil {
 			dir.cacheInvokersMap.Store(key, newInvoker)