AlexStocks commented on code in PR #973:
URL: https://github.com/apache/dubbo-go-pixiu/pull/973#discussion_r3379751742
##########
pkg/cluster/loadbalancer/load_balancer.go:
##########
@@ -173,10 +176,15 @@ func pickEndpoint(balancer LoadBalancer, context
PickContext, policy model.LbPol
}
config := *context.Config
config.Endpoints = model.CloneEndpoints(allEndpoints)
- cursorBefore := atomic.LoadUint32(&context.Config.PrePickEndpointIndex)
+ var cursorBefore, cursorAfter uint32
+ if context.RoundRobinCursor != nil {
+ cursorBefore = context.RoundRobinCursor.Load()
+ } else {
+ cursorBefore =
atomic.LoadUint32(&context.Config.PrePickEndpointIndex)
+ }
atomic.StoreUint32(&config.PrePickEndpointIndex, cursorBefore)
endpoint := balancer.Handler(&config, policy)
- cursorAfter := atomic.LoadUint32(&config.PrePickEndpointIndex)
+ cursorAfter = atomic.LoadUint32(&config.PrePickEndpointIndex)
if cursorAfter != cursorBefore {
atomic.AddUint32(&context.Config.PrePickEndpointIndex,
cursorAfter-cursorBefore)
Review Comment:
[P1] 当 `PickContext.RoundRobinCursor` 非 nil 时,legacy balancer 的 cursor delta
仍然回写到 `context.Config.PrePickEndpointIndex`,运行时的 `RoundRobinCursor` 没有前进。这个 PR
把正常请求路径的游标迁到了 `Cluster.runtimeState`,`ClusterManager` 也会传入
`RoundRobinCursor`;因此仍走旧 `Handler(*ClusterConfig, Policy)` 的自定义负载均衡器如果依赖
`PrePickEndpointIndex`,下一次 pick 仍会从旧 runtime cursor 开始,轮询状态丢失。这里应在
`RoundRobinCursor` 非 nil 时把 delta 写回 `context.RoundRobinCursor`,只有 nil 时才回写
`Config.PrePickEndpointIndex`。
--
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]