Skip to content

Commit

Permalink
fix: bug cannot use the disk which has failed replica
Browse files Browse the repository at this point in the history
We should not exclude the disk which has failed replica in 2 cases:
1. The caller is trying to reuse the failed replica, this disk is a
   valid candidate
2. The failed replica is still reusable, this disk is a valid candidate

longhorn-10210

Signed-off-by: Phan Le <[email protected]>
  • Loading branch information
PhanLe1010 committed Jan 19, 2025
1 parent 5fef491 commit f8289bd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scheduler/replica_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (rcs *ReplicaScheduler) getDiskCandidates(nodeInfo map[string]*longhorn.Nod
}
multiError.Append(errors)
}
diskCandidates = filterDisksWithMatchingReplicas(diskCandidates, replicas, diskSoftAntiAffinity)
diskCandidates = filterDisksWithMatchingReplicas(diskCandidates, replicas, diskSoftAntiAffinity, ignoreFailedReplicas)
return diskCandidates, multiError
}

Expand Down Expand Up @@ -467,9 +467,17 @@ func (rcs *ReplicaScheduler) filterNodeDisksForReplica(node *longhorn.Node, disk
// filterDiskWithMatchingReplicas returns disk that have no matching replicas when diskSoftAntiAffinity is false.
// Otherwise, it returns the input disks map.

Check notice on line 468 in scheduler/replica_scheduler.go

View check run for this annotation

codefactor.io / CodeFactor

scheduler/replica_scheduler.go#L368-L468

Complex Method
func filterDisksWithMatchingReplicas(disks map[string]*Disk, replicas map[string]*longhorn.Replica,
diskSoftAntiAffinity bool) map[string]*Disk {
diskSoftAntiAffinity, ignoreFailedReplicas bool) map[string]*Disk {
replicasCountPerDisk := map[string]int{}
for _, r := range replicas {
if r.Spec.FailedAt != "" {
if ignoreFailedReplicas {
continue
}
if !IsPotentiallyReusableReplica(r) {
continue // This replica can never be used again, so it does not count in scheduling decisions.
}
}
replicasCountPerDisk[r.Spec.DiskID]++
}

Expand Down

0 comments on commit f8289bd

Please sign in to comment.