From 54ea6c6578dfa6237041544e8ff250f06adf0736 Mon Sep 17 00:00:00 2001 From: Shuo Wu Date: Thu, 22 Feb 2024 16:06:12 +0800 Subject: [PATCH] controller: Allow DR volume activation if the latest backup is empty Longhorn 7997 Signed-off-by: Shuo Wu --- controller/volume_controller.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/controller/volume_controller.go b/controller/volume_controller.go index b128f6332a..67953f1c93 100644 --- a/controller/volume_controller.go +++ b/controller/volume_controller.go @@ -3120,15 +3120,19 @@ func (c *VolumeController) checkAndFinishVolumeRestore(v *longhorn.Volume, e *lo return err } if bv != nil { - 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 bv.Status.LastBackupName != e.Status.LastRestoredBackup { - 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 + if bv.Status.LastBackupName != "" { + // If the backup CR does not exist, the Longhorn system may be still syncing up the info with the remote backup target. + // If the backup is removed already, the backup volume should receive the notification and update bv.Status.LastBackupName. + // Hence we cannot continue the activation when the backup get call returns error IsNotFound. + b, err := c.ds.GetBackup(bv.Status.LastBackupName) + if err != nil { + return err + } + if b.Name != e.Status.LastRestoredBackup { + log.Infof("Restore/DR volume needs to restore the latest backup %s, and the current restored backup is %s", b.Name, e.Status.LastRestoredBackup) + c.enqueueVolume(v) + return nil + } } } }