From 2f23912ff47655cfaac9a0f33f5dec40bc2ef0a1 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Wed, 28 Aug 2024 11:57:01 +0800 Subject: [PATCH 1/2] revert: "feat(restore): create incremental restore snapshot" This reverts commit 2240d479e5685031e20578d562290357c7a8944a. longhorn/longhorn-9305 Signed-off-by: Chin-Ya Huang --- pkg/spdk/engine.go | 28 +++++++++++++--------------- pkg/spdk/replica.go | 42 ++++++++---------------------------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/pkg/spdk/engine.go b/pkg/spdk/engine.go index 761d66d2..13927c47 100644 --- a/pkg/spdk/engine.go +++ b/pkg/spdk/engine.go @@ -61,8 +61,7 @@ type Engine struct { Head *api.Lvol SnapshotMap map[string]*api.Lvol - IsRestoring bool - RestoringSnapshotName string + IsRestoring bool // UpdateCh should not be protected by the engine lock UpdateCh chan interface{} @@ -1748,18 +1747,17 @@ func (e *Engine) BackupRestore(spdkClient *spdkclient.Client, backupUrl, engineN e.IsRestoring = true - switch { - case snapshotName != "": - e.RestoringSnapshotName = snapshotName - e.log.Infof("Using input snapshot name %s for the restore", e.RestoringSnapshotName) - case len(e.SnapshotMap) == 0: - e.RestoringSnapshotName = util.UUID() - e.log.Infof("Using new generated snapshot name %s for the full restore", e.RestoringSnapshotName) - case e.RestoringSnapshotName != "": - e.log.Infof("Using existing snapshot name %s for the incremental restore", e.RestoringSnapshotName) - default: - e.RestoringSnapshotName = util.UUID() - e.log.Infof("Using new generated snapshot name %s for the incremental restore because e.FinalSnapshotName is empty", e.RestoringSnapshotName) + // TODO: support DR volume + if len(e.SnapshotMap) == 0 { + if snapshotName == "" { + snapshotName = util.UUID() + e.log.Infof("Generating a snapshot name %s for the full restore", snapshotName) + } + } else { + if snapshotName == "" { + snapshotName = util.UUID() + e.log.Infof("Generating a snapshot name %s for the incremental restore", snapshotName) + } } defer func() { @@ -1793,7 +1791,7 @@ func (e *Engine) BackupRestore(spdkClient *spdkclient.Client, backupUrl, engineN err = replicaServiceCli.ReplicaBackupRestore(&client.BackupRestoreRequest{ BackupUrl: backupUrl, ReplicaName: replicaName, - SnapshotName: e.RestoringSnapshotName, + SnapshotName: snapshotName, Credential: credential, ConcurrentLimit: concurrentLimit, }) diff --git a/pkg/spdk/replica.go b/pkg/spdk/replica.go index 72344b4e..6350fdbf 100644 --- a/pkg/spdk/replica.go +++ b/pkg/spdk/replica.go @@ -1926,11 +1926,11 @@ func (r *Replica) BackupRestore(spdkClient *spdkclient.Client, backupUrl, snapsh lvolName := GetReplicaSnapshotLvolName(r.Name, snapshotName) r.restore, err = NewRestore(spdkClient, lvolName, snapshotName, backupUrl, backupName, r) if err != nil { - err = errors.Wrap(err, "failed to start new restore") + err = errors.Wrapf(err, "failed to start new restore") return grpcstatus.Errorf(grpccodes.Internal, err.Error()) } } else { - r.log.Infof("Resetting the restore for backup %v", backupUrl) + r.log.Info("Resetting the restore for backup %v", backupUrl) var lvolName string var snapshotNameToBeRestored string @@ -1938,13 +1938,13 @@ func (r *Replica) BackupRestore(spdkClient *spdkclient.Client, backupUrl, snapsh validLastRestoredBackup := r.canDoIncrementalRestore(restore, backupUrl, backupName) if validLastRestoredBackup { r.log.Infof("Starting an incremental restore for backup %v", backupUrl) + lvolName = GetReplicaSnapshotLvolName(r.Name, restore.LastRestored) + snapshotNameToBeRestored = restore.LastRestored } else { r.log.Infof("Starting a full restore for backup %v", backupUrl) + lvolName = GetReplicaSnapshotLvolName(r.Name, snapshotName) + snapshotNameToBeRestored = snapshotName } - - lvolName = GetReplicaSnapshotLvolName(r.Name, snapshotName) - snapshotNameToBeRestored = snapshotName - r.restore.StartNewRestore(backupUrl, backupName, lvolName, snapshotNameToBeRestored, validLastRestoredBackup) } @@ -2052,7 +2052,7 @@ func (r *Replica) completeBackupRestore(spdkClient *spdkclient.Client, isFullRes return r.postFullRestoreOperations(spdkClient, restore) } - return r.postIncrementalRestoreOperations(spdkClient, restore) + return r.postIncrementalRestoreOperations(restore) } func (r *Replica) waitForRestoreComplete() error { @@ -2083,33 +2083,7 @@ func (r *Replica) waitForRestoreComplete() error { return nil } -func (r *Replica) postIncrementalRestoreOperations(spdkClient *spdkclient.Client, restore *Restore) error { - r.log.Infof("Replacing snapshot %v of the restored volume", restore.SnapshotName) - - if r.restore.State == btypes.ProgressStateCanceled { - r.log.Info("Doing nothing for canceled backup restoration") - return nil - } - - // Delete snapshot; SPDK will coalesce the content into the current head lvol. - r.log.Infof("Deleting snapshot %v for snapshot replacement of the restored volume", restore.SnapshotName) - _, err := r.SnapshotDelete(spdkClient, restore.SnapshotName) - if err != nil { - r.log.WithError(err).Error("Failed to delete snapshot of the restored volume") - return errors.Wrapf(err, "failed to delete snapshot of the restored volume") - } - - r.log.Infof("Creating snapshot %v for snapshot replacement of the restored volume", restore.SnapshotName) - opts := &api.SnapshotOptions{ - UserCreated: false, - Timestamp: util.Now(), - } - _, err = r.SnapshotCreate(spdkClient, restore.SnapshotName, opts) - if err != nil { - r.log.WithError(err).Error("Failed to take snapshot of the restored volume") - return errors.Wrapf(err, "failed to take snapshot of the restored volume") - } - +func (r *Replica) postIncrementalRestoreOperations(restore *Restore) error { r.log.Infof("Done running incremental restore %v to lvol %v", restore.BackupURL, restore.LvolName) return nil } From a03e93ed1b9f39ffe9f6239ab575469177b29985 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Wed, 28 Aug 2024 11:59:30 +0800 Subject: [PATCH 2/2] revert: vendor longhorn/longhorn-9305 Signed-off-by: Chin-Ya Huang --- go.mod | 2 ++ go.sum | 4 ++-- .../longhorn/backupstore/deltablock.go | 16 +++++----------- vendor/modules.txt | 3 ++- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 81784243..acf735ac 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.22.0 toolchain go1.22.6 +replace github.com/longhorn/backupstore => github.com/c3y1huang/backupstore v0.0.0-20240828035323-5cc2e815df20 + require ( github.com/0xPolygon/polygon-edge v1.3.3 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index eacb3544..aca8ed0c 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bits-and-blooms/bitset v1.12.0 h1:U/q1fAF7xXRhFCrhROzIfffYnu+dlS38vCZtmFVPHmA= github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/c3y1huang/backupstore v0.0.0-20240828035323-5cc2e815df20 h1:irQJHZFUP/xsF5PrYPLdB+n6eRiphX2++E1Vn2njG1A= +github.com/c3y1huang/backupstore v0.0.0-20240828035323-5cc2e815df20/go.mod h1:N4cqNhSs4VUw9aGbO2OfyiIvJL7/L53hUrNiT73UN+U= github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 h1:SjZ2GvvOononHOpK84APFuMvxqsk3tEIaKH/z4Rpu3g= github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -42,8 +44,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f h1:/Wo/leT2yrMmiDieCGhzqyzXb9FNsWoGeYWNfuf29KA= -github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f/go.mod h1:N4cqNhSs4VUw9aGbO2OfyiIvJL7/L53hUrNiT73UN+U= github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f h1:hjqUs3WVodkzrWwlUMVsnKAlom3uohoNlhZBGLsRvQY= github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f/go.mod h1:Qv34svr/msf6XoUwnrltNBTwMhQljbHEhb5ZKWiRdxo= github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff h1:8vR29tkbmzmdqRVtOo5kL7Rs7nfhA6duXsmetIh1Tbg= diff --git a/vendor/github.com/longhorn/backupstore/deltablock.go b/vendor/github.com/longhorn/backupstore/deltablock.go index edb237cd..f6b02c1e 100644 --- a/vendor/github.com/longhorn/backupstore/deltablock.go +++ b/vendor/github.com/longhorn/backupstore/deltablock.go @@ -941,16 +941,10 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest return err } go func() { - var err error - finalProgress := 0 - defer func() { if _err := deltaOps.CloseVolumeDev(volDev); _err != nil { logrus.WithError(_err).Warnf("Failed to close volume device %v", volDevName) } - - deltaOps.UpdateRestoreStatus(volDevName, finalProgress, err) - if unlockErr := lock.Unlock(); unlockErr != nil { logrus.WithError(unlockErr).Warn("Failed to unlock") } @@ -963,18 +957,18 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest // We want to truncate regular files, but not device if stat.Mode().IsRegular() { log.Infof("Truncate %v to size %v", volDevName, vol.Size) - err = volDev.Truncate(vol.Size) - if err != nil { + if err := volDev.Truncate(vol.Size); err != nil { + deltaOps.UpdateRestoreStatus(volDevName, 0, err) return } } - err = performIncrementalRestore(ctx, bsDriver, config, srcVolumeName, volDevPath, lastBackup, backup) - if err != nil { + if err := performIncrementalRestore(ctx, bsDriver, config, srcVolumeName, volDevPath, lastBackup, backup); err != nil { + deltaOps.UpdateRestoreStatus(volDevName, 0, err) return } - finalProgress = PROGRESS_PERCENTAGE_BACKUP_TOTAL + deltaOps.UpdateRestoreStatus(volDevName, PROGRESS_PERCENTAGE_BACKUP_TOTAL, nil) }() return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index edc45e89..fa834453 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -45,7 +45,7 @@ github.com/kr/pretty # github.com/kr/text v0.2.0 ## explicit github.com/kr/text -# github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f +# github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f => github.com/c3y1huang/backupstore v0.0.0-20240828035323-5cc2e815df20 ## explicit; go 1.22.0 github.com/longhorn/backupstore github.com/longhorn/backupstore/logging @@ -303,3 +303,4 @@ k8s.io/utils/internal/third_party/forked/golang/net k8s.io/utils/io k8s.io/utils/keymutex k8s.io/utils/net +# github.com/longhorn/backupstore => github.com/c3y1huang/backupstore v0.0.0-20240828035323-5cc2e815df20