diff --git a/generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json b/generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json new file mode 100644 index 000000000000..7e794ed2d15f --- /dev/null +++ b/generator/.DevConfigs/1cecd29e-66f5-4ac7-be16-2df3ba18f3d2.json @@ -0,0 +1,11 @@ +{ + "services": [ + { + "serviceName": "DynamoDBv2", + "type": "patch", + "changeLogMessages": [ + "Add DynamoDBRetryPolicy.WaitBeforeRetryAsync override method in order to use the updated retry logic for async retries." + ] + } + ] +} \ No newline at end of file diff --git a/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs b/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs index ce9270383ab4..a59298271fc2 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Internal/DynamoDBRetryPolicy.cs @@ -1,12 +1,12 @@ -/* +/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at - * + * * http://aws.amazon.com/apache2.0 - * + * * or in the "license" file accompanying this file. This file 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 @@ -14,10 +14,7 @@ */ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - +using System.Threading.Tasks; using Amazon.Runtime; using Amazon.Runtime.Internal; @@ -38,12 +35,12 @@ public DynamoDBRetryPolicy(IClientConfig config) : base(config) { ThrottlingErrorCodes.Add("TransactionInProgressException"); - - //When derived from DefaultRetryPolicy, we are in legacy retry + + //When derived from DefaultRetryPolicy, we are in legacy retry //mode. When in legacy retry mode MaxErrorRetry used to be set //to 10 in the DynamoDB and DynamoDBStreams configs. This //can no longer be set in the configs because the retry mode - //may not be known at that point where standard and adaptive + //may not be known at that point where standard and adaptive //retry modes are not to have this default. if(!config.IsMaxErrorRetrySet) { @@ -57,24 +54,32 @@ public DynamoDBRetryPolicy(IClientConfig config) : /// public override void WaitBeforeRetry(IExecutionContext executionContext) { - pauseExponentially(executionContext.RequestContext.Retries); + Amazon.Util.AWSSDKUtils.Sleep(CalculateRetryDelay(executionContext.RequestContext.Retries)); + } + + /// + /// Overriden to cause a pause between retries. + /// + /// + public override Task WaitBeforeRetryAsync(IExecutionContext executionContext) + { + return Task.Delay(CalculateRetryDelay(executionContext.RequestContext.Retries), executionContext.RequestContext.CancellationToken); } /// /// Override the pausing function so retries would happen more frequent then the default operation. /// - /// Current number of retries. - private void pauseExponentially(int retries) + private int CalculateRetryDelay(int retries) { int delay; - + if (retries <= 0) delay = 0; else if (retries < 20) delay = Convert.ToInt32(Math.Pow(2, retries - 1) * 50.0); else delay = Int32.MaxValue; if (retries > 0 && (delay > MaxBackoffInMilliseconds || delay <= 0)) delay = MaxBackoffInMilliseconds; - Amazon.Util.AWSSDKUtils.Sleep(delay); + return delay; } } }