Skip to content

Commit

Permalink
fixed method for deleting global tables with replicas in AWSDynamoUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Nov 19, 2021
1 parent cdbe8c9 commit 069b2d0
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import software.amazon.awssdk.services.applicationautoscaling.model.PolicyType;
import software.amazon.awssdk.services.applicationautoscaling.model.ScalableDimension;
import software.amazon.awssdk.services.applicationautoscaling.model.ServiceNamespace;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
Expand Down Expand Up @@ -350,22 +351,26 @@ public static boolean deleteTable(String appid) {
try {
String table = getTableNameForAppid(appid);
if (!getReplicaRegions().isEmpty() && !App.isRoot(appid)) {
getReplicaRegions().stream().filter(r -> !r.equals(AWS_REGION)).forEach(region -> {
try {
logger.info("Removing replica from global table '{}' in region {}...", table, region);
getClient().updateGlobalTable(b -> b.globalTableName(table).replicaUpdates(ReplicaUpdate.
builder().delete(d -> d.regionName(region)).build()));
waitForActive(table, AWS_REGION);
logger.info("Deleting replica table in region {} for table {}", region, table);
getClient(region).deleteTable(b -> b.tableName(table));
} catch (Exception ex) {
logger.error(null, ex);
}
List<ReplicaUpdate> replicaUpdates = new LinkedList<>();
getReplicaRegions().stream().forEach(region -> {
logger.info("Removing replica from global table '{}' in region {}...", table, region);
replicaUpdates.add(ReplicaUpdate.builder().delete(d -> d.regionName(region)).build());
});
waitForActive(table, AWS_REGION);
try {
// this only removes the replicas for each region - it DOES NOT delete the actual replica tables
getClient().updateGlobalTable(b -> b.globalTableName(table).replicaUpdates(replicaUpdates));
getReplicaRegions().stream().forEach(region -> {
DynamoDbAsyncClient asyncdb = DynamoDbAsyncClient.builder().region(Region.of(region)).build();
asyncdb.deleteTable(b -> b.tableName(table));
logger.info("Deleted DynamoDB table '{}' in region {}.", table, region);
});
} catch (Exception ex) {
logger.error(null, ex);
}
} else {
getClient().deleteTable(b -> b.tableName(table));
logger.info("Deleted DynamoDB table '{}'.", table);
}
getClient().deleteTable(b -> b.tableName(table));
logger.info("Deleted DynamoDB table '{}'.", table);
} catch (Exception e) {
logger.error(null, e);
return false;
Expand Down

0 comments on commit 069b2d0

Please sign in to comment.