Skip to content

Commit

Permalink
fix: fix panic when generating plans (milvus-io#35309)
Browse files Browse the repository at this point in the history
issue: milvus-io#35335

Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby authored Aug 7, 2024
1 parent 72a1754 commit ae1b81a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/querycoordv2/balance/multi_target_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ func (g *rowCountBasedPlanGenerator) generatePlans() []SegmentAssignPlan {
})
}
maxNode, minNode := nodesWithRowCount[len(nodesWithRowCount)-1], nodesWithRowCount[0]
if len(maxNode.segments) == 0 {
break
}
segment := maxNode.segments[rand.Intn(len(maxNode.segments))]
plan := SegmentAssignPlan{
Segment: segment,
Expand Down Expand Up @@ -346,6 +349,9 @@ func (g *segmentCountBasedPlanGenerator) generatePlans() []SegmentAssignPlan {
})
}
maxNode, minNode := nodesWithSegmentCount[len(nodesWithSegmentCount)-1], nodesWithSegmentCount[0]
if len(maxNode.segments) == 0 {
break
}
segment := maxNode.segments[rand.Intn(len(maxNode.segments))]
plan := SegmentAssignPlan{
Segment: segment,
Expand Down Expand Up @@ -399,6 +405,9 @@ func newRandomPlanGenerator(maxSteps int) *randomPlanGenerator {
func (g *randomPlanGenerator) generatePlans() []SegmentAssignPlan {
g.currClusterCost = g.calClusterCost(g.replicaNodeSegments, g.globalNodeSegments)
nodes := lo.Keys(g.replicaNodeSegments)
if len(nodes) == 0 {
return g.plans
}
for i := 0; i < g.maxSteps; i++ {
// random select two nodes and two segments
node1 := nodes[rand.Intn(len(nodes))]
Expand All @@ -408,6 +417,9 @@ func (g *randomPlanGenerator) generatePlans() []SegmentAssignPlan {
}
segments1 := g.replicaNodeSegments[node1]
segments2 := g.replicaNodeSegments[node2]
if len(segments1) == 0 || len(segments2) == 0 {
continue
}
segment1 := segments1[rand.Intn(len(segments1))]
segment2 := segments2[rand.Intn(len(segments2))]

Expand Down

0 comments on commit ae1b81a

Please sign in to comment.