Alanxtl commented on code in PR #3305:
URL: https://github.com/apache/dubbo-go/pull/3305#discussion_r3329998202


##########
cluster/router/tag/router.go:
##########
@@ -52,6 +55,19 @@ func (p *PriorityRouter) Route(invokers []base.Invoker, url 
*common.URL, invocat
                logger.Warn("[Router][Tag] invokers from previous router is 
empty")
                return invokers
        }
+
+       // Cache only takes effect when TagRouter is the first router in the 
chain.
+       // RouterChain sets RouterCacheDisable=true after each router, so later 
routers always skip cache.
+       if v := p.cache.Load(); v != nil {
+               if 
!invocation.GetAttributeWithDefaultValue(constant.RouterCacheDisable, 
false).(bool) {
+                       c := v.(router.Cache)
+                       pool, fullInvokers := c.FindAddrPool(p)
+                       if pool != nil && fullInvokers != nil {
+                               return p.routeWithPool(fullInvokers, pool, url, 
invocation)
+                       }
+               }
+       }

Review Comment:
   cache 快路径绕过了 `Route` 传入的 `invokers`,直接用 `FindAddrPool()` 返回的 `fullInvokers` 
做路由。`RouterChain.Route()` 在 `cluster/router/chain/chain.go:57-76` 先拷贝了一份当前 
invoker snapshot,但 cache 是在另一把锁里由 `SetInvokers()` 重建的;如果注册中心更新发生在 chain 
snapshot 和 TagRouter cache lookup 之间,本次调用可能返回另一个 cache snapshot 里的 
provider,绕过当前 `finalInvokers` 的 service filtering / 顺序语义。
   
   测试一下:cache 建在 `[a,b,c]` 上,但调用 `Route([a], tag=gray)` 返回了 `[a,b]`。
   
   建议只有在能证明 cache snapshot 和当前 `invokers` 是同一代数据时才走 bitmap 路径,否则 fallback 
到原逻辑;可以用 generation/token 由 RouterChain 传递,或在 cache 里统一提供本次 route 的 snapshot。



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

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