ztelur commented on code in PR #389: URL: https://github.com/apache/dubbo-go-pixiu/pull/389#discussion_r849258023
########## pkg/adapter/dubboregistry/registry/nacos/service_listener.go: ########## @@ -58,11 +64,76 @@ func newNacosSrvListener(url *dubboCommon.URL, client naming_client.INamingClien client: client, exit: make(chan struct{}), adapterListener: adapterListener, + instanceMap: map[string]nacosModel.Instance{}, } } -func (z *serviceListener) Notify(e *dubboRegistry.ServiceEvent) { - bkConfig, methods, location, err := registry.ParseDubboString(e.Service.String()) +func (z *serviceListener) Callback(services []nacosModel.SubscribeService, err error) { + if err != nil { + logger.Errorf("nacos subscribe callback error:%s", err.Error()) + return + } + + addInstances := make([]nacosModel.Instance, 0, len(services)) + delInstances := make([]nacosModel.Instance, 0, len(services)) + updateInstances := make([]nacosModel.Instance, 0, len(services)) + newInstanceMap := make(map[string]nacosModel.Instance, len(services)) + + z.cacheLock.Lock() Review Comment: - service_listener的 Callback 函数只会处理某个service的instance变更回调,并发理论上不会很高(依赖 nacos_client subscribe 回调的实现机制,可能也不存在并发,都是逐次回调); - 下面的逻辑是根据内存缓存中的 instance 元信息和回调的最新元信息一起计算,得出新增或删除的 instance,然后覆盖内存缓存的 instance 元信息,应该加锁,不然理论上可能会出现两次回调同时进行,导致更新覆盖的问题。 -- 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-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org