Skip to content

Commit

Permalink
optimize retry in backup prepare
Browse files Browse the repository at this point in the history
Signed-off-by: wayblink <[email protected]>
  • Loading branch information
wayblink committed Oct 25, 2024
1 parent 99e51a0 commit 943807f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 19 additions & 4 deletions core/backup_impl_create_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,25 @@ func (b *BackupContext) executeCreateBackup(ctx context.Context, request *backup
for _, collection := range toBackupCollections {
collectionClone := collection
job := func(ctx context.Context) error {
err := retry.Do(ctx, func() error {
return b.backupCollectionPrepare(ctx, backupInfo, collectionClone, request.GetForce())
}, retry.Sleep(120*time.Second), retry.Attempts(128))
return err
retryForSpecificError := func(retries int, delay time.Duration) error {
for i := 0; i < retries; i++ {
err := b.backupCollectionPrepare(ctx, backupInfo, collectionClone, request.GetForce())
// If no error, return successfully
if err == nil {
return nil
}
// Retry only for the specific error
if strings.Contains(err.Error(), "rate limit exceeded") {
fmt.Printf("Attempt %d: Temporary error occurred, retrying...\n", i+1)
time.Sleep(delay)
continue
}
// Return immediately for any other error
return err
}
return fmt.Errorf("operation failed after %d retries", retries)
}
return retryForSpecificError(10, 10*time.Second)
}
jobId := b.getBackupCollectionWorkerPool().SubmitWithId(job)
jobIds = append(jobIds, jobId)
Expand Down
3 changes: 1 addition & 2 deletions core/storage/local_chunk_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func (lcm *LocalChunkManager) UploadObject(ctx context.Context, i UploadObjectIn
return err
}

fmt.Println("Successfully written to file!")
return nil
}

Expand Down Expand Up @@ -356,7 +355,7 @@ func CopyDir(source string, dest string) (err error) {
}

func CopyFile(source string, dest string) (err error) {

// get properties of source parent dir
sourceParentDir := filepath.Dir(source)
sourceParentDirInfo, err := os.Stat(sourceParentDir)
Expand Down

0 comments on commit 943807f

Please sign in to comment.