mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): bill each BatchGetItem key like a GetItem (#6708)
* fix(dynamodb): bill each BatchGetItem key like a GetItem DynamoDB bills each key of a BatchGetItem as a GetItem of the whole item. That is half a unit per 4KB, doubled for a consistent read, with the minimum charged for a key that finds nothing. A projection does not lower it, and a vector attribute counts at its billed size. * fix(dynamodb): size BatchGetItem items only when capacity is requested
This commit is contained in:
1 parent
825564a3d0
commit
0cc4984356
3 files changed
+79
-9
No files matched your search
+47
@@ -643,6 +643,53 @@ class DynamoDbConsumedCapacityIntegrationTest {
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void batchGetItemChargesEachKeyLikeAGetItemOfTheWholeItem() {
|
||||
putItem("""
|
||||
{"pk": {"S": "cc-bg-small"}}
|
||||
""");
|
||||
// 11 for the key and 3 for the pad's name bring it to 8193 bytes, three 4KB reads.
|
||||
putItem("""
|
||||
{"pk": {"S": "cc-bg-big"}, "pad": {"S": "%s"}}
|
||||
""".formatted("x".repeat(8179)));
|
||||
String keys = """
|
||||
[{"pk": {"S": "cc-bg-small"}}, {"pk": {"S": "cc-bg-big"}}, {"pk": {"S": "cc-bg-missing"}}]
|
||||
""";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.BatchGetItem")
|
||||
.contentType(CT)
|
||||
.body("""
|
||||
{
|
||||
"RequestItems": {"%s": {"Keys": %s, "ConsistentRead": true, "ProjectionExpression": "pk"}},
|
||||
"ReturnConsumedCapacity": "TOTAL"
|
||||
}
|
||||
""".formatted(TABLE, keys))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConsumedCapacity", hasSize(1))
|
||||
.body("ConsumedCapacity[0].TableName", equalTo(TABLE))
|
||||
.body("ConsumedCapacity[0].CapacityUnits", equalTo(5.0f))
|
||||
.body("ConsumedCapacity[0].Table", nullValue());
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.BatchGetItem")
|
||||
.contentType(CT)
|
||||
.body("""
|
||||
{"RequestItems": {"%s": {"Keys": %s}}, "ReturnConsumedCapacity": "INDEXES"}
|
||||
""".formatted(TABLE, keys))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConsumedCapacity[0].CapacityUnits", equalTo(2.5f))
|
||||
.body("ConsumedCapacity[0].Table.CapacityUnits", equalTo(2.5f))
|
||||
.body("ConsumedCapacity[0].GlobalSecondaryIndexes", nullValue());
|
||||
}
|
||||
|
||||
private static void putItem(String itemJson) {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
|
||||
+5
@@ -116,6 +116,11 @@ class DynamoDbVectorBilledSizeIntegrationTest {
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("ConsumedCapacity[0].CapacityUnits", equalTo(2.0f));
|
||||
ddb("BatchGetItem", """
|
||||
{"RequestItems":{"%s":{"Keys":[{"pk":{"S":"r6"}}],"ConsistentRead":true}},"ReturnConsumedCapacity":"TOTAL"}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("ConsumedCapacity[0].CapacityUnits", equalTo(1.0f));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user