fix(dynamodb): report WarmThroughput on each global secondary index (#7120)

This commit is contained in:
Aymen JAMAAOUI authored and GitHub committed 2026-10-31 14:59:30 -04:00
1 parent f74744dc5f
commit 2eb75ee686
3 files changed
+115 -1

No files matched your search

@@ -69,6 +69,9 @@ public class NativeDynamoDbJsonHandler {
private static final int MAX_BACKUP_ARN_LENGTH = 1024;
private static final Instant MAX_TIME_RANGE_BOUND = Instant.ofEpochMilli(99_999_999_999_999L);
private static final int MAX_RECOVERY_PERIOD_DAYS = 35;
// The warm throughput a new on-demand table or index starts with.
private static final long ON_DEMAND_WARM_READ_UNITS = 12000;
private static final long ON_DEMAND_WARM_WRITE_UNITS = 4000;
private final DynamoDbService dynamoDbService;
private final NativeDynamoDbTableService tableService;
@@ -2324,7 +2327,8 @@ public class NativeDynamoDbJsonHandler {
}
if (described.has("GlobalSecondaryIndexes")) {
for (JsonNode gsi : described.get("GlobalSecondaryIndexes")) {
((ObjectNode) gsi).remove(List.of("IndexArn", "IndexStatus", "IndexSizeBytes", "ItemCount"));
((ObjectNode) gsi).remove(
List.of("IndexArn", "IndexStatus", "IndexSizeBytes", "ItemCount", "WarmThroughput"));
((ObjectNode) gsi.get("ProvisionedThroughput")).remove("NumberOfDecreasesToday");
}
features.set("GlobalSecondaryIndexes", described.get("GlobalSecondaryIndexes"));
@@ -3299,6 +3303,7 @@ public class NativeDynamoDbJsonHandler {
}
gsiNode.set("OnDemandThroughput", gsiOdt);
}
gsiNode.set("WarmThroughput", gsiWarmThroughput(table, gsi));
gsiArray.add(gsiNode);
}
@@ -3359,6 +3364,21 @@ public class NativeDynamoDbJsonHandler {
return node;
}
/**
* AWS reports a provisioned index's warm throughput as its provisioned capacity, and an on-demand
* one's as the values a new on-demand index starts with. An index is ACTIVE as soon as it exists here.
*/
private ObjectNode gsiWarmThroughput(TableDefinition table, GlobalSecondaryIndex gsi) {
boolean onDemand = "PAY_PER_REQUEST".equals(table.getBillingMode());
ObjectNode warmThroughput = objectMapper.createObjectNode();
warmThroughput.put("ReadUnitsPerSecond",
onDemand ? ON_DEMAND_WARM_READ_UNITS : gsi.getProvisionedThroughput().getReadCapacityUnits());
warmThroughput.put("WriteUnitsPerSecond",
onDemand ? ON_DEMAND_WARM_WRITE_UNITS : gsi.getProvisionedThroughput().getWriteCapacityUnits());
warmThroughput.put("Status", "ACTIVE");
return warmThroughput;
}
/**
* Renders a VectorIndexDescription. ItemCount and IndexSizeBytes are always 0. AWS refreshes
* those two roughly every six hours, so a freshly built index reports 0 for both there too.
@@ -77,6 +77,8 @@ class DynamoDbBackupIntegrationTest {
equalTo("gsi1"))
.body("BackupDescription.SourceTableFeatureDetails.GlobalSecondaryIndexes[0]",
not(hasKey("IndexStatus")))
.body("BackupDescription.SourceTableFeatureDetails.GlobalSecondaryIndexes[0]",
not(hasKey("WarmThroughput")))
.body("BackupDescription.SourceTableFeatureDetails.LocalSecondaryIndexes[0].IndexName",
equalTo("lsi1"))
.body("BackupDescription.SourceTableFeatureDetails.LocalSecondaryIndexes[0]",
@@ -590,6 +590,98 @@ class NativeDynamoDbJsonHandlerTest {
assertEquals(30, describedGsi.get("ProvisionedThroughput").get("WriteCapacityUnits").asInt());
}
@Test
void describeTableReportsProvisionedGsiCapacityAsWarmThroughput() throws Exception {
createProvisionedTableWithGsi("gsi-warm-provisioned", "eu-west-1");
JsonNode warmThroughput = warmThroughputOf(describedGsi("gsi-warm-provisioned", "TitleIndex"));
assertEquals(5, warmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(5, warmThroughput.get("WriteUnitsPerSecond").asLong());
assertEquals("ACTIVE", warmThroughput.get("Status").asText());
}
@Test
void describeTableReportsOnDemandGsiWarmThroughput() throws Exception {
handler.handle("CreateTable", json("""
{
"TableName": "gsi-warm-on-demand",
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
"AttributeDefinitions": [
{"AttributeName": "pk", "AttributeType": "S"},
{"AttributeName": "g", "AttributeType": "S"}
],
"BillingMode": "PAY_PER_REQUEST",
"GlobalSecondaryIndexes": [{
"IndexName": "gsi1",
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"}
}]
}
"""), "eu-west-1");
JsonNode warmThroughput = warmThroughputOf(describedGsi("gsi-warm-on-demand", "gsi1"));
assertEquals(12000, warmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(4000, warmThroughput.get("WriteUnitsPerSecond").asLong());
assertEquals("ACTIVE", warmThroughput.get("Status").asText());
}
@Test
void updateTableCreatedGsiReportsItsWarmThroughput() throws Exception {
handler.handle("CreateTable", json("""
{
"TableName": "gsi-warm-created",
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
"BillingMode": "PROVISIONED",
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}
}
"""), "eu-west-1");
Response response = handler.handle("UpdateTable", json("""
{
"TableName": "gsi-warm-created",
"AttributeDefinitions": [{"AttributeName": "g", "AttributeType": "S"}],
"GlobalSecondaryIndexUpdates": [{"Create": {
"IndexName": "gsi1",
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"},
"ProvisionedThroughput": {"ReadCapacityUnits": 2, "WriteCapacityUnits": 3}
}}]
}
"""), "eu-west-1");
assertEquals(200, response.getStatus());
JsonNode body = mapper.convertValue(response.getEntity(), JsonNode.class);
JsonNode updatedWarmThroughput = warmThroughputOf(
body.get("TableDescription").get("GlobalSecondaryIndexes").get(0));
assertEquals(2, updatedWarmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(3, updatedWarmThroughput.get("WriteUnitsPerSecond").asLong());
JsonNode describedWarmThroughput = warmThroughputOf(describedGsi("gsi-warm-created", "gsi1"));
assertEquals(2, describedWarmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(3, describedWarmThroughput.get("WriteUnitsPerSecond").asLong());
assertEquals("ACTIVE", describedWarmThroughput.get("Status").asText());
}
private JsonNode describedGsi(String tableName, String indexName) throws Exception {
Response response = handler.handle("DescribeTable",
mapper.createObjectNode().put("TableName", tableName), "eu-west-1");
assertEquals(200, response.getStatus());
JsonNode body = mapper.convertValue(response.getEntity(), JsonNode.class);
for (JsonNode gsi : body.get("Table").get("GlobalSecondaryIndexes")) {
if (indexName.equals(gsi.get("IndexName").asText())) {
return gsi;
}
}
throw new AssertionError("DescribeTable lists no GSI named " + indexName);
}
private static JsonNode warmThroughputOf(JsonNode gsi) {
assertTrue(gsi.has("WarmThroughput"), "The GSI description must report its WarmThroughput");
return gsi.get("WarmThroughput");
}
@Test
void updateTableRejectsConflictingDeleteAndUpdateWithoutRemovingGsi() throws Exception {
createProvisionedTableWithGsi("gsi-conflicting-update-table", "eu-west-1");