Skip to content

Commit 8108a29

Browse files
committed
fixed static int to structs
1 parent 8a8bb7b commit 8108a29

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

src/aws-cpp-sdk-core/include/aws/core/internal/RetryStrategyImpl.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ namespace Aws
1515
{
1616
namespace Client
1717
{
18-
static const int THROTTLE_BASED_RETRY_COST = 14;
19-
static const int THROTTLE_BASED_THROTTLING_COST = 5;
20-
static const int THROTTLE_BASED_INITIAL_TOKENS = 500;
18+
struct QuotaConfig
19+
{
20+
int retryCost = 14;
21+
int throttlingCost = 5;
22+
int initialTokens = 500;
23+
};
2124

2225
class AWS_CORE_LOCAL ThrottleBasedRetryQuotaContainer : public RetryQuotaContainer
2326
{
2427
public:
25-
ThrottleBasedRetryQuotaContainer(int retryCost = THROTTLE_BASED_RETRY_COST, int throttlingRetryCost = THROTTLE_BASED_THROTTLING_COST)
26-
: m_retryQuota(THROTTLE_BASED_INITIAL_TOKENS), m_retryCost(retryCost), m_throttlingRetryCost(throttlingRetryCost) {}
28+
ThrottleBasedRetryQuotaContainer(const QuotaConfig& config = QuotaConfig{})
29+
: m_config(config), m_retryQuota(config.initialTokens) {}
2730

2831
virtual ~ThrottleBasedRetryQuotaContainer() = default;
2932

@@ -43,29 +46,28 @@ namespace Aws
4346

4447
bool AcquireRetryQuota(const AWSError<CoreErrors>& error) override
4548
{
46-
int capacityAmount = error.ShouldThrottle() ? m_throttlingRetryCost : m_retryCost;
49+
int capacityAmount = error.ShouldThrottle() ? m_config.throttlingCost : m_config.retryCost;
4750
return AcquireRetryQuota(capacityAmount);
4851
}
4952

5053
void ReleaseRetryQuota(int capacityAmount) override
5154
{
5255
Aws::Utils::Threading::WriterLockGuard guard(m_retryQuotaLock);
53-
m_retryQuota = (std::min)(m_retryQuota + capacityAmount, THROTTLE_BASED_INITIAL_TOKENS);
56+
m_retryQuota = (std::min)(m_retryQuota + capacityAmount, m_config.initialTokens);
5457
}
5558

5659
void ReleaseRetryQuota(const AWSError<CoreErrors>& error) override
5760
{
58-
int capacityAmount = error.ShouldThrottle() ? m_throttlingRetryCost : m_retryCost;
61+
int capacityAmount = error.ShouldThrottle() ? m_config.throttlingCost : m_config.retryCost;
5962
ReleaseRetryQuota(capacityAmount);
6063
}
6164

6265
int GetRetryQuota() const override { return m_retryQuota; }
6366

6467
private:
68+
QuotaConfig m_config;
6569
mutable Aws::Utils::Threading::ReaderWriterLock m_retryQuotaLock;
6670
int m_retryQuota;
67-
int m_retryCost;
68-
int m_throttlingRetryCost;
6971
};
7072
} // namespace Client
7173
} // namespace Aws

src/aws-cpp-sdk-core/source/client/RetryStrategy.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
using namespace Aws::Utils::Threading;
1717
using namespace Aws::Client;
1818

19-
static const char RETRY_STRATEGY_TAG[] = "StandardRetryStrategy";
20-
2119
namespace Aws
2220
{
2321
namespace Client
@@ -32,6 +30,8 @@ namespace Aws
3230
}
3331

3432
namespace {
33+
const char RETRY_STRATEGY_TAG[] = "StandardRetryStrategy";
34+
3535
bool IsNewRetriesEnabled()
3636
{
3737
return Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_NEW_RETRIES_2026").c_str()) == "true";
@@ -44,7 +44,7 @@ namespace {
4444
{
4545
AWS_UNREFERENCED_PARAM(error);
4646
// Maximum left shift factor is capped by ceil(log2(max_delay)), to avoid wrap-around and overflow into negative values:
47-
return std::min(static_cast<int>(Aws::Utils::GetRandomValue() % 1000) * (1 << std::min(attemptedRetries, 15L)), 20000);
47+
return (std::min)(static_cast<int>(Aws::Utils::GetRandomValue() % 1000) * (1 << (std::min)(attemptedRetries, 15L)), 20000);
4848
}
4949
};
5050

@@ -65,13 +65,13 @@ namespace {
6565
if (it != headers.end())
6666
{
6767
long long headerMs = Aws::Utils::StringUtils::ConvertToInt64(it->second.c_str());
68-
if (headerMs < 0)
68+
if (headerMs >= 0)
6969
{
70-
AWS_LOGSTREAM_DEBUG(RETRY_STRATEGY_TAG, "Ignoring invalid x-amz-retry-after value: " << it->second);
70+
double headerSec = static_cast<double>(headerMs) / 1000.0;
71+
double clamped = (std::max)(t_i, (std::min)(headerSec, 5.0 + t_i));
72+
return static_cast<long>(clamped * 1000.0);
7173
}
72-
double headerSec = static_cast<double>(headerMs) / 1000.0;
73-
double clamped = (std::max)(t_i, (std::min)(headerSec, 5.0 + t_i));
74-
return static_cast<long>(clamped * 1000.0);
74+
AWS_LOGSTREAM_DEBUG(RETRY_STRATEGY_TAG, "Ignoring invalid x-amz-retry-after value: " << it->second);
7575
}
7676

7777
return static_cast<long>(t_i * 1000.0);

tests/aws-cpp-sdk-core-tests/aws/client/RetryStrategyTest.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,4 @@ TEST_F(NewRetriesStrategyTest, InvalidRetryAfterFallsBack)
290290
long delay = retryStrategy.CalculateDelayBeforeNextRetry(error, 0);
291291
ASSERT_GE(delay, 0);
292292
ASSERT_LE(delay, 50);
293-
}
294-
295-
// SEP Test Cases 2, 4, 7 are covered by TestStandardRetryStrategy above (same behavior with/without gate).
296-
// TODO: SEP Test Case 11 (DynamoDB 25ms base) deferred to next PR.
297-
// TODO: SEP Test Cases 12-16 (long-polling) require pipeline integration tests.
293+
}

0 commit comments

Comments
 (0)