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

optimize retry in backup prepare #445

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
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
Loading