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

Add retry with exponential backoff to S3ObjectClient.PutObject() #4732

Closed
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
39 changes: 26 additions & 13 deletions pkg/storage/chunk/aws/s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,35 @@ func (a *S3ObjectClient) GetObject(ctx context.Context, objectKey string) (io.Re

// PutObject into the store
func (a *S3ObjectClient) PutObject(ctx context.Context, objectKey string, object io.ReadSeeker) error {
return instrument.CollectedRequest(ctx, "S3.PutObject", s3RequestDuration, instrument.ErrorCode, func(ctx context.Context) error {
putObjectInput := &s3.PutObjectInput{
Body: object,
Bucket: aws.String(a.bucketFromKey(objectKey)),
Key: aws.String(objectKey),
bucket := a.bucketFromKey(objectKey)
retries := backoff.New(ctx, a.cfg.BackoffConfig)
err := ctx.Err()
for retries.Ongoing() {
if ctx.Err() != nil {
return errors.Wrap(ctx.Err(), "ctx related error during s3 putObject")
}
err = instrument.CollectedRequest(ctx, "S3.PutObject", s3RequestDuration, instrument.ErrorCode, func(ctx context.Context) error {
putObjectInput := &s3.PutObjectInput{
Body: object,
Bucket: aws.String(bucket),
Key: aws.String(objectKey),
}

if a.sseConfig != nil {
putObjectInput.ServerSideEncryption = aws.String(a.sseConfig.ServerSideEncryption)
putObjectInput.SSEKMSKeyId = a.sseConfig.KMSKeyID
putObjectInput.SSEKMSEncryptionContext = a.sseConfig.KMSEncryptionContext
}
if a.sseConfig != nil {
putObjectInput.ServerSideEncryption = aws.String(a.sseConfig.ServerSideEncryption)
putObjectInput.SSEKMSKeyId = a.sseConfig.KMSKeyID
putObjectInput.SSEKMSEncryptionContext = a.sseConfig.KMSEncryptionContext
}

_, err := a.S3.PutObjectWithContext(ctx, putObjectInput)
return err
})
_, requestErr := a.S3.PutObjectWithContext(ctx, putObjectInput)
return requestErr
})
if err == nil {
return nil
}
retries.Wait()
}
return errors.Wrap(err, "failed to put s3 object")
}

// List implements chunk.ObjectClient.
Expand Down