beiwei30 commented on a change in pull request #708:
URL: https://github.com/apache/dubbo-go/pull/708#discussion_r472700207
##########
File path: cluster/router/chain/chain.go
##########
@@ -109,14 +233,62 @@ func NewRouterChain(url *common.URL) (*RouterChain,
error) {
chain := &RouterChain{
builtinRouters: routers,
routers: newRouters,
+ last: time.Now(),
+ notify: make(chan struct{}),
}
if url != nil {
chain.url = *url
}
+ go chain.loop()
return chain, nil
}
+// poolRouter calls poolable router's Pool() to create new address pool and
address metadata if necessary.
+// If the corresponding cache entry exists, and the poolable router answers no
need to re-pool (possibly because its
+// rule doesn't change), and the address list doesn't change, then the
existing data will be re-used.
+func poolRouter(p router.Poolable, origin *InvokerCache, invokers
[]protocol.Invoker) (router.AddrPool, router.AddrMetadata) {
+ name := p.Name()
+ if isCacheMiss(origin, name) || p.ShouldPool() ||
isInvokersChanged(origin.invokers, invokers) {
+ logger.Debugf("build address cache for router %q", name)
+ return p.Pool(invokers)
+ }
+
+ logger.Debugf("reuse existing address cache for router %q", name)
+ return origin.pools[name], origin.metadatas[name]
+}
+
+// isCacheMiss checks if the corresponding cache entry for a poolable router
has already existed.
+// False returns when the cache is nil, or cache's pool is nil, or cache's
invokers snapshot is nil, or the entry
+// doesn't exist.
+func isCacheMiss(cache *InvokerCache, key string) bool {
+ if cache == nil || cache.pools == nil || cache.invokers == nil ||
cache.pools[key] == nil {
Review comment:
I believe it is unnecessary, since cache is fetched from atomic.Value.
----------------------------------------------------------------
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]