Repository navigation
feat(engine): serve a batch partially when a backend throttles some entries #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/throttling-reasons
Are you sure you want to change the base?
Changes from all commits
4428a3c
1fd29a0
9e74009
f66d2bd
4fbf180
2c87bf8
6285b81
d994093
32028eb
2715696
eca7b86
542d073
f5ef794
fa7a1e5
3cd1be4
a4ab5e8
4ef952e
e63887d
f55f560
3bcee8d
5f54a42
dbeb02a
5d14699
f5457b6
87aa815
816e456
999b71d
ea4efd4
87b9a82
f7a2ada
6287ab4
523e3b4
0890859
15805a7
2a0676b
c9fae6a
5e16c28
0923371
17dab89
cf240c3
f9e372a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright 2026 ExtendDB contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| //! The create-backup and restore mappings name a few table-state variants and | ||
| //! delegate the rest to `backup_requests::storage_err_to_dynamo`, so a | ||
| //! backend-classified error reaches the client through them as it does through | ||
| //! that mapping (`service_error_log_tests`). | ||
|
|
||
| use extenddb_core::error::error_document; | ||
| use extenddb_storage::error::StorageError; | ||
|
|
||
| use super::{create_backup_storage_err_to_dynamo, restore_storage_err_to_dynamo}; | ||
|
|
||
| #[test] | ||
| fn a_service_error_reaches_the_client_as_classified_through_create_backup_and_restore() { | ||
| for (error, body) in crate::service_error_log_tests::rows() { | ||
| let create = create_backup_storage_err_to_dynamo(StorageError::Service(error.clone()), "t"); | ||
| assert_eq!(error_document(&create), body, "CreateBackup: {error:?}"); | ||
| let restore = restore_storage_err_to_dynamo(StorageError::Service(error.clone())); | ||
| assert_eq!(error_document(&restore), body, "Restore: {error:?}"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,17 @@ | |
|
|
||
| //! `BatchGetItem` operation handler. | ||
|
|
||
| use std::collections::{HashMap, HashSet}; | ||
| use std::collections::{BTreeMap, HashMap, HashSet}; | ||
|
|
||
| use serde_json::Value; | ||
|
|
||
| use extenddb_core::error::DynamoDbError; | ||
| use extenddb_core::expression::Projection; | ||
| use extenddb_core::types::{BatchGetItemInput, BatchGetItemOutput, Item, item_size_bytes}; | ||
| use extenddb_core::types::{ | ||
| BatchGetItemInput, BatchGetItemOutput, Item, KeysAndAttributes, item_size_bytes, | ||
| }; | ||
| use extenddb_core::validation::{validate_batch_key_only, validate_key_sizes}; | ||
| use extenddb_storage::error::StorageError; | ||
|
|
||
| use crate::OperationContext; | ||
| use crate::capacity_helpers; | ||
|
|
@@ -45,6 +48,8 @@ pub async fn handle_batch_get_item( | |
| .map(|(table_name, ka)| (table_name.as_str(), Some(ka.keys.len()))) | ||
| .collect(); | ||
| request_limits::check_batch_counts("BatchGetItem", &counts)?; | ||
| // The partial-success boundary below compares against the whole request. | ||
| let total_keys: usize = counts.iter().map(|(_, n)| n.unwrap_or(0)).sum(); | ||
|
|
||
| // Reject mixing expression and non-expression parameters anywhere in the | ||
| // request. The check is request-wide: ProjectionExpression on one table and | ||
|
|
@@ -166,6 +171,15 @@ pub async fn handle_batch_get_item( | |
| } | ||
|
|
||
| let mut responses: HashMap<String, Vec<Item>> = HashMap::new(); | ||
| // Keys a backend throttled, grouped by table. The service serves the rest | ||
| // of the batch and returns these under `UnprocessedKeys` with the table's | ||
| // request fields echoed (measured 2026-10-21: 2 partial responses, 16 of | ||
| // 25 keys served, `ConsistentRead` and `ProjectionExpression` echoed); | ||
| // when every key was throttled the call fails with the throttle error | ||
| // instead (API Reference; documented, not reached in the sample). | ||
| let mut unprocessed_keys: HashMap<String, KeysAndAttributes> = HashMap::new(); | ||
| let mut first_throttle: Option<DynamoDbError> = None; | ||
| let mut throttled_tables: BTreeMap<String, u32> = BTreeMap::new(); | ||
| let mut total_rcu: f64 = 0.0; | ||
| let mut total_pre_proj_bytes: usize = 0; | ||
| let mut returned_count: u64 = 0; | ||
|
|
@@ -180,16 +194,29 @@ pub async fn handle_batch_get_item( | |
| let projection = table_projections.get(table_name).and_then(Option::as_ref); | ||
|
|
||
| let mut table_items: Vec<Item> = Vec::new(); | ||
| let mut table_unprocessed: Vec<Item> = Vec::new(); | ||
| for key in &ka.keys { | ||
| validate_batch_key_only(key, &key_info.key_schema, &key_info.attribute_definitions)?; | ||
| validate_key_sizes(key, &key_info.key_schema, &ctx.limits)?; | ||
|
|
||
| if let Some(item) = ctx | ||
| .storage | ||
| .get_item(&key_info, key) | ||
| .await | ||
| .map_err(storage_err_to_dynamo)? | ||
| { | ||
| let fetched = match ctx.storage.get_item(&key_info, key).await { | ||
| Ok(fetched) => fetched, | ||
| // A throttled key is not an error for the batch: it is reported | ||
| // back unprocessed and the loop continues. Every other storage | ||
| // error still fails the request. | ||
| Err(StorageError::Service(e)) if e.is_throttle() => { | ||
| table_unprocessed.push(key.clone()); | ||
| *throttled_tables | ||
| .entry(key_info.table_name.clone()) | ||
| .or_default() += 1; | ||
| if first_throttle.is_none() { | ||
| first_throttle = Some(e); | ||
| } | ||
| continue; | ||
| } | ||
| Err(e) => return Err(storage_err_to_dynamo(e)), | ||
| }; | ||
| if let Some(item) = fetched { | ||
| let size = item_size_bytes(&item); | ||
| let strongly_consistent = ka.consistent_read == Some(true); | ||
| let item_rcu = capacity_helpers::read_capacity_units(size, strongly_consistent); | ||
|
|
@@ -205,9 +232,41 @@ pub async fn handle_batch_get_item( | |
| table_items.push(item); | ||
| } | ||
| } | ||
| if !table_unprocessed.is_empty() { | ||
| // The request's KeysAndAttributes with Keys reduced to the | ||
| // unprocessed ones, in request order (the service's order is not | ||
| // measured: its served and unprocessed lists came back in neither | ||
| // request nor sorted order); the other fields are echoed as sent | ||
| // (ConsistentRead and ProjectionExpression measured, | ||
| // ExpressionAttributeNames and AttributesToGet documented). | ||
| unprocessed_keys.insert( | ||
| table_name.clone(), | ||
| KeysAndAttributes { | ||
| keys: table_unprocessed, | ||
| consistent_read: ka.consistent_read, | ||
| projection_expression: ka.projection_expression.clone(), | ||
| expression_attribute_names: ka.expression_attribute_names.clone(), | ||
| attributes_to_get: ka.attributes_to_get.clone(), | ||
| }, | ||
| ); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A table whose every key was throttled is put in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not changed this yet. I measure a service shape on a table of my own before the engine copies it. This one needs a drained provisioned table, which I have not set up. I ran each shape twice at the merged head, against the test double with The change for your answer is to insert a table into |
||
| responses.insert(table_name.clone(), table_items); | ||
| } | ||
|
|
||
| // No key of any table could be read: the call fails with the first | ||
| // throttle error (API Reference; measured 2026-11-24, 24 of 24 | ||
| // all-throttled batches answered 400). "First" is the request map's | ||
| // iteration order, so with tables of different billing modes either error | ||
| // class can come out; the service's choice for that case is not measured | ||
| // (one table per request in the sample). A table whose every key was | ||
| // throttled beside a served table keeps an empty `Responses` list; the | ||
| // service left it out in 29 of 29 measured responses. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment records the difference, but the shape is unchanged: through |
||
| if let Some(e) = first_throttle | ||
| && throttled_tables.values().sum::<u32>() as usize == total_keys | ||
| { | ||
| return Err(e); | ||
| } | ||
|
|
||
| let consumed_capacity = capacity_helpers::batch_read_capacity( | ||
| input.return_consumed_capacity, | ||
| per_table_rcu.iter().map(|(t, cu)| (t.as_str(), *cu)), | ||
|
|
@@ -218,7 +277,7 @@ pub async fn handle_batch_get_item( | |
|
|
||
| let output = BatchGetItemOutput { | ||
| responses, | ||
| unprocessed_keys: HashMap::new(), | ||
| unprocessed_keys, | ||
| consumed_capacity, | ||
| }; | ||
| let body = serialize_output(&output)?; | ||
|
|
@@ -228,6 +287,7 @@ pub async fn handle_batch_get_item( | |
| read_capacity_units: rcu, | ||
| returned_item_count: returned_count, | ||
| returned_bytes: total_pre_proj_bytes as u64, | ||
| throttled_tables, | ||
| ..Default::default() | ||
| }, | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional. Since 0890859 this doc no longer holds: a partly served batch records no
ThrottledRequests.