1
- /*
1
+ /*
2
2
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
3
+ *
4
4
* Licensed under the Apache License, Version 2.0 (the "License").
5
5
* You may not use this file except in compliance with the License.
6
6
* A copy of the License is located at
7
- *
7
+ *
8
8
* http://aws.amazon.com/apache2.0
9
- *
9
+ *
10
10
* or in the "license" file accompanying this file. This file is distributed
11
11
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
12
* express or implied. See the License for the specific language governing
13
13
* permissions and limitations under the License.
14
14
*/
15
15
16
16
using System ;
17
- using System . Collections . Generic ;
18
- using System . Linq ;
19
- using System . Text ;
20
-
17
+ using System . Threading ;
18
+ using System . Threading . Tasks ;
21
19
using Amazon . Runtime ;
22
20
using Amazon . Runtime . Internal ;
23
21
@@ -38,12 +36,12 @@ public DynamoDBRetryPolicy(IClientConfig config) :
38
36
base ( config )
39
37
{
40
38
ThrottlingErrorCodes . Add ( "TransactionInProgressException" ) ;
41
-
42
- //When derived from DefaultRetryPolicy, we are in legacy retry
39
+
40
+ //When derived from DefaultRetryPolicy, we are in legacy retry
43
41
//mode. When in legacy retry mode MaxErrorRetry used to be set
44
42
//to 10 in the DynamoDB and DynamoDBStreams configs. This
45
43
//can no longer be set in the configs because the retry mode
46
- //may not be known at that point where standard and adaptive
44
+ //may not be known at that point where standard and adaptive
47
45
//retry modes are not to have this default.
48
46
if ( ! config . IsMaxErrorRetrySet )
49
47
{
@@ -57,24 +55,32 @@ public DynamoDBRetryPolicy(IClientConfig config) :
57
55
/// <param name="executionContext"></param>
58
56
public override void WaitBeforeRetry ( IExecutionContext executionContext )
59
57
{
60
- pauseExponentially ( executionContext . RequestContext . Retries ) ;
58
+ Thread . Sleep ( CalculateRetryDelay ( executionContext . RequestContext . Retries ) ) ;
59
+ }
60
+
61
+ /// <summary>
62
+ /// Overriden to cause a pause between retries.
63
+ /// </summary>
64
+ /// <param name="executionContext"></param>
65
+ public override Task WaitBeforeRetryAsync ( IExecutionContext executionContext )
66
+ {
67
+ return Task . Delay ( CalculateRetryDelay ( executionContext . RequestContext . Retries ) , executionContext . RequestContext . CancellationToken ) ;
61
68
}
62
69
63
70
/// <summary>
64
71
/// Override the pausing function so retries would happen more frequent then the default operation.
65
72
/// </summary>
66
- /// <param name="retries">Current number of retries.</param>
67
- private void pauseExponentially ( int retries )
73
+ private int CalculateRetryDelay ( int retries )
68
74
{
69
75
int delay ;
70
-
76
+
71
77
if ( retries <= 0 ) delay = 0 ;
72
78
else if ( retries < 20 ) delay = Convert . ToInt32 ( Math . Pow ( 2 , retries - 1 ) * 50.0 ) ;
73
79
else delay = Int32 . MaxValue ;
74
80
75
81
if ( retries > 0 && ( delay > MaxBackoffInMilliseconds || delay <= 0 ) )
76
82
delay = MaxBackoffInMilliseconds ;
77
- Amazon . Util . AWSSDKUtils . Sleep ( delay ) ;
83
+ return delay ;
78
84
}
79
85
}
80
86
}
0 commit comments