diff --git a/go.mod b/go.mod index f68ff0184..953daa3a2 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,11 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 - github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e + github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58 github.com/longhorn/sparse-tools v0.0.0-20240729132735-18b207e459ff - github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 + github.com/longhorn/types v0.0.0-20240827042720-af8f10eb57cd github.com/moby/moby v26.1.5+incompatible github.com/pkg/errors v0.9.1 github.com/rancher/go-fibmap v0.0.0-20160418233256-5fc9f8c1ed47 diff --git a/go.sum b/go.sum index ef791dfb7..d4a9fb814 100644 --- a/go.sum +++ b/go.sum @@ -79,16 +79,16 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e h1:Kvt/BqiHKaOlTPSM2HFz0VupuQM0laln67rMIDCRYxQ= -github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e/go.mod h1:N4cqNhSs4VUw9aGbO2OfyiIvJL7/L53hUrNiT73UN+U= +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-iscsi-helper v0.0.0-20240811043302-df8de353dd58 h1:fzLAnCLCecoUnsSYyyo7li5GD17xckyBl/zietxz168= github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58/go.mod h1:TobRDCXmF0Ni+jz6+nLJamw3uVu+gNDZoZre1JczGwc= github.com/longhorn/sparse-tools v0.0.0-20240729132735-18b207e459ff h1:gmdQDbnaGJ/zmrK+QJzSys8mH679os6i7vW/pOpRn1U= github.com/longhorn/sparse-tools v0.0.0-20240729132735-18b207e459ff/go.mod h1:iUJCZtOKG/9xv2rfrUAYZntFTzP5dZtvy4Kwe6dMcUc= -github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 h1:L2g0sIJ2fXt4BSFRYNnF6ObtKryCUFm9qLcCXHWssCk= -github.com/longhorn/types v0.0.0-20240725040629-473d671316c4/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w= +github.com/longhorn/types v0.0.0-20240827042720-af8f10eb57cd h1:AwVxaFaxLPmyl++SyigaZZw8u+Ggun7HlcmNgNqyhjs= +github.com/longhorn/types v0.0.0-20240827042720-af8f10eb57cd/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= diff --git a/integration/requirements.txt b/integration/requirements.txt index 457932149..cff36aec1 100644 --- a/integration/requirements.txt +++ b/integration/requirements.txt @@ -1,7 +1,7 @@ cattle==0.5.4 directio==1.3 protobuf==4.25.4 -grpcio==1.66.0 +grpcio==1.66.1 flake8 pytest==8.3.2 diff --git a/vendor/github.com/longhorn/backupstore/deltablock.go b/vendor/github.com/longhorn/backupstore/deltablock.go index 16c5ad42c..edb237cd7 100644 --- a/vendor/github.com/longhorn/backupstore/deltablock.go +++ b/vendor/github.com/longhorn/backupstore/deltablock.go @@ -741,7 +741,9 @@ func RestoreDeltaBlockBackup(ctx context.Context, config *DeltaRestoreConfig) er } defer func() { if err != nil { - _ = deltaOps.CloseVolumeDev(volDev) + if _err := deltaOps.CloseVolumeDev(volDev); _err != nil { + logrus.WithError(_err).Warnf("Failed to close volume device %v", volDevName) + } } }() @@ -775,7 +777,10 @@ func RestoreDeltaBlockBackup(ctx context.Context, config *DeltaRestoreConfig) er currentProgress := 0 defer func() { - _ = deltaOps.CloseVolumeDev(volDev) + if _err := deltaOps.CloseVolumeDev(volDev); _err != nil { + logrus.WithError(_err).Warnf("Failed to close volume device %v", volDevName) + } + deltaOps.UpdateRestoreStatus(volDevName, currentProgress, err) if unlockErr := lock.Unlock(); unlockErr != nil { logrus.WithError(unlockErr).Warn("Failed to unlock") @@ -843,8 +848,9 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest lastBackupName := config.LastBackupName deltaOps := config.DeltaOps if deltaOps == nil { - return fmt.Errorf("missing DeltaBlockBackupOperations") + return fmt.Errorf("missing DeltaRestoreOperations") } + bsDriver, err := GetBackupStoreDriver(backupURL) if err != nil { return err @@ -894,14 +900,16 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest } } - volDev, err := os.Create(volDevName) + volDev, volDevPath, err := deltaOps.OpenVolumeDev(volDevName) if err != nil { - return err + return errors.Wrapf(err, "failed to open volume device %v", volDevName) } defer func() { // make sure to close the device if err != nil { - _ = volDev.Close() + if _err := deltaOps.CloseVolumeDev(volDev); _err != nil { + logrus.WithError(_err).Warnf("Failed to close volume device %v", volDevName) + } } }() @@ -933,10 +941,18 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest return err } go func() { - defer volDev.Close() + 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(err).Warn("Failed to unlock") + logrus.WithError(unlockErr).Warn("Failed to unlock") } }() @@ -945,20 +961,20 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest // closed. // https://github.com/longhorn/longhorn/issues/2503 // We want to truncate regular files, but not device - if stat.Mode()&os.ModeType == 0 { - log.Debugf("Truncate %v to size %v", volDevName, vol.Size) - if err := volDev.Truncate(vol.Size); err != nil { - deltaOps.UpdateRestoreStatus(volDevName, 0, err) + if stat.Mode().IsRegular() { + log.Infof("Truncate %v to size %v", volDevName, vol.Size) + err = volDev.Truncate(vol.Size) + if err != nil { return } } - if err := performIncrementalRestore(ctx, bsDriver, config, srcVolumeName, volDevName, lastBackup, backup); err != nil { - deltaOps.UpdateRestoreStatus(volDevName, 0, err) + err = performIncrementalRestore(ctx, bsDriver, config, srcVolumeName, volDevPath, lastBackup, backup) + if err != nil { return } - deltaOps.UpdateRestoreStatus(volDevName, PROGRESS_PERCENTAGE_BACKUP_TOTAL, nil) + finalProgress = PROGRESS_PERCENTAGE_BACKUP_TOTAL }() return nil } @@ -1107,7 +1123,7 @@ func restoreBlocks(ctx context.Context, bsDriver BackupStoreDriver, deltaOps Del } func performIncrementalRestore(ctx context.Context, bsDriver BackupStoreDriver, config *DeltaRestoreConfig, - srcVolumeName, volDevName string, lastBackup *Backup, backup *Backup) error { + srcVolumeName, volDevPath string, lastBackup *Backup, backup *Backup) error { var err error concurrentLimit := config.ConcurrentLimit @@ -1119,7 +1135,7 @@ func performIncrementalRestore(ctx context.Context, bsDriver BackupStoreDriver, errorChans := []<-chan error{errChan} for i := 0; i < int(concurrentLimit); i++ { - errorChans = append(errorChans, restoreBlocks(ctx, bsDriver, config.DeltaOps, config.Filename, srcVolumeName, blockChan, progress)) + errorChans = append(errorChans, restoreBlocks(ctx, bsDriver, config.DeltaOps, volDevPath, srcVolumeName, blockChan, progress)) } mergedErrChan := mergeErrorChannels(ctx, errorChans...) diff --git a/vendor/modules.txt b/vendor/modules.txt index 9c933772c..7b6f83ca9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -161,7 +161,7 @@ github.com/kr/pretty # github.com/kr/text v0.2.0 ## explicit github.com/kr/text -# github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e +# github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f ## explicit; go 1.22.0 github.com/longhorn/backupstore github.com/longhorn/backupstore/azblob @@ -205,7 +205,7 @@ github.com/longhorn/sparse-tools/sparse/rest github.com/longhorn/sparse-tools/stats github.com/longhorn/sparse-tools/types github.com/longhorn/sparse-tools/util -# github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 +# github.com/longhorn/types v0.0.0-20240827042720-af8f10eb57cd ## explicit; go 1.21 github.com/longhorn/types/pkg/generated/enginerpc github.com/longhorn/types/pkg/generated/profilerrpc