Skip to content

Commit

Permalink
Store error in restic stats for parallel backup and dump (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: hmsayem <hmsayem@appscode.com>
  • Loading branch information
hmsayem committed May 29, 2023
1 parent ba0e434 commit 1e979c4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apis/stash/v1beta1/backup_session_types.go
Expand Up @@ -151,7 +151,7 @@ type HostBackupStats struct {
// Snapshots specifies the stats of individual snapshots that has been taken for this host in current backup session
// +optional
Snapshots []SnapshotStats `json:"snapshots,omitempty"`
// Duration indicates total time taken to complete backup for this hosts
// Duration indicates total time taken to complete backup for this host
// +optional
Duration string `json:"duration,omitempty"`
// Error indicates string value of error in case of backup failure
Expand Down
2 changes: 1 addition & 1 deletion apis/stash/v1beta1/openapi_generated.go

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

2 changes: 1 addition & 1 deletion crds/stash.appscode.com_backupsessions.yaml
Expand Up @@ -252,7 +252,7 @@ spec:
properties:
duration:
description: Duration indicates total time taken to complete
backup for this hosts
backup for this host
type: string
error:
description: Error indicates string value of error in
Expand Down
2 changes: 1 addition & 1 deletion openapi/swagger.json
Expand Up @@ -10247,7 +10247,7 @@
"type": "object",
"properties": {
"duration": {
"description": "Duration indicates total time taken to complete backup for this hosts",
"description": "Duration indicates total time taken to complete backup for this host",
"type": "string"
},
"error": {
Expand Down
17 changes: 7 additions & 10 deletions pkg/restic/backup.go
Expand Up @@ -90,20 +90,20 @@ func (w *ResticWrapper) RunParallelBackup(backupOptions []BackupOptions, targetR
}()

// sh field in ResticWrapper is a pointer. we must not use same w in multiple go routine.
// otherwise they might enter in a racing condition.
// otherwise they might enter in racing condition.
nw := w.Copy()

hostStats, err := nw.runBackup(opt)
hostStats.Duration = time.Since(startTime).String()
if err != nil {
// acquire lock to make sure no other go routine is writing to backupErr
hostStats.Phase = api_v1beta1.HostBackupFailed
hostStats.Error = err.Error()
mu.Lock()
backupErrs = append(backupErrs, err)
mu.Unlock()
return
} else {
hostStats.Phase = api_v1beta1.HostBackupSucceeded
}
hostStats.Duration = time.Since(startTime).String()
hostStats.Phase = api_v1beta1.HostBackupSucceeded

// add hostStats to backupOutput. use lock to avoid racing condition.
mu.Lock()
backupOutput.upsertHostBackupStats(hostStats)
Expand All @@ -114,10 +114,7 @@ func (w *ResticWrapper) RunParallelBackup(backupOptions []BackupOptions, targetR
// wait for all the go routines to complete
wg.Wait()

if backupErrs != nil {
return nil, errors.NewAggregate(backupErrs)
}
return backupOutput, nil
return backupOutput, errors.NewAggregate(backupErrs)
}

func (w *ResticWrapper) runBackup(backupOption BackupOptions) (api_v1beta1.HostBackupStats, error) {
Expand Down
18 changes: 9 additions & 9 deletions pkg/restic/restore.go
Expand Up @@ -195,27 +195,27 @@ func (w *ResticWrapper) ParallelDump(dumpOptions []DumpOptions, targetRef api_v1
opt.SourceHost = opt.Host
}

hostStats := api_v1beta1.HostRestoreStats{
Hostname: opt.Host,
}
// run restore
_, err := nw.DumpOnce(opt)
hostStats.Duration = time.Since(startTime).String()
if err != nil {
hostStats.Phase = api_v1beta1.HostRestoreFailed
hostStats.Error = err.Error()
mu.Lock()
restoreErrs = append(restoreErrs, err)
mu.Unlock()
return
} else {
hostStats.Phase = api_v1beta1.HostRestoreSucceeded
}
hostStats := api_v1beta1.HostRestoreStats{
Hostname: opt.Host,
}
hostStats.Duration = time.Since(startTime).String()
hostStats.Phase = api_v1beta1.HostRestoreSucceeded

// add hostStats to restoreOutput
// add hostStats to restoreOutput. use lock to avoid racing condition.
mu.Lock()
restoreOutput.upsertHostRestoreStats(hostStats)
mu.Unlock()
}(dumpOptions[i], time.Now())
}

// wait for all the go routines to complete
wg.Wait()

Expand Down

0 comments on commit 1e979c4

Please sign in to comment.