mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): apply DynamoDB GlobalTable Replicas (#4134)
AWS::DynamoDB::GlobalTable was provisioned as a plain table and its Replicas property was ignored. Now the declared replica regions are reconciled onto the table via the same applyReplicaUpdates the UpdateTable ReplicaUpdates path uses. - Create adds every declared replica region; update diffs declared vs tracked, adding new regions and removing dropped ones so an edited Replicas list converges. - The deployment region is served by the table itself and the service rejects a replica there, so it is filtered out rather than tracked.
This commit is contained in:
1 parent
32856bfee0
commit
f9e96f3d22
3 files changed
+111
-2
No files matched your search
+11
-1
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
@@ -58,7 +59,7 @@ class CloudFormationDynamoDbGlobalTableIntegrationTest {
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"BillingMode": "PAY_PER_REQUEST",
|
||||
"Replicas": [{"Region": "us-east-1"}]
|
||||
"Replicas": [{"Region": "us-east-1"}, {"Region": "us-west-2"}]
|
||||
}
|
||||
},
|
||||
"RefParam": {
|
||||
@@ -88,6 +89,15 @@ class CloudFormationDynamoDbGlobalTableIntegrationTest {
|
||||
assertTrue(tableArn != null && tableArn.startsWith("arn:aws:dynamodb:"), "TableArn: " + tableArn);
|
||||
assertFalse(tableId == null || tableId.isBlank(), "DescribeTable reported no TableId");
|
||||
|
||||
// The Replicas property is applied: the non-local region is tracked and surfaced by
|
||||
// DescribeTable. Whether the deployment region itself appears in Replicas is deliberately not
|
||||
// asserted here: on AWS a global table lists its stack region as a replica too, and reporting
|
||||
// that is a DescribeTable follow-up (the reconcile must keep filtering the local region, since
|
||||
// the UpdateTable ReplicaUpdates API rejects adding it).
|
||||
List<String> replicaRegions = described.getList("Table.Replicas.RegionName");
|
||||
assertTrue(replicaRegions != null && replicaRegions.contains("us-west-2"),
|
||||
"DescribeTable Replicas did not report us-west-2: " + replicaRegions);
|
||||
|
||||
assertEquals(tableName, parameterValue("/gt-v2/" + suffix + "/ref"));
|
||||
assertEquals(tableArn, parameterValue("/gt-v2/" + suffix + "/arn"));
|
||||
assertEquals(tableId, parameterValue("/gt-v2/" + suffix + "/table-id"));
|
||||
|
||||
+50
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -110,6 +111,7 @@ class DynamoDbCfnProvisionerTest {
|
||||
void globalTableIsProvisionedAsATableAndPublishesTableId() throws Exception {
|
||||
when(dynamoDb.createTable(anyString(), anyList(), anyList(), any(), any(), anyList(), anyList(), anyString()))
|
||||
.thenReturn(table(false));
|
||||
when(dynamoDb.describeTable(TABLE_NAME, "us-east-1")).thenReturn(table(false));
|
||||
StackResource r = resource("AWS::DynamoDB::GlobalTable", "Orders");
|
||||
|
||||
provisioner.provision(r, props("{\"TableName\":\"orders\"}"), ctx());
|
||||
@@ -119,6 +121,54 @@ class DynamoDbCfnProvisionerTest {
|
||||
assertEquals(TABLE_NAME, r.getPhysicalId());
|
||||
assertEquals(Set.of("Arn", "TableId"), r.getAttributes().keySet());
|
||||
assertEquals(TABLE_ID, r.getAttributes().get("TableId"));
|
||||
// No Replicas declared and none tracked, so nothing to reconcile.
|
||||
verify(dynamoDb, never()).applyReplicaUpdates(anyString(), anyList(), anyList(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalTableCreateAddsDeclaredReplicaRegionsFilteringTheDeploymentRegion() throws Exception {
|
||||
when(dynamoDb.createTable(anyString(), anyList(), anyList(), any(), any(), anyList(), anyList(), anyString()))
|
||||
.thenReturn(table(false));
|
||||
when(dynamoDb.describeTable(TABLE_NAME, "us-east-1")).thenReturn(table(false));
|
||||
StackResource r = resource("AWS::DynamoDB::GlobalTable", "Orders");
|
||||
|
||||
provisioner.provision(r, props("{\"TableName\":\"orders\",\"Replicas\":["
|
||||
+ "{\"Region\":\"us-east-1\"},{\"Region\":\"us-west-2\"},{\"Region\":\"eu-west-1\"}]}"), ctx());
|
||||
|
||||
// us-east-1 is the deployment region served by the table itself, so it is filtered out.
|
||||
verify(dynamoDb).applyReplicaUpdates(TABLE_NAME, List.of("us-west-2", "eu-west-1"), List.of(), "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalTableUpdateAddsNewReplicasAndRemovesDroppedOnes() throws Exception {
|
||||
when(dynamoDb.createTable(anyString(), anyList(), anyList(), any(), any(), anyList(), anyList(), anyString()))
|
||||
.thenReturn(table(false));
|
||||
TableDefinition existing = table(false);
|
||||
existing.setReplicaRegions(new ArrayList<>(List.of("us-west-2", "eu-west-1")));
|
||||
when(dynamoDb.describeTable(TABLE_NAME, "us-east-1")).thenReturn(existing);
|
||||
StackResource r = resource("AWS::DynamoDB::GlobalTable", "Orders");
|
||||
r.setPhysicalId(TABLE_NAME);
|
||||
|
||||
provisioner.provision(r, props("{\"TableName\":\"orders\",\"Replicas\":["
|
||||
+ "{\"Region\":\"us-west-2\"},{\"Region\":\"ap-south-1\"}]}"), updateCtx(TABLE_NAME));
|
||||
|
||||
verify(dynamoDb).applyReplicaUpdates(TABLE_NAME, List.of("ap-south-1"), List.of("eu-west-1"), "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalTableWithUnchangedReplicasSkipsTheReplicaUpdate() throws Exception {
|
||||
when(dynamoDb.createTable(anyString(), anyList(), anyList(), any(), any(), anyList(), anyList(), anyString()))
|
||||
.thenReturn(table(false));
|
||||
TableDefinition existing = table(false);
|
||||
existing.setReplicaRegions(new ArrayList<>(List.of("us-west-2")));
|
||||
when(dynamoDb.describeTable(TABLE_NAME, "us-east-1")).thenReturn(existing);
|
||||
StackResource r = resource("AWS::DynamoDB::GlobalTable", "Orders");
|
||||
r.setPhysicalId(TABLE_NAME);
|
||||
|
||||
provisioner.provision(r, props("{\"TableName\":\"orders\",\"Replicas\":[{\"Region\":\"us-west-2\"}]}"),
|
||||
updateCtx(TABLE_NAME));
|
||||
|
||||
verify(dynamoDb, never()).applyReplicaUpdates(anyString(), anyList(), anyList(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user