Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug cannot use the disk which has failed replica (backport #3499) #3500

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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
4 changes: 3 additions & 1 deletion scheduler/replica_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ func (s *TestSuite) TestFilterDisksWithMatchingReplicas(c *C) {
inputDiskUUIDs []string
inputReplicas map[string]*longhorn.Replica
diskSoftAntiAffinity bool
ignoreFailedReplicas bool

expectDiskUUIDs []string
}
Expand Down Expand Up @@ -1454,6 +1455,7 @@ func (s *TestSuite) TestFilterDisksWithMatchingReplicas(c *C) {
replica4.Name: replica4,
}
tc.diskSoftAntiAffinity = true
tc.ignoreFailedReplicas = false
tc.expectDiskUUIDs = []string{diskUUID5} // Only disk5 has no matching replica.
tests["only schedule to disk without matching replica"] = tc

Expand All @@ -1463,7 +1465,7 @@ func (s *TestSuite) TestFilterDisksWithMatchingReplicas(c *C) {
for _, UUID := range tc.inputDiskUUIDs {
inputDisks[UUID] = &Disk{}
}
outputDiskUUIDs := filterDisksWithMatchingReplicas(inputDisks, tc.inputReplicas, tc.diskSoftAntiAffinity)
outputDiskUUIDs := filterDisksWithMatchingReplicas(inputDisks, tc.inputReplicas, tc.diskSoftAntiAffinity, tc.ignoreFailedReplicas)
c.Assert(len(outputDiskUUIDs), Equals, len(tc.expectDiskUUIDs))
for _, UUID := range tc.expectDiskUUIDs {
_, ok := outputDiskUUIDs[UUID]
Expand Down
Loading