fix: Check latest leader exists before using it (#31500)

See also #31495

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-03-22 18:25:07 +08:00 committed by GitHub
parent f65a796d18
commit 4d2142d041
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -364,13 +364,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}
}