Protect DynamoLockReg & DynamoMDS from hanging

If `DynamoDbLockRegistry` and `DynamoDbMetaDataStore` are not declared
as beans (or their `afterPropertiesSet()` is not called), they hanging on
the `awaitForActive()`
This commit is contained in:
Artem Bilan
2018-06-28 11:47:59 -04:00
parent 9e14e86880
commit d192e17007
2 changed files with 37 additions and 0 deletions

View File

@@ -135,6 +135,8 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
*/
private boolean executorExplicitlySet;
private volatile boolean initialized;
public DynamoDbLockRegistry(AmazonDynamoDB dynamoDB) {
this(dynamoDB, DEFAULT_TABLE_NAME);
@@ -279,9 +281,14 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
this.createTableLatch.countDown();
}
});
this.initialized = true;
}
private void awaitForActive() {
Assert.state(this.initialized, () -> "The component has not been initialized: " + this +
".\n Is it declared as a bean?");
IllegalStateException illegalStateException =
new IllegalStateException(
"The DynamoDb table " + this.tableName + " has not been created during " + 60 + " seconds");
@@ -326,6 +333,20 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
}
}
@Override
public String toString() {
return "DynamoDbLockRegistry{" + "tableName='" + this.tableName + '\'' +
", readCapacity=" + this.readCapacity +
", writeCapacity=" + this.writeCapacity +
", partitionKey='" + this.partitionKey + '\'' +
", sortKeyName='" + this.sortKeyName + '\'' +
", sortKey='" + this.sortKey + '\'' +
", refreshPeriod=" + this.refreshPeriod +
", leaseDuration=" + this.leaseDuration +
", heartbeatPeriod=" + this.heartbeatPeriod +
'}';
}
private final class DynamoDbLock implements Lock {
private final ReentrantLock delegate = new ReentrantLock();

View File

@@ -95,6 +95,8 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
private Integer timeToLive;
private volatile boolean initialized;
public DynamoDbMetaDataStore(AmazonDynamoDBAsync dynamoDB) {
this(dynamoDB, DEFAULT_TABLE_NAME);
}
@@ -202,6 +204,8 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
}
});
this.initialized = true;
}
private void updateTimeToLiveIfAny() {
@@ -226,6 +230,8 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
}
private void awaitForActive() {
Assert.state(this.initialized, () -> "The component has not been initialized: " + this +
".\n Is it declared as a bean?");
try {
this.createTableLatch.await(this.createTableRetries * this.createTableDelay, TimeUnit.SECONDS);
}
@@ -359,4 +365,14 @@ public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, Initializ
}
}
@Override
public String toString() {
return "DynamoDbMetaDataStore{" + "table=" + this.table +
", createTableRetries=" + this.createTableRetries +
", createTableDelay=" + this.createTableDelay +
", readCapacity=" + this.readCapacity +
", writeCapacity=" + this.writeCapacity +
", timeToLive=" + this.timeToLive +
'}';
}
}