Skip to content

Commit 2ce643b

Browse files
committed
moved function to header
1 parent 7323afe commit 2ce643b

3 files changed

Lines changed: 46 additions & 45 deletions

File tree

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

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,51 @@ 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;
21+
1822
class AWS_CORE_LOCAL ThrottleBasedRetryQuotaContainer : public RetryQuotaContainer
1923
{
2024
public:
21-
ThrottleBasedRetryQuotaContainer(int retryCost = 14, int throttlingRetryCost = 5);
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) {}
27+
2228
virtual ~ThrottleBasedRetryQuotaContainer() = default;
23-
virtual bool AcquireRetryQuota(int capacityAmount) override;
24-
virtual bool AcquireRetryQuota(const AWSError<CoreErrors>& error) override;
25-
virtual void ReleaseRetryQuota(int capacityAmount) override;
26-
virtual void ReleaseRetryQuota(const AWSError<CoreErrors>& lastError) override;
27-
virtual int GetRetryQuota() const override { return m_retryQuota; }
29+
30+
bool AcquireRetryQuota(int capacityAmount) override
31+
{
32+
Aws::Utils::Threading::WriterLockGuard guard(m_retryQuotaLock);
33+
if (capacityAmount > m_retryQuota)
34+
{
35+
return false;
36+
}
37+
else
38+
{
39+
m_retryQuota -= capacityAmount;
40+
return true;
41+
}
42+
}
43+
44+
bool AcquireRetryQuota(const AWSError<CoreErrors>& error) override
45+
{
46+
int capacityAmount = error.ShouldThrottle() ? m_throttlingRetryCost : m_retryCost;
47+
return AcquireRetryQuota(capacityAmount);
48+
}
49+
50+
void ReleaseRetryQuota(int capacityAmount) override
51+
{
52+
Aws::Utils::Threading::WriterLockGuard guard(m_retryQuotaLock);
53+
m_retryQuota = (std::min)(m_retryQuota + capacityAmount, THROTTLE_BASED_INITIAL_TOKENS);
54+
}
55+
56+
void ReleaseRetryQuota(const AWSError<CoreErrors>& error) override
57+
{
58+
int capacityAmount = error.ShouldThrottle() ? m_throttlingRetryCost : m_retryCost;
59+
ReleaseRetryQuota(capacityAmount);
60+
}
61+
62+
int GetRetryQuota() const override { return m_retryQuota; }
2863

2964
private:
3065
mutable Aws::Utils::Threading::ReaderWriterLock m_retryQuotaLock;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String re
562562
{
563563
if (maxAttempts < 0)
564564
{
565+
// negative value set above force usage of default max attempts
565566
retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG);
566567
}
567568
else
@@ -573,6 +574,7 @@ std::shared_ptr<RetryStrategy> InitRetryStrategy(int maxAttempts, Aws::String re
573574
{
574575
if (maxAttempts < 0)
575576
{
577+
// negative value set above force usage of default max attempts
576578
retryStrategy = Aws::MakeShared<AdaptiveRetryStrategy>(CLIENT_CONFIG_TAG);
577579
}
578580
else

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

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace Aws
4444
long CalculateDelay(const AWSError<CoreErrors>& error, long attemptedRetries) const override
4545
{
4646
double x = error.ShouldThrottle() ? 1.0 : 0.05;
47-
double exponentialPart = x * static_cast<double>(1L << std::min(attemptedRetries, 30L));
48-
double cappedPart = std::min(exponentialPart, 20.0);
47+
double exponentialPart = x * static_cast<double>(1L << (std::min)(attemptedRetries, 30L));
48+
double cappedPart = (std::min)(exponentialPart, 20.0);
4949

5050
double b = static_cast<double>(Aws::Utils::GetRandomValue() % 10000) / 10000.0;
5151
double t_i = b * cappedPart;
@@ -55,7 +55,7 @@ namespace Aws
5555
if (it != headers.end())
5656
{
5757
double headerSec = static_cast<double>(Aws::Utils::StringUtils::ConvertToInt64(it->second.c_str())) / 1000.0;
58-
double clamped = std::max(t_i, std::min(headerSec, 5.0 + t_i));
58+
double clamped = (std::max)(t_i, (std::min)(headerSec, 5.0 + t_i));
5959
return static_cast<long>(clamped * 1000.0);
6060
}
6161

@@ -160,41 +160,5 @@ namespace Aws
160160
ReleaseRetryQuota(capacityAmount);
161161
}
162162

163-
ThrottleBasedRetryQuotaContainer::ThrottleBasedRetryQuotaContainer(int retryCost, int throttlingRetryCost)
164-
: m_retryQuota(INITIAL_RETRY_TOKENS), m_retryCost(retryCost), m_throttlingRetryCost(throttlingRetryCost)
165-
{}
166-
167-
bool ThrottleBasedRetryQuotaContainer::AcquireRetryQuota(int capacityAmount)
168-
{
169-
WriterLockGuard guard(m_retryQuotaLock);
170-
171-
if (capacityAmount > m_retryQuota)
172-
{
173-
return false;
174-
}
175-
else
176-
{
177-
m_retryQuota -= capacityAmount;
178-
return true;
179-
}
180-
}
181-
182-
bool ThrottleBasedRetryQuotaContainer::AcquireRetryQuota(const AWSError<CoreErrors>& error)
183-
{
184-
int capacityAmount = error.ShouldThrottle() ? m_throttlingRetryCost : m_retryCost;
185-
return AcquireRetryQuota(capacityAmount);
186-
}
187-
188-
void ThrottleBasedRetryQuotaContainer::ReleaseRetryQuota(int capacityAmount)
189-
{
190-
WriterLockGuard guard(m_retryQuotaLock);
191-
m_retryQuota = (std::min)(m_retryQuota + capacityAmount, INITIAL_RETRY_TOKENS);
192-
}
193-
194-
void ThrottleBasedRetryQuotaContainer::ReleaseRetryQuota(const AWSError<CoreErrors>& error)
195-
{
196-
int capacityAmount = error.ShouldThrottle() ? m_throttlingRetryCost : m_retryCost;
197-
ReleaseRetryQuota(capacityAmount);
198-
}
199163
}
200164
}

0 commit comments

Comments
 (0)