mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): report correct WarmThroughput for tables (#7648)
Table-level WarmThroughput was hardcoded to 0/0. Now reports provisioned capacity for provisioned tables and 12000/4000 for on-demand tables, matching AWS. Tracks max capacity history on updates. Omits WarmThroughput from CreateTable responses as AWS does. Closes #7114 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
6ef4ad536b
commit
282b53cacc
5 files changed
+211
-27
No files matched your search
@@ -38,6 +38,7 @@ import io.floci.aws.services.dynamodb.model.IncrementalExportSpecification;
|
||||
import io.floci.aws.services.dynamodb.model.KeySchemaElement;
|
||||
import io.floci.aws.services.dynamodb.model.LocalSecondaryIndex;
|
||||
import io.floci.aws.services.dynamodb.model.PointInTimeChange;
|
||||
import io.floci.aws.services.dynamodb.model.ProvisionedThroughput;
|
||||
import io.floci.aws.services.dynamodb.model.StreamDescription;
|
||||
import io.floci.aws.services.dynamodb.model.TableBackup;
|
||||
import io.floci.aws.services.dynamodb.model.TableDefinition;
|
||||
@@ -648,6 +649,11 @@ public class DynamoDbService {
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(readCapacity);
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(writeCapacity);
|
||||
}
|
||||
// Track warm throughput: on-demand uses fixed values, provisioned uses the capacity.
|
||||
ProvisionedThroughput tp = readCapacity != null && writeCapacity != null
|
||||
? new ProvisionedThroughput(readCapacity, writeCapacity) : null;
|
||||
table.setWarmReadUnitsPerSecond(TableDefinition.defaultWarmReadUnits(billingMode, tp));
|
||||
table.setWarmWriteUnitsPerSecond(TableDefinition.defaultWarmWriteUnits(billingMode, tp));
|
||||
|
||||
if (gsis != null && !gsis.isEmpty()) {
|
||||
for (GlobalSecondaryIndex gsi : gsis) {
|
||||
@@ -2610,9 +2616,32 @@ public class DynamoDbService {
|
||||
|
||||
if (readCapacity != null) {
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(readCapacity);
|
||||
if (readCapacity > table.getWarmReadUnitsPerSecond()) {
|
||||
table.setWarmReadUnitsPerSecond(readCapacity);
|
||||
}
|
||||
}
|
||||
if (writeCapacity != null) {
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(writeCapacity);
|
||||
if (writeCapacity > table.getWarmWriteUnitsPerSecond()) {
|
||||
table.setWarmWriteUnitsPerSecond(writeCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle billing mode switch.
|
||||
if (billingMode != null && !billingMode.equals(table.getBillingMode())) {
|
||||
table.setBillingMode(billingMode);
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(0L);
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(0L);
|
||||
long wru = TableDefinition.defaultWarmReadUnits("PAY_PER_REQUEST", null);
|
||||
long wwu = TableDefinition.defaultWarmWriteUnits("PAY_PER_REQUEST", null);
|
||||
if (wru > table.getWarmReadUnitsPerSecond()) {
|
||||
table.setWarmReadUnitsPerSecond(wru);
|
||||
}
|
||||
if (wwu > table.getWarmWriteUnitsPerSecond()) {
|
||||
table.setWarmWriteUnitsPerSecond(wwu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String indexName : gsiDeletes) {
|
||||
@@ -4141,7 +4170,7 @@ public class DynamoDbService {
|
||||
arr.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setValueAtPath(ObjectNode item, String path, JsonNode value, JsonNode exprAttrNames) {
|
||||
List<Object> tokens = parsePath(path, exprAttrNames);
|
||||
if (tokens.isEmpty()) return;
|
||||
|
||||
@@ -197,8 +197,10 @@ public class NativeDynamoDbJsonHandler {
|
||||
throwValidationErrors(createTableViolations(request));
|
||||
TableDefinition table = createTableFromSpec(request, "", region, "ACTIVE");
|
||||
|
||||
ObjectNode tableNode = tableToNode(table);
|
||||
tableNode.remove("WarmThroughput");
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("TableDescription", tableToNode(table));
|
||||
response.set("TableDescription", tableNode);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@@ -3924,8 +3926,8 @@ public class NativeDynamoDbJsonHandler {
|
||||
|
||||
ObjectNode warmThroughput = objectMapper.createObjectNode();
|
||||
warmThroughput.put("Status", "ACTIVE");
|
||||
warmThroughput.put("ReadUnitsPerSecond", 0);
|
||||
warmThroughput.put("WriteUnitsPerSecond", 0);
|
||||
warmThroughput.put("ReadUnitsPerSecond", table.getWarmReadUnitsPerSecond());
|
||||
warmThroughput.put("WriteUnitsPerSecond", table.getWarmWriteUnitsPerSecond());
|
||||
node.set("WarmThroughput", warmThroughput);
|
||||
|
||||
// Global-table replicas. In a single-process emulator every region is served by this same
|
||||
|
||||
@@ -466,14 +466,6 @@ public class NativeDynamoDbTableService {
|
||||
table.setDeletionProtectionEnabled(settings.deletionProtectionEnabled());
|
||||
}
|
||||
|
||||
String billingMode = settings.billingMode();
|
||||
if (billingMode != null) {
|
||||
table.setBillingMode(billingMode);
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(0L);
|
||||
table.getProvisionedThroughput().setWriteCapacityUnits(0L);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.tableClass() != null) {
|
||||
table.setTableClass(settings.tableClass());
|
||||
|
||||
@@ -28,6 +28,8 @@ public class TableDefinition {
|
||||
private long itemCount;
|
||||
private long tableSizeBytes;
|
||||
private ProvisionedThroughput provisionedThroughput;
|
||||
private long warmReadUnitsPerSecond;
|
||||
private long warmWriteUnitsPerSecond;
|
||||
private String tableArn;
|
||||
private Map<String, String> tags;
|
||||
private List<GlobalSecondaryIndex> globalSecondaryIndexes;
|
||||
@@ -95,6 +97,8 @@ public class TableDefinition {
|
||||
this.tableArn = AwsArnUtils.Arn.of("dynamodb", region, accountId, "table/" + tableName).toString();
|
||||
this.tableId = UUID.randomUUID().toString();
|
||||
this.provisionedThroughput = new ProvisionedThroughput(5, 5);
|
||||
this.warmReadUnitsPerSecond = 5;
|
||||
this.warmWriteUnitsPerSecond = 5;
|
||||
this.tags = new HashMap<>();
|
||||
this.globalSecondaryIndexes = new ArrayList<>();
|
||||
this.localSecondaryIndexes = new ArrayList<>();
|
||||
@@ -104,6 +108,24 @@ public class TableDefinition {
|
||||
this.replicaRegions = new ArrayList<>();
|
||||
}
|
||||
|
||||
/** Baseline warm read units for a table given its billing mode and provisioned capacity. */
|
||||
public static long defaultWarmReadUnits(String billingMode, ProvisionedThroughput pt) {
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
return 12000;
|
||||
}
|
||||
long rcu = pt != null ? pt.getReadCapacityUnits() : 0;
|
||||
return rcu > 0 ? rcu : 5;
|
||||
}
|
||||
|
||||
/** Baseline warm write units for a table given its billing mode and provisioned capacity. */
|
||||
public static long defaultWarmWriteUnits(String billingMode, ProvisionedThroughput pt) {
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
return 4000;
|
||||
}
|
||||
long wcu = pt != null ? pt.getWriteCapacityUnits() : 0;
|
||||
return wcu > 0 ? wcu : 5;
|
||||
}
|
||||
|
||||
public String getTableName() { return tableName; }
|
||||
public void setTableName(String tableName) { this.tableName = tableName; }
|
||||
|
||||
@@ -128,6 +150,22 @@ public class TableDefinition {
|
||||
public ProvisionedThroughput getProvisionedThroughput() { return provisionedThroughput; }
|
||||
public void setProvisionedThroughput(ProvisionedThroughput provisionedThroughput) { this.provisionedThroughput = provisionedThroughput; }
|
||||
|
||||
public long getWarmReadUnitsPerSecond() {
|
||||
if (warmReadUnitsPerSecond <= 0) {
|
||||
return defaultWarmReadUnits(billingMode, provisionedThroughput);
|
||||
}
|
||||
return warmReadUnitsPerSecond;
|
||||
}
|
||||
public void setWarmReadUnitsPerSecond(long v) { this.warmReadUnitsPerSecond = v; }
|
||||
|
||||
public long getWarmWriteUnitsPerSecond() {
|
||||
if (warmWriteUnitsPerSecond <= 0) {
|
||||
return defaultWarmWriteUnits(billingMode, provisionedThroughput);
|
||||
}
|
||||
return warmWriteUnitsPerSecond;
|
||||
}
|
||||
public void setWarmWriteUnitsPerSecond(long v) { this.warmWriteUnitsPerSecond = v; }
|
||||
|
||||
public String getTableArn() { return tableArn; }
|
||||
public void setTableArn(String tableArn) { this.tableArn = tableArn; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user