-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Migrate the S3 SDK from v1 to v2 #16664
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,75 @@ | ||
/* | ||
Copyright 2024 The Vitess Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package s3backupstorage | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
) | ||
|
||
// ClosedConnectionRetryer implements the aws request.Retryer interface | ||
// ClosedConnectionRetryer implements the aws.Retryer interface | ||
// and is used to retry closed connection errors during MultipartUpload | ||
// operations. | ||
// operations. It is a simplified version of the RetryableConnectionError | ||
// implementation, which always retry on any type of connection error. | ||
type ClosedConnectionRetryer struct { | ||
awsRetryer request.Retryer | ||
awsRetryer aws.Retryer | ||
} | ||
|
||
// RetryRules is part of the Retryer interface. It defers to the underlying | ||
// aws Retryer to compute backoff rules. | ||
func (retryer *ClosedConnectionRetryer) RetryRules(r *request.Request) time.Duration { | ||
return retryer.awsRetryer.RetryRules(r) | ||
} | ||
|
||
// ShouldRetry is part of the Retryer interface. It retries on errors that occur | ||
// due to a closed network connection, and then falls back to the underlying aws | ||
// Retryer for checking additional retry conditions. | ||
func (retryer *ClosedConnectionRetryer) ShouldRetry(r *request.Request) bool { | ||
if retryer.MaxRetries() == 0 { | ||
// IsErrorRetryable returns true if the error should be retried. We first try | ||
// to see if the error is due to the use of a closed connection, if it is, | ||
// we retry, and if not, we default to what the aws.Retryer would do. | ||
func (retryer *ClosedConnectionRetryer) IsErrorRetryable(err error) bool { | ||
if retryer.MaxAttempts() == 0 { | ||
return false | ||
} | ||
|
||
if r.Retryable != nil { | ||
return *r.Retryable | ||
} | ||
|
||
if r.Error != nil { | ||
if awsErr, ok := r.Error.(awserr.Error); ok { | ||
if strings.Contains(awsErr.Error(), "use of closed network connection") { | ||
return true | ||
} | ||
if err != nil { | ||
if strings.Contains(err.Error(), "use of closed network connection") { | ||
return true | ||
} | ||
} | ||
|
||
return retryer.awsRetryer.ShouldRetry(r) | ||
return retryer.awsRetryer.IsErrorRetryable(err) | ||
} | ||
|
||
// MaxAttempts returns the maximum number of attempts that can be made for | ||
// an attempt before failing. A value of 0 implies that the attempt should | ||
// be retried until it succeeds if the errors are retryable. | ||
func (retryer *ClosedConnectionRetryer) MaxAttempts() int { | ||
return retryer.awsRetryer.MaxAttempts() | ||
} | ||
|
||
// RetryDelay returns the delay that should be used before retrying the | ||
// attempt. Will return error if the delay could not be determined. | ||
func (retryer *ClosedConnectionRetryer) RetryDelay(attempt int, opErr error) (time.Duration, error) { | ||
return retryer.awsRetryer.RetryDelay(attempt, opErr) | ||
} | ||
|
||
// GetRetryToken attempts to deduct the retry cost from the retry token pool. | ||
// Returning the token release function, or error. | ||
func (retryer *ClosedConnectionRetryer) GetRetryToken(ctx context.Context, opErr error) (releaseToken func(error) error, err error) { | ||
return retryer.awsRetryer.GetRetryToken(ctx, opErr) | ||
} | ||
|
||
// MaxRetries is part of the Retryer interface. It defers to the | ||
// underlying aws Retryer for the max number of retries. | ||
func (retryer *ClosedConnectionRetryer) MaxRetries() int { | ||
return retryer.awsRetryer.MaxRetries() | ||
// GetInitialToken returns the initial attempt token that can increment the | ||
// retry token pool if the attempt is successful. | ||
func (retryer *ClosedConnectionRetryer) GetInitialToken() (releaseToken func(error) error) { | ||
return retryer.awsRetryer.GetInitialToken() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor.