Skip to content

Commit 3c6926b

Browse files
authored
optimize retry in backup prepare (#445)
Signed-off-by: wayblink <[email protected]>
1 parent 99e51a0 commit 3c6926b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

core/backup_impl_create_backup.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,25 @@ func (b *BackupContext) executeCreateBackup(ctx context.Context, request *backup
698698
for _, collection := range toBackupCollections {
699699
collectionClone := collection
700700
job := func(ctx context.Context) error {
701-
err := retry.Do(ctx, func() error {
702-
return b.backupCollectionPrepare(ctx, backupInfo, collectionClone, request.GetForce())
703-
}, retry.Sleep(120*time.Second), retry.Attempts(128))
704-
return err
701+
retryForSpecificError := func(retries int, delay time.Duration) error {
702+
for i := 0; i < retries; i++ {
703+
err := b.backupCollectionPrepare(ctx, backupInfo, collectionClone, request.GetForce())
704+
// If no error, return successfully
705+
if err == nil {
706+
return nil
707+
}
708+
// Retry only for the specific error
709+
if strings.Contains(err.Error(), "rate limit exceeded") {
710+
fmt.Printf("Attempt %d: Temporary error occurred, retrying...\n", i+1)
711+
time.Sleep(delay)
712+
continue
713+
}
714+
// Return immediately for any other error
715+
return err
716+
}
717+
return fmt.Errorf("operation failed after %d retries", retries)
718+
}
719+
return retryForSpecificError(10, 10*time.Second)
705720
}
706721
jobId := b.getBackupCollectionWorkerPool().SubmitWithId(job)
707722
jobIds = append(jobIds, jobId)

core/storage/local_chunk_manager.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ func (lcm *LocalChunkManager) UploadObject(ctx context.Context, i UploadObjectIn
234234
return err
235235
}
236236

237-
fmt.Println("Successfully written to file!")
238237
return nil
239238
}
240239

@@ -356,7 +355,7 @@ func CopyDir(source string, dest string) (err error) {
356355
}
357356

358357
func CopyFile(source string, dest string) (err error) {
359-
358+
360359
// get properties of source parent dir
361360
sourceParentDir := filepath.Dir(source)
362361
sourceParentDirInfo, err := os.Stat(sourceParentDir)

0 commit comments

Comments
 (0)