Skip to content

Commit

Permalink
offline rebuilding: check spc.backendStoreDriver using a defensive way
Browse files Browse the repository at this point in the history
Longhorn 6688

Signed-off-by: Derek Su <derek.su@suse.com>
(cherry picked from commit 7544169)
  • Loading branch information
derekbit authored and David Ko committed Sep 19, 2023
1 parent f86e6dc commit fdd7e20
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,13 @@ func (c *VolumeController) ReconcileEngineReplicaState(v *longhorn.Volume, es ma
}
}

if v.Spec.BackendStoreDriver == longhorn.BackendStoreDriverTypeV2 {
shouldStop, err := c.shouldStopOfflineReplicaRebuilding(v, healthyCount)
if err != nil {
log.WithError(err).Errorf("Failed to check if offline replica rebuilding should be stopped")
return err
}
if shouldStop {
v.Status.OfflineReplicaRebuildingRequired = false
}
shouldStop, err := c.shouldStopOfflineReplicaRebuilding(v, healthyCount)
if err != nil {
log.WithError(err).Errorf("Failed to check if offline replica rebuilding should be stopped")
return err
}
if shouldStop {
v.Status.OfflineReplicaRebuildingRequired = false
}

// Cannot continue evicting or replenishing replicas during engine migration.
Expand Down Expand Up @@ -731,9 +729,7 @@ func (c *VolumeController) ReconcileEngineReplicaState(v *longhorn.Volume, es ma
}
}

if v.Spec.BackendStoreDriver == longhorn.BackendStoreDriverTypeV2 {
v.Status.OfflineReplicaRebuildingRequired = false
}
v.Status.OfflineReplicaRebuildingRequired = false
} else { // healthyCount < v.Spec.NumberOfReplicas
v.Status.Robustness = longhorn.VolumeRobustnessDegraded
if oldRobustness != longhorn.VolumeRobustnessDegraded {
Expand Down Expand Up @@ -797,6 +793,10 @@ func areAllReplicasFailed(rs map[string]*longhorn.Replica) bool {
}

func (c *VolumeController) shouldStopOfflineReplicaRebuilding(v *longhorn.Volume, healthyCount int) (bool, error) {
if v.Spec.BackendStoreDriver != longhorn.BackendStoreDriverTypeV2 {
return true, nil
}

if healthyCount == v.Spec.NumberOfReplicas {
return true, nil
}
Expand Down Expand Up @@ -2854,7 +2854,7 @@ func (c *VolumeController) updateRequestedBackupForVolumeRestore(v *longhorn.Vol
func (c *VolumeController) checkAndInitVolumeOfflineReplicaRebuilding(v *longhorn.Volume, rs map[string]*longhorn.Replica) error {
log := getLoggerForVolume(c.logger, v)

if v.Spec.BackendStoreDriver == longhorn.BackendStoreDriverTypeV1 {
if v.Spec.BackendStoreDriver != longhorn.BackendStoreDriverTypeV2 {
return nil
}

Expand Down

0 comments on commit fdd7e20

Please sign in to comment.