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

controller: DR volume should wait for the latest backup restored before activation (backport #2611) #2615

Merged
merged 1 commit into from
Feb 20, 2024
Merged
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
25 changes: 24 additions & 1 deletion controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,9 @@ func (c *VolumeController) checkAndFinishVolumeRestore(v *longhorn.Volume, e *lo
// 3) The restore/DR volume is
// 3.1) it's state `Healthy`;
// 3.2) or it's state `Degraded` with all the scheduled replica included in the engine
if v.Spec.FromBackup == "" || !v.Status.IsStandby {
return nil
}
isPurging := false
for _, status := range e.Status.PurgeStatus {
if status.IsPurging {
Expand All @@ -3169,6 +3172,26 @@ func (c *VolumeController) checkAndFinishVolumeRestore(v *longhorn.Volume, e *lo
return nil
}

// Make sure the backup volume is up-to-date and the latest backup is restored
_, bvName, _, err := backupstore.DecodeBackupURL(v.Spec.FromBackup)
if err != nil {
return errors.Wrapf(err, "failed to get backup name from volume %s backup URL %v", v.Name, v.Spec.FromBackup)
}
bv, err := c.ds.GetBackupVolumeRO(bvName)
if err != nil {
return err
}
if !bv.Status.LastSyncedAt.IsZero() &&
bv.Spec.SyncRequestedAt.After(bv.Status.LastSyncedAt.Time) {
log.Infof("Restore/DR volume needs to wait for backup volume %s update", bvName)
return nil
}
if e.Status.LastRestoredBackup != bv.Status.LastBackupName {
log.Infof("Restore/DR volume needs to restore the latest backup %s, and the current restored backup is %s", bv.Status.LastBackupName, e.Status.LastRestoredBackup)
c.enqueueVolume(v)
return nil
}

allScheduledReplicasIncluded, err := c.checkAllScheduledReplicasIncluded(v, e, rs)
if err != nil {
return err
Expand All @@ -3180,7 +3203,7 @@ func (c *VolumeController) checkAndFinishVolumeRestore(v *longhorn.Volume, e *lo
}

if !isPurging && ((v.Status.Robustness == longhorn.VolumeRobustnessHealthy && allScheduledReplicasIncluded) || (v.Status.Robustness == longhorn.VolumeRobustnessDegraded && degradedVolumeSupported)) {
log.Info("Restore/DR volume finished")
log.Infof("Restore/DR volume finished with the last restored backup %s", e.Status.LastRestoredBackup)
v.Status.IsStandby = false
v.Status.RestoreRequired = false
}
Expand Down
Loading