Skip to content

Commit

Permalink
restore: improve progress report on retries
Browse files Browse the repository at this point in the history
  • Loading branch information
vroldanbet committed Dec 20, 2023
1 parent 4baac8f commit 041cb09
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/cmd/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
Fail ConflictStrategy = iota
Skip
Touch

defaultBackoff = 50 * time.Millisecond
defaultMaxRetries = 10
)

var conflictStrategyMapping = map[string]ConflictStrategy{
Expand Down Expand Up @@ -299,7 +302,7 @@ func (r *restorer) commitStream(ctx context.Context, bulkImportClient v1.Experim
// each batch will be committed independently. If a batch fails, it will be retried up to 10 times with a backoff.
func (r *restorer) writeBatchesWithRetry(ctx context.Context, batches [][]*v1.Relationship) (uint64, uint64, error) {
backoffInterval := backoff.NewExponentialBackOff()
backoffInterval.InitialInterval = 10 * time.Millisecond
backoffInterval.InitialInterval = defaultBackoff
backoffInterval.MaxInterval = 2 * time.Second
backoffInterval.MaxElapsedTime = 0
backoffInterval.Reset()
Expand All @@ -314,17 +317,19 @@ func (r *restorer) writeBatchesWithRetry(ctx context.Context, batches [][]*v1.Re
})

for {
// throttle the writes so we don't overwhelm the server
time.Sleep(backoffInterval.NextBackOff())
cancelCtx, cancel := context.WithTimeout(ctx, r.requestTimeout)
_, err := r.client.WriteRelationships(cancelCtx, &v1.WriteRelationshipsRequest{Updates: updates})
cancel()

if isRetryableError(err) && currentRetries < 10 {
if isRetryableError(err) && currentRetries < defaultMaxRetries {
// throttle the writes so we don't overwhelm the server
bo := backoffInterval.NextBackOff()
r.bar.Describe(fmt.Sprintf("retrying write with backoff %s after error (attempt %d/%d)", bo,
currentRetries+1, defaultMaxRetries))
time.Sleep(bo)
currentRetries++
r.totalRetries++
totalRetries++
r.bar.Describe(fmt.Sprintf("retrying after error (attempt %d)", currentRetries+1))
continue
}
if err != nil {
Expand Down

0 comments on commit 041cb09

Please sign in to comment.