mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): check WarmThroughput last on CreateTable (#9077)
This commit is contained in:
1 parent
7c4ed46223
commit
4713120f3e
3 files changed
+57
-10
No files matched your search
@@ -523,6 +523,21 @@ public class DynamoDbService {
|
||||
List<VectorIndexCreate> vectorIndexes,
|
||||
String billingMode,
|
||||
String region) {
|
||||
return createTable(tableName, keySchema, attributeDefinitions, readCapacity, writeCapacity,
|
||||
gsis, lsis, vectorIndexes, billingMode, region, () -> { });
|
||||
}
|
||||
|
||||
/** @param lastCheck runs after every other check, just before the table is stored */
|
||||
TableDefinition createTable(String tableName,
|
||||
List<KeySchemaElement> keySchema,
|
||||
List<AttributeDefinition> attributeDefinitions,
|
||||
Long readCapacity, Long writeCapacity,
|
||||
List<GlobalSecondaryIndex> gsis,
|
||||
List<LocalSecondaryIndex> lsis,
|
||||
List<VectorIndexCreate> vectorIndexes,
|
||||
String billingMode,
|
||||
String region,
|
||||
Runnable lastCheck) {
|
||||
// Enforce at the service boundary: CreateTable persists its input as the
|
||||
// canonical table name and derives TableArn from it. An ARN-form input
|
||||
// would produce ARN-on-ARN TableArn values. Handler-layer rejection alone
|
||||
@@ -705,6 +720,8 @@ public class DynamoDbService {
|
||||
table.setVectorIndexes(created);
|
||||
}
|
||||
|
||||
lastCheck.run();
|
||||
|
||||
synchronized (capacityLock) {
|
||||
if (!"PAY_PER_REQUEST".equals(billingMode)) {
|
||||
DynamoDbCapacityQuotas.requireNewTableWithinQuotas(table, reservedCapacity(region), region);
|
||||
|
||||
@@ -144,14 +144,13 @@ public class NativeDynamoDbTableService {
|
||||
+ "disabled, UpdateViewType should not be specified", 400);
|
||||
}
|
||||
|
||||
requireCreateWarmThroughput(request, "PAY_PER_REQUEST".equals(billingMode));
|
||||
|
||||
TableDefinition table = dynamoDbService.createTable(tableName, request.keySchema(),
|
||||
request.attributeDefinitions(),
|
||||
throughput != null ? throughput.readCapacityUnits() : null,
|
||||
throughput != null ? throughput.writeCapacityUnits() : null,
|
||||
request.globalSecondaryIndexes(), request.localSecondaryIndexes(), request.vectorIndexes(),
|
||||
billingMode, region);
|
||||
billingMode, region,
|
||||
() -> requireCreateWarmThroughput(request, "PAY_PER_REQUEST".equals(billingMode)));
|
||||
table.setTableStatus(initialStatus);
|
||||
|
||||
table.setDeletionProtectionEnabled(Boolean.TRUE.equals(settings.deletionProtectionEnabled()));
|
||||
@@ -459,6 +458,9 @@ public class NativeDynamoDbTableService {
|
||||
GlobalSecondaryIndex gsi = table.findGsi(update.indexName()).orElseThrow();
|
||||
Throughput gsiThroughput = update.provisionedThroughput();
|
||||
if (gsiThroughput != null) {
|
||||
// A capacity cut leaves the index's warm throughput where it was.
|
||||
gsi.setWarmReadUnitsPerSecond(table.gsiWarmReadUnits(gsi));
|
||||
gsi.setWarmWriteUnitsPerSecond(table.gsiWarmWriteUnits(gsi));
|
||||
if (gsiThroughput.readCapacityUnits() != null) {
|
||||
gsi.getProvisionedThroughput().setReadCapacityUnits(gsiThroughput.readCapacityUnits());
|
||||
}
|
||||
@@ -681,7 +683,11 @@ public class NativeDynamoDbTableService {
|
||||
onDemand, provisioned != null ? provisioned.readCapacityUnits() : null,
|
||||
provisioned != null ? provisioned.writeCapacityUnits() : null);
|
||||
}
|
||||
for (GlobalSecondaryIndex gsi : request.globalSecondaryIndexes()) {
|
||||
requireNewIndexWarmThroughput(request.globalSecondaryIndexes(), onDemand);
|
||||
}
|
||||
|
||||
private static void requireNewIndexWarmThroughput(List<GlobalSecondaryIndex> indexes, boolean onDemand) {
|
||||
for (GlobalSecondaryIndex gsi : indexes) {
|
||||
requireCreateWarmThroughput("index " + gsi.getIndexName(), gsi.getWarmReadUnitsPerSecond(),
|
||||
gsi.getWarmWriteUnitsPerSecond(), onDemand, gsi.getProvisionedThroughput().getReadCapacityUnits(),
|
||||
gsi.getProvisionedThroughput().getWriteCapacityUnits());
|
||||
@@ -734,12 +740,7 @@ public class NativeDynamoDbTableService {
|
||||
warm.writeUnitsPerSecond(), table.gsiWarmReadUnits(gsi), table.gsiWarmWriteUnits(gsi),
|
||||
CURRENT_WARM_REASON, CURRENT_WARM_REASON);
|
||||
}
|
||||
boolean onDemand = "PAY_PER_REQUEST".equals(table.getBillingMode());
|
||||
for (GlobalSecondaryIndex gsi : request.gsiCreates()) {
|
||||
requireCreateWarmThroughput("index " + gsi.getIndexName(), gsi.getWarmReadUnitsPerSecond(),
|
||||
gsi.getWarmWriteUnitsPerSecond(), onDemand, gsi.getProvisionedThroughput().getReadCapacityUnits(),
|
||||
gsi.getProvisionedThroughput().getWriteCapacityUnits());
|
||||
}
|
||||
requireNewIndexWarmThroughput(request.gsiCreates(), "PAY_PER_REQUEST".equals(table.getBillingMode()));
|
||||
}
|
||||
|
||||
private static void requireWarmThroughputAtLeast(String target, Long read, Long write, long minimumRead,
|
||||
|
||||
@@ -1109,6 +1109,35 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
assertTrue(orderEx.getMessage().contains("for table"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTableKeepsIndexWarmThroughputThroughACapacityCut() throws Exception {
|
||||
createWarmTable("warm-index-cut", false, null, null);
|
||||
String capacityUpdate = """
|
||||
{"TableName": "warm-index-cut", "GlobalSecondaryIndexUpdates": [{"Update": {"IndexName": "gsi1",
|
||||
"ProvisionedThroughput": {"ReadCapacityUnits": %d, "WriteCapacityUnits": %d}}}]}
|
||||
""";
|
||||
updateWarm(capacityUpdate.formatted(20, 30));
|
||||
updateWarm(capacityUpdate.formatted(7, 8));
|
||||
|
||||
assertWarm(warmThroughputOf(describedGsi("warm-index-cut", "gsi1")), 20, 30, "ACTIVE");
|
||||
AwsException ex = warmFailure("UpdateTable", json("""
|
||||
{"TableName": "warm-index-cut", "GlobalSecondaryIndexUpdates": [
|
||||
{"Update": {"IndexName": "gsi1", "WarmThroughput": {"ReadUnitsPerSecond": 19}}}]}
|
||||
"""));
|
||||
assertEquals("One or more parameter values were invalid: Requested ReadUnitsPerSecond for WarmThroughput "
|
||||
+ "for index gsi1 is lower than " + CURRENT_REASON, ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableReportsAnExistingTableBeforeAnyWarmThroughputCheck() throws Exception {
|
||||
createWarmTable("warm-create-order", true, null, null);
|
||||
|
||||
AwsException ex = warmFailure("CreateTable",
|
||||
warmTableRequest("warm-create-order", true, "{\"ReadUnitsPerSecond\": 1}", null));
|
||||
|
||||
assertEquals("ResourceInUseException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTableRejectsEmptyTableWarmThroughputWithInternalFailure() throws Exception {
|
||||
createWarmTable("warm-empty-table", true, null, null);
|
||||
|
||||
Reference in new issue
Block a user