Skip to content

Commit

Permalink
Simplify existing replica scheduling
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed Jul 28, 2023
1 parent 1d35e1d commit f48ec93
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions scheduler/replica_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (rcs *ReplicaScheduler) getDiskCandidates(nodeInfo map[string]*longhorn.Nod

nodeSoftAntiAffinity, err := rcs.ds.GetSettingAsBool(types.SettingNameReplicaSoftAntiAffinity)
if err != nil {
logrus.Errorf("error getting replica soft anti-affinity setting: %v", err)
logrus.Errorf("Error getting replica soft anti-affinity setting: %v", err)
}

if volume.Spec.ReplicaSoftAntiAffinity != longhorn.ReplicaSoftAntiAffinityDefault &&
Expand Down Expand Up @@ -213,8 +213,7 @@ func (rcs *ReplicaScheduler) getDiskCandidates(nodeInfo map[string]*longhorn.Nod
}

unusedNodes := map[string]*longhorn.Node{}
unusedNodesInNewZones := map[string]*longhorn.Node{}
nodesInUnusedZones := map[string]*longhorn.Node{}
unusedNodesInUnusedZones := map[string]*longhorn.Node{} // By definition, these nodes are also unused.
nodesWithEvictingReplicas := getNodesWithEvictingReplicas(replicas, nodeInfo)

for nodeName, node := range nodeInfo {
Expand All @@ -224,18 +223,18 @@ func (rcs *ReplicaScheduler) getDiskCandidates(nodeInfo map[string]*longhorn.Nod
}
if _, ok := usedNodes[nodeName]; !ok {
unusedNodes[nodeName] = node
if _, ok := usedZones[node.Status.Zone]; !ok {
unusedNodesInNewZones[nodeName] = node
}
}
if _, ok := usedZones[node.Status.Zone]; !ok {
nodesInUnusedZones[nodeName] = node
unusedNodesInUnusedZones[nodeName] = node
}
}

switch {
case !zoneSoftAntiAffinity && !nodeSoftAntiAffinity:
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInNewZones)
fallthrough
// Same as the above. If we cannot schedule two replicas in the same zone, we cannot schedule them on the same node.
case !zoneSoftAntiAffinity && nodeSoftAntiAffinity:
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInUnusedZones)
if len(diskCandidates) > 0 {
return diskCandidates, nil
}
Expand All @@ -246,7 +245,7 @@ func (rcs *ReplicaScheduler) getDiskCandidates(nodeInfo map[string]*longhorn.Nod
}
multiError.Append(errors)
case zoneSoftAntiAffinity && !nodeSoftAntiAffinity:
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInNewZones)
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInUnusedZones)
if len(diskCandidates) > 0 {
return diskCandidates, nil
}
Expand All @@ -261,24 +260,8 @@ func (rcs *ReplicaScheduler) getDiskCandidates(nodeInfo map[string]*longhorn.Nod
return diskCandidates, nil
}
multiError.Append(errors)
case !zoneSoftAntiAffinity && nodeSoftAntiAffinity:
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInNewZones)
if len(diskCandidates) > 0 {
return diskCandidates, nil
}
multiError.Append(errors)
diskCandidates, errors = getDiskCandidatesFromNodes(nodesInUnusedZones)
if len(diskCandidates) > 0 {
return diskCandidates, nil
}
multiError.Append(errors)
diskCandidates, errors = getDiskCandidatesFromNodes(nodesWithEvictingReplicas)
if len(diskCandidates) > 0 {
return diskCandidates, nil
}
multiError.Append(errors)
case zoneSoftAntiAffinity && nodeSoftAntiAffinity:
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInNewZones)
diskCandidates, errors := getDiskCandidatesFromNodes(unusedNodesInUnusedZones)
if len(diskCandidates) > 0 {
return diskCandidates, nil
}
Expand Down

0 comments on commit f48ec93

Please sign in to comment.