mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 09:08:43 +08:00
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:
parent
eb81e6ed01
commit
a308331b81
@ -559,7 +559,11 @@ func (b *MultiTargetBalancer) genSegmentPlan(ctx context.Context, replica *meta.
|
||||
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 {
|
||||
|
||||
@ -170,6 +170,10 @@ func (s *BalanceTestSuit) initCollection(collectionName string, replica int, cha
|
||||
}
|
||||
|
||||
func (s *BalanceTestSuit) TestBalanceOnSingleReplica() {
|
||||
testBalanceOnSingleReplica(s)
|
||||
}
|
||||
|
||||
func testBalanceOnSingleReplica(s *BalanceTestSuit) {
|
||||
name := "test_balance_" + funcutil.GenRandomStr()
|
||||
s.initCollection(name, 1, 2, 2, 2000, 500)
|
||||
|
||||
@ -414,6 +418,16 @@ func (s *BalanceTestSuit) TestConcurrentBalanceChannelAndSegment() {
|
||||
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) {
|
||||
suite.Run(t, new(BalanceTestSuit))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user