zhaoyunxing92 opened a new issue #1141:
URL: https://github.com/apache/dubbo-go/issues/1141


   k8s服务如果使用的是node的ip在滚动升级的时候触发下线事件就会把刚刚注册的服务下线掉,导致客户端找不到服务,代码流程如下
   > registry/directory/directory.go:124
   ```go
   // refreshInvokers refreshes service's events.
   func (dir *RegistryDirectory) refreshInvokers(event *registry.ServiceEvent) {
         ....
        if event != nil {
                   // 根据事件缓存Invoker
                oldInvoker, _ = dir.cacheInvokerByEvent(event)
        }
        ....
   }
   ```
   
   > registry/directory/directory.go:240
   ```go
   // cacheInvokerByEvent caches invokers from the service event
   func (dir *RegistryDirectory) cacheInvokerByEvent(event 
*registry.ServiceEvent) (protocol.Invoker, error) {
        // judge is override or others
        if event != nil {
                u := dir.convertUrl(event)
                switch event.Action {
                case remoting.EventTypeAdd, remoting.EventTypeUpdate:
                        logger.Infof("selector add service url{%s}", 
event.Service)
                        if u != nil && constant.ROUTER_PROTOCOL == u.Protocol {
                                dir.configRouters()
                        }
                        return dir.cacheInvoker(u), nil
                case remoting.EventTypeDel:
                        logger.Infof("selector delete service url{%s}", 
event.Service)
                          // 如果是删除类型事件
                        return dir.uncacheInvoker(u), nil
                default:
                        return nil, fmt.Errorf("illegal event type: %v", 
event.Action)
                }
        }
        return nil, nil
   }
   ```
   > registry/directory/directory.go:327
   
   ``` go
   // uncacheInvoker will return abandoned Invoker, if no Invoker to be 
abandoned, return nil
   func (dir *RegistryDirectory) uncacheInvoker(url *common.URL) 
protocol.Invoker {
        return dir.uncacheInvokerWithKey(url.Key())
   }
   ```
   > common/url.go:341
   ``` go
   // Key gets key
   func (c *URL) Key() string {
        buildString := 
fmt.Sprintf("%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s",
                c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), 
c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, ""))
        return buildString
   }
   ```
   关键代码就是`Key()`方法,因为`ip`、`port`等等有一样
   


-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to