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

[aws-cpp-sdk-s3-crt] support for the exponential back-off retry strategy #2615

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ namespace Aws
/* Callback and associated user data for when the client has completed its shutdown process. */
std::function<void(void*)> clientShutdownCallback;
void *shutdownCallbackUserData = nullptr;

/**
* Parameters for the AWS_C_S3_RETRY_STRATEGY::EXPONENTIAL_BACKOFF strategy.
*/
/* Maximum number of request retries. Specifying 0 here will fall back to the default set by aws-c-io. */
size_t exponentialBackoffMaxRetries = 0;

/* Scale factor (in seconds) for the back-off value. */
double exponentialBackoffScaleFactor = 1.0;

/* Maximum delay between retries (in seconds). Specifying 0 here will fall back to the default set by aws-c-io. */
uint32_t exponentialMaxBackoffSecs = 0;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ namespace Aws
REGIONAL //stands for using regional endpoint for us-east-1
};


/** AWS_C_S3_RETRY_STRATEGY specifies the aws-c-s3 retry strategy to use. */
enum class AWS_C_S3_RETRY_STRATEGY
{
DEFAULT=0, /* Defaults to standard now but may change. */
STANDARD,
EXPONENTIAL_BACKOFF,
NO_RETRY=-1,
};

struct AWS_S3CRT_API S3CrtClientConfiguration : public Aws::Client::GenericClientConfiguration</*EndpointDiscoverySupported*/true>
{
using BaseClientConfigClass = Aws::Client::GenericClientConfiguration</*EndpointDiscoverySupported*/true>;
Expand Down Expand Up @@ -54,6 +64,7 @@ namespace Aws

bool useVirtualAddressing = true;
US_EAST_1_REGIONAL_ENDPOINT_OPTION useUSEast1RegionalEndPointOption = US_EAST_1_REGIONAL_ENDPOINT_OPTION::NOT_SET;
AWS_C_S3_RETRY_STRATEGY s3CrtRetryStrategy = AWS_C_S3_RETRY_STRATEGY::DEFAULT;
bool disableMultiRegionAccessPoints = false;
bool useArnRegion = false;
Client::AWSAuthV4Signer::PayloadSigningPolicy payloadSigningPolicy = Client::AWSAuthV4Signer::PayloadSigningPolicy::RequestDependent;
Expand Down
15 changes: 14 additions & 1 deletion generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config,
AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider);
m_endpointProvider->InitBuiltInParameters(config);

// initialize aws_s3_client;
// initialize aws_s3_client:
aws_s3_client_config s3CrtConfig;
AWS_ZERO_STRUCT(s3CrtConfig);
s3CrtConfig.region = Aws::Crt::ByteCursorFromCString(config.region.c_str());
Expand Down Expand Up @@ -330,6 +330,18 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config,
Aws::Crt::Io::ClientBootstrap* clientBootstrap = config.clientBootstrap ? config.clientBootstrap.get() : Aws::GetDefaultClientBootstrap();
s3CrtConfig.client_bootstrap = clientBootstrap->GetUnderlyingHandle();


if (config.s3CrtRetryStrategy == AWS_C_S3_RETRY_STRATEGY::EXPONENTIAL_BACKOFF) {
struct aws_exponential_backoff_retry_options retry_options = {
.el_group = s3CrtConfig.client_bootstrap->event_loop_group,
.max_retries = config.exponentialBackoffMaxRetries,
.backoff_scale_factor_ms = static_cast<uint32_t>(config.exponentialBackoffScaleFactor * 1e3),
.max_backoff_secs = config.exponentialMaxBackoffSecs,
.jitter_mode = AWS_EXPONENTIAL_BACKOFF_JITTER_FULL,
};
s3CrtConfig.retry_strategy = aws_retry_strategy_new_exponential_backoff(Aws::get_aws_allocator(), &retry_options);
}

m_crtCredProvider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderDelegate({
std::bind([](const std::shared_ptr<AWSCredentialsProvider>& provider) {
if (provider == nullptr) {
Expand Down Expand Up @@ -480,6 +492,7 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config,
{
aws_tls_connection_options_clean_up(&nonConstTlsOptions);
}
aws_retry_strategy_release(s3CrtConfig.retry_strategy);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws_retry_strategy_release does nothing when given a NULL parameter, so safe to use with defaults.

if (!m_s3CrtClient)
{
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to allocate aws_s3_client instance, abort.");
Expand Down