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

revert: fix for fluctuating checksum #212

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
28 changes: 13 additions & 15 deletions pkg/spdk/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
})
Expand Down
42 changes: 8 additions & 34 deletions pkg/spdk/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -1926,25 +1926,25 @@ 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

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)
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 5 additions & 11 deletions vendor/github.com/longhorn/backupstore/deltablock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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