From 369a811ae1d55a0abe589ceb3c3ee67ca1bfe345 Mon Sep 17 00:00:00 2001 From: wei liu Date: Fri, 25 Jul 2025 14:18:54 +0800 Subject: [PATCH] fix: only clear exclude node list after refresh shard leader cache (#43553) issue: #43511 Signed-off-by: Wei Liu --- internal/proxy/lb_policy.go | 2 +- internal/proxy/lb_policy_test.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/proxy/lb_policy.go b/internal/proxy/lb_policy.go index cfc64df282..ba726664f3 100644 --- a/internal/proxy/lb_policy.go +++ b/internal/proxy/lb_policy.go @@ -144,7 +144,7 @@ func (lb *LBPolicyImpl) selectNode(ctx context.Context, balancer LBBalancer, wor // if all available delegator has been excluded even after refresh shard leader cache // we should clear excludeNodes and try to select node again instead of failing the request at selectNode - if len(shardLeaders) > 0 && len(shardLeaders) <= excludeNodes.Len() { + if !withCache && len(shardLeaders) > 0 && len(shardLeaders) <= excludeNodes.Len() { allReplicaExcluded := true for _, node := range shardLeaders { if !excludeNodes.Contain(node.nodeID) { diff --git a/internal/proxy/lb_policy_test.go b/internal/proxy/lb_policy_test.go index 20b59a74fc..43cd698767 100644 --- a/internal/proxy/lb_policy_test.go +++ b/internal/proxy/lb_policy_test.go @@ -663,8 +663,6 @@ func (s *LBPolicySuite) TestSelectNodeWithExcludeClearing() { s.lbBalancer.ExpectedCalls = nil s.lbBalancer.EXPECT().RegisterNodeInfo(mock.Anything) // First attempt fails due to no candidates - s.lbBalancer.EXPECT().SelectNode(mock.Anything, mock.Anything, mock.Anything).Return(-1, merr.ErrNodeNotAvailable).Times(1) - // Second attempt succeeds after exclude nodes are cleared s.lbBalancer.EXPECT().SelectNode(mock.Anything, mock.Anything, mock.Anything).Return(1, nil).Times(1) // Setup mock to return only excluded nodes first, then same nodes for retry