fix: Set replica field in balance plans to prevent panic (#45722)

issue: #45598

The MultiTargetBalancer was missing replica field assignment in the
generated segment and channel plans, which caused panic during balance
operations. This change ensures that all balance plans have the replica
field properly set to fix the panic issue.

Also refactored the balance test to extract common test logic into a
reusable helper function and added a new integration test specifically
for MultipleTargetBalancer policy.

Signed-off-by: Wei Liu <wei.liu@zilliz.com>
This commit is contained in:
wei liu 2025-12-04 10:19:11 +08:00 committed by GitHub
parent eb81e6ed01
commit a308331b81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -559,7 +559,11 @@ func (b *MultiTargetBalancer) genSegmentPlan(ctx context.Context, replica *meta.
globalNodeSegments[node] = b.dist.SegmentDistManager.GetByFilter(meta.WithNodeID(node)) globalNodeSegments[node] = b.dist.SegmentDistManager.GetByFilter(meta.WithNodeID(node))
} }
return b.genPlanByDistributions(nodeSegments, globalNodeSegments) plans := b.genPlanByDistributions(nodeSegments, globalNodeSegments)
for i := range plans {
plans[i].Replica = replica
}
return plans
} }
func (b *MultiTargetBalancer) genPlanByDistributions(nodeSegments, globalNodeSegments map[int64][]*meta.Segment) []SegmentAssignPlan { func (b *MultiTargetBalancer) genPlanByDistributions(nodeSegments, globalNodeSegments map[int64][]*meta.Segment) []SegmentAssignPlan {

View File

@ -170,6 +170,10 @@ func (s *BalanceTestSuit) initCollection(collectionName string, replica int, cha
} }
func (s *BalanceTestSuit) TestBalanceOnSingleReplica() { func (s *BalanceTestSuit) TestBalanceOnSingleReplica() {
testBalanceOnSingleReplica(s)
}
func testBalanceOnSingleReplica(s *BalanceTestSuit) {
name := "test_balance_" + funcutil.GenRandomStr() name := "test_balance_" + funcutil.GenRandomStr()
s.initCollection(name, 1, 2, 2, 2000, 500) s.initCollection(name, 1, 2, 2, 2000, 500)
@ -414,6 +418,16 @@ func (s *BalanceTestSuit) TestConcurrentBalanceChannelAndSegment() {
s.Equal(int64(0), failCounter.Load()) s.Equal(int64(0), failCounter.Load())
} }
func (s *BalanceTestSuit) TestMultiTargetBalancePolicy() {
// Set balance policy to MultipleTargetBalancer
revertGuard := s.Cluster.MustModifyMilvusConfig(map[string]string{
paramtable.Get().QueryCoordCfg.Balancer.Key: "MultipleTargetBalancer",
})
defer revertGuard()
testBalanceOnSingleReplica(s)
}
func TestBalance(t *testing.T) { func TestBalance(t *testing.T) {
suite.Run(t, new(BalanceTestSuit)) suite.Run(t, new(BalanceTestSuit))
} }