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/04/02 14:54:38 UTC

[GitHub] [dubbo-go] ztelur opened a new pull request #1130: fix reExporter bug when config-center {applicationName}.configurator data change

ztelur opened a new pull request #1130:
URL: https://github.com/apache/dubbo-go/pull/1130


   ### What this PR does:
   - 修改 protocol.go 文件中 getCacheKey 函数实现;
   - 删除各个协议下 exporter 的 Unexport 方法中common.ServiceMap.UnRegister操作,在service_config的 Unexport 方法中添加UnRegister操作。
   ### Fixes
   - 修复issue #894 配置中心下发配置无法实时生效
   - 修复多次配置更改,实时生效时,reExport 操作的Error [DubboExporter.Unexport] error: no services for dubbo 问题
   ### Special notes for your reviewer:
   旧的 getCacheKey 函数根据url中所有参数生成key,精度太高,url稍微有变化就生成不同的key,导致配置下发时根据providerUrl生成的key和Export存储时用的key不同,无法进行配置更新。
   ```
   // 初始化时
   func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
           .....
   	providerUrl := getProviderUrl(invoker) // 1 clone了一份url,所以修改不会影响原url
           .....
   	proto.providerConfigurationListener.OverrideUrl(providerUrl)
           .....
   	serviceConfigurationListener.OverrideUrl(providerUrl)
           // 2 上述两个OverrideUrl修改了providerUrl的值
           .....
   	key := getCacheKey(providerUrl)
   	cachedExporter, loaded := proto.bounds.Load(key)
          if loaded {
   		logger.Infof("The exporter has been cached, and will return cached exporter!")
   	} else {
                    // 3 将key和cachedExproter的映射关系存入bounds .....
   		proto.bounds.Store(key, cachedExporter)
   	}
           ....
   }
   
   // 配置变更时,该函数会进行处理
   func (nl *overrideSubscribeListener) doOverrideIfNecessary() {
   	providerUrl := getProviderUrl(nl.originInvoker)
   	key := getCacheKey(providerUrl)
           // 4 再次getProviderUrl获取的是旧的url,导致getCachedKey获得key和Export时的不同
   	if exporter, ok := nl.protocol.bounds.Load(key); ok {
              ....
           }
   }
   ```
   - 配置实时生效时会调用reExport方法,reExport会调用 protocol.Exporter 的 unexport 和 export 方法,该方法进行了ServiceMap.UnRegister操作,但是 export 时却没有进行 ServiceMap.Register 操作,导致再次配置实时生效时报错;
   - protocol.Exporter.unexport 目前只会在reExport和 destroy 场景时调用,并不需要影响到上层的 ServiceMap,应该让上层自己处理ServiceMap;
   - ServiceMap.Register 操作只会在 service_config.go 中进行,所以考虑到整体项目的层次性,将 ServiceMap.UnRegister 放在service_config.Unexport 方法中,protocol.Exporter.unexport 时就不进行UnRegister操作了。
   ```
   func (proto *registryProtocol) reExport(invoker protocol.Invoker, newUrl *common.URL) {
   	url := getProviderUrl(invoker)
   	key := getCacheKey(url)
   	if oldExporter, loaded := proto.bounds.Load(key); loaded {
   		wrappedNewInvoker := newWrappedInvoker(invoker, newUrl)
                    // unexport
   		oldExporter.(protocol.Exporter).Unexport()
   		proto.bounds.Delete(key)
                   // export
   		proto.Export(wrappedNewInvoker)
   		// TODO:  unregister & unsubscribe
   	}
   }
   func (de *DubboExporter) Unexport() {
   	interfaceName := de.GetInvoker().GetUrl().GetParam(constant.INTERFACE_KEY, "")
   	de.BaseExporter.Unexport()
   
   	err := common.ServiceMap.UnRegister(interfaceName, DUBBO, de.GetInvoker().GetUrl().ServiceKey())
   	if err != nil {
   		logger.Errorf("[DubboExporter.Unexport] error: %v", err)
   	}
   }
   ```


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


[GitHub] [dubbo-go] ztelur closed pull request #1130: fix reExporter bug when config-center {applicationName}.configurator data change

Posted by GitBox <gi...@apache.org>.
ztelur closed pull request #1130:
URL: https://github.com/apache/dubbo-go/pull/1130


   


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


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #1130: fix reExporter bug when config-center {applicationName}.configurator data change

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #1130:
URL: https://github.com/apache/dubbo-go/pull/1130#discussion_r606751202



##########
File path: config/service_config.go
##########
@@ -249,17 +249,27 @@ func (c *ServiceConfig) Unexport() {
 		return
 	}
 
+	if !c.exported.CAS(true, false) {
+		return
+	}
+	if !c.unexported.CAS(false, true) {
+		return

Review comment:
       他整体逻辑需要参照 dubbo 重构下,等重新写完再看下。




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


[GitHub] [dubbo-go] zouyx commented on a change in pull request #1130: fix reExporter bug when config-center {applicationName}.configurator data change

Posted by GitBox <gi...@apache.org>.
zouyx commented on a change in pull request #1130:
URL: https://github.com/apache/dubbo-go/pull/1130#discussion_r606737666



##########
File path: config/service_config.go
##########
@@ -249,17 +249,27 @@ func (c *ServiceConfig) Unexport() {
 		return
 	}
 
+	if !c.exported.CAS(true, false) {
+		return
+	}
+	if !c.unexported.CAS(false, true) {
+		return

Review comment:
       Previous logic is always success, but now not.
   If return without a flag, how can i know it is unexport successfully?




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