GH-76: DynamoDbMDStore: add create retry options

Resolves spring-projects/spring-integration-aws#77
Resolves spring-projects/spring-integration-aws#76

Add configuration options in the `DynamoDbMetaDataStore`
for the retry policy for the `DescribeTableRequest`
Change the `createTableLatch` to wait for the whole retry time
This commit is contained in:
Artem Bilan
2017-09-15 16:53:25 -04:00
parent 464213001e
commit 43754e19c6
3 changed files with 24 additions and 10 deletions

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Wed Jul 26 16:30:33 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip

View File

@@ -80,9 +80,13 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
private final CountDownLatch createTableLatch = new CountDownLatch(1);
private Long readCapacity = 10000L;
private int createTableRetries = 25;
private Long writeCapacity = 10000L;
private int createTableDelay = 1;
private long readCapacity = 1L;
private long writeCapacity = 1L;
public DynamoDbMetaDataStore(AmazonDynamoDBAsync dynamoDB) {
this(dynamoDB, DEFAULT_TABLE_NAME);
@@ -98,14 +102,22 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
}
public void setReadCapacity(Long readCapacity) {
public void setReadCapacity(long readCapacity) {
this.readCapacity = readCapacity;
}
public void setWriteCapacity(Long writeCapacity) {
public void setWriteCapacity(long writeCapacity) {
this.writeCapacity = writeCapacity;
}
public void setCreateTableRetries(int createTableRetries) {
this.createTableRetries = createTableRetries;
}
public void setCreateTableDelay(int createTableDelay) {
this.createTableDelay = createTableDelay;
}
@Override
public void afterPropertiesSet() throws Exception {
try {
@@ -147,8 +159,9 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
new WaiterParameters<>(
new DescribeTableRequest(DynamoDbMetaDataStore.this.table.getTableName()))
.withPollingStrategy(
new PollingStrategy(new MaxAttemptsRetryStrategy(25),
new FixedDelayStrategy(1)));
new PollingStrategy(
new MaxAttemptsRetryStrategy(DynamoDbMetaDataStore.this.createTableRetries),
new FixedDelayStrategy(DynamoDbMetaDataStore.this.createTableDelay)));
waiter.runAsync(waiterParameters, new WaiterHandler<DescribeTableRequest>() {
@@ -173,10 +186,12 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
private void awaitForActive() {
try {
this.createTableLatch.await(10, TimeUnit.SECONDS);
this.createTableLatch.await(this.createTableRetries * this.createTableDelay, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("The DynamoDb table " + this.table.getTableName() +
" has not been created during " + this.createTableRetries * this.createTableDelay + " seconds");
}
}