Skip to content

Commit

Permalink
Merge branch 'v1.5.x' into mergify/bp/v1.5.x/pr-2635
Browse files Browse the repository at this point in the history
  • Loading branch information
innobead authored Feb 23, 2024
2 parents 87634d4 + 54ea6c6 commit 7e25dc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
26 changes: 16 additions & 10 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3116,18 +3116,24 @@ func (c *VolumeController) checkAndFinishVolumeRestore(v *longhorn.Volume, e *lo
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 {
if err != nil && !apierrors.IsNotFound(err) {
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
if bv != 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
}
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions manager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/longhorn/longhorn-manager/datastore"
Expand Down Expand Up @@ -447,6 +448,12 @@ func (m *VolumeManager) triggerBackupVolumeToSync(volume *longhorn.Volume) error

backupVolume, err := m.ds.GetBackupVolume(backupVolumeName)
if err != nil {
// The backup volume may be deleted already.
// hence it's better not to block the caller to continue the handlings like DR volume activation.
if apierrors.IsNotFound(err) {
logrus.Infof("Cannot find backup volume %v to trigger the sync-up, will skip it", backupVolumeName)
return nil
}
return errors.Wrapf(err, "failed to get backup volume: %v", backupVolumeName)
}
requestSyncTime := metav1.Time{Time: time.Now().UTC()}
Expand Down

0 comments on commit 7e25dc1

Please sign in to comment.