Skip to content

Commit e72e927

Browse files
derekbitmergify[bot]
authored andcommitted
feat(scheduler): record reason for scheduling failure in the volume's Scheduled condition
To reduce flooding log messages caused by scheduling failures, record reason for the failure in the volume's Scheduled condition. Longhorn 3708 Signed-off-by: Derek Su <derek.su@suse.com>
1 parent 3cb638a commit e72e927

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

controller/volume_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,12 +1762,12 @@ func (c *VolumeController) reconcileVolumeCondition(v *longhorn.Volume, e *longh
17621762

17631763
if scheduledReplica == nil {
17641764
if r.Spec.HardNodeAffinity == "" {
1765-
log.WithField("replica", r.Name).Warn("Failed to schedule replica")
1765+
log.WithField("replica", r.Name).Debug("Failed to schedule replica")
17661766
v.Status.Conditions = types.SetCondition(v.Status.Conditions,
17671767
longhorn.VolumeConditionTypeScheduled, longhorn.ConditionStatusFalse,
17681768
longhorn.VolumeConditionReasonReplicaSchedulingFailure, "")
17691769
} else {
1770-
log.WithField("replica", r.Name).Warnf("Failed to schedule replica of volume with HardNodeAffinity = %v", r.Spec.HardNodeAffinity)
1770+
log.WithField("replica", r.Name).Debugf("Failed to schedule replica of volume with HardNodeAffinity = %v", r.Spec.HardNodeAffinity)
17711771
v.Status.Conditions = types.SetCondition(v.Status.Conditions,
17721772
longhorn.VolumeConditionTypeScheduled, longhorn.ConditionStatusFalse,
17731773
longhorn.VolumeConditionReasonLocalReplicaSchedulingFailure, "")

scheduler/replica_scheduler.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ func NewReplicaScheduler(ds *datastore.DataStore) *ReplicaScheduler {
5555
func (rcs *ReplicaScheduler) ScheduleReplica(replica *longhorn.Replica, replicas map[string]*longhorn.Replica, volume *longhorn.Volume) (*longhorn.Replica, util.MultiError, error) {
5656
// only called when replica is starting for the first time
5757
if replica.Spec.NodeID != "" {
58-
return nil, nil, fmt.Errorf("BUG: Replica %v has been scheduled to node %v", replica.Name, replica.Spec.NodeID)
58+
return nil, nil, fmt.Errorf("replica %v has been scheduled to node %v", replica.Name, replica.Spec.NodeID)
5959
}
6060

6161
// not to schedule a replica failed and unused before.
6262
if replica.Spec.HealthyAt == "" && replica.Spec.FailedAt != "" {
63-
logrus.WithField("replica", replica.Name).Warn("Failed replica is not scheduled")
64-
return nil, nil, nil
63+
return nil, util.NewMultiError(fmt.Sprintf("failed replica %v is not scheduled", replica.Name)), nil
6564
}
6665

6766
diskCandidates, multiError, err := rcs.FindDiskCandidates(replica, replicas, volume)
@@ -71,7 +70,11 @@ func (rcs *ReplicaScheduler) ScheduleReplica(replica *longhorn.Replica, replicas
7170

7271
// there's no disk that fit for current replica
7372
if len(diskCandidates) == 0 {
74-
logrus.Errorf("There's no available disk for replica %v, size %v", replica.Name, replica.Spec.VolumeSize)
73+
if len(multiError) == 0 {
74+
return nil, util.NewMultiError(fmt.Sprintf("no disk candidates found for replica %v with size %v and with hardNodeAffinity %q",
75+
replica.Name, replica.Spec.VolumeSize, replica.Spec.HardNodeAffinity)), nil
76+
}
77+
7578
return nil, multiError, nil
7679
}
7780

@@ -133,7 +136,9 @@ func (rcs *ReplicaScheduler) FindDiskCandidates(replica *longhorn.Replica, repli
133136

134137
nodeCandidates, multiError := rcs.getNodeCandidates(nodesInfo, replica)
135138
if len(nodeCandidates) == 0 {
136-
logrus.Errorf("There's no available node for replica %v, size %v", replica.Name, replica.Spec.VolumeSize)
139+
if len(multiError) == 0 {
140+
return nil, util.NewMultiError(fmt.Errorf("no node candidates found for replica %v with size %v", replica.Name, replica.Spec.VolumeSize).Error()), nil
141+
}
137142
return nil, multiError, nil
138143
}
139144

0 commit comments

Comments
 (0)