Skip to content

Commit

Permalink
Merge pull request #1157 from jack15083/3.0
Browse files Browse the repository at this point in the history
Fix:delete a service provider when using k8s hpa (3.0)
  • Loading branch information
AlexStocks committed Apr 17, 2021
2 parents ea7f4e7 + faf3bfb commit 0bd7945
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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
}

//GetCacheInvokerMapKey get directory cacheInvokerMap key
func (c *URL) GetCacheInvokerMapKey() string {
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.GetCacheInvokerMapKey()
}

// setNewInvokers groups the invokers from the cache first, then set the result to both directory and router chain.
Expand Down Expand Up @@ -317,7 +317,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.GetCacheInvokerMapKey())
}

func (dir *RegistryDirectory) uncacheInvokerWithKey(key string) protocol.Invoker {
Expand Down Expand Up @@ -356,7 +356,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.GetCacheInvokerMapKey()
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.GetCacheInvokerMapKey()
return e.key
}

Expand Down

0 comments on commit 0bd7945

Please sign in to comment.