fix: [Cherry-pick] Check latest leader exists before using it (#31500) (#31546)

Cherry-pick from master
pr: #31500
See also #31495

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/31542/head^2
congqixia 2024-03-23 11:51:06 +08:00 committed by GitHub
parent 99774548f2
commit 5d3aa2a496
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -370,13 +370,13 @@ func (c *SegmentChecker) createSegmentLoadTasks(ctx context.Context, segments []
plans := make([]balance.SegmentAssignPlan, 0)
for shard, segments := range shardSegments {
// if channel is not subscribed yet, skip load segments
if len(c.dist.LeaderViewManager.GetLeadersByShard(shard)) == 0 {
leader := c.dist.LeaderViewManager.GetLatestLeadersByReplicaShard(replica, shard)
if leader == nil {
continue
}
// L0 segment can only be assign to shard leader's node
if isLevel0 {
leader := c.dist.LeaderViewManager.GetLatestLeadersByReplicaShard(replica, shard)
availableNodes = []int64{leader.ID}
}