Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: delete a service provider when using k8s hpa #1154

Merged
merged 9 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ func (c *URL) Key() string {
return buildString
}

//CacheInvokerMapKey get dir cacheInvokerMap key
func (c *URL) CacheInvokerMapKey() string {
jack15083 marked this conversation as resolved.
Show resolved Hide resolved
urlNew, _ := NewURL(c.PrimitiveURL)

buildString := fmt.Sprintf("%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s&timestamp=%s",
c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""),
c.GetParam(constant.VERSION_KEY, ""), urlNew.GetParam(constant.TIMESTAMP_KEY, ""))
return buildString
}

// ServiceKey gets a unique key of a service.
func (c *URL) ServiceKey() string {
return ServiceKey(c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/")),
Expand Down
6 changes: 3 additions & 3 deletions registry/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (dir *RegistryDirectory) invokerCacheKey(event *registry.ServiceEvent) stri
referenceUrl := dir.GetDirectoryUrl().SubURL
newUrl := common.MergeUrl(event.Service, referenceUrl)
event.Update(newUrl)
return newUrl.Key()
return newUrl.CacheInvokerMapKey()
}

// setNewInvokers groups the invokers from the cache first, then set the result to both directory and router chain.
Expand Down Expand Up @@ -325,7 +325,7 @@ func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {

// 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())
return dir.uncacheInvokerWithKey(url.CacheInvokerMapKey())
}

func (dir *RegistryDirectory) uncacheInvokerWithKey(key string) protocol.Invoker {
Expand Down Expand Up @@ -364,7 +364,7 @@ func (dir *RegistryDirectory) cacheInvoker(url *common.URL) protocol.Invoker {
}

func (dir *RegistryDirectory) doCacheInvoker(newUrl *common.URL) (protocol.Invoker, bool) {
key := newUrl.Key()
key := newUrl.CacheInvokerMapKey()
if cacheInvoker, ok := dir.cacheInvokersMap.Load(key); !ok {
logger.Debugf("service will be added in cache invokers: invokers url is %s!", newUrl)
newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(newUrl)
Expand Down
2 changes: 1 addition & 1 deletion registry/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (e *ServiceEvent) Key() string {
if len(e.key) > 0 {
return e.key
}
e.key = e.Service.Key()
e.key = e.Service.CacheInvokerMapKey()
return e.key
}

Expand Down
3 changes: 0 additions & 3 deletions remoting/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li
if l.listenServiceNodeEvent(node, listener) {
logger.Warnf("delete zkNode{%s}", node)
listener.DataChange(remoting.Event{Path: node, Action: remoting.EventTypeDel})
l.pathMapLock.Lock()
delete(l.pathMap, zkPath)
l.pathMapLock.Unlock()
}
logger.Warnf("handleZkNodeEvent->listenSelf(zk path{%s}) goroutine exit now", node)
}(newNode, listener)
Expand Down