Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4428a3c
feat(storage): a StorageError::Service variant the engine passes through
LeeroyHannigan Oct 24, 2026
1fd29a0
docs: describe StorageError::Service in the storage design, the manua…
LeeroyHannigan Oct 24, 2026
9e74009
Merge branch 'feat/storage-service-error' into feat/partial-batch-thr…
LeeroyHannigan Oct 24, 2026
f66d2bd
test(engine): build the capacity error through its constructor after …
LeeroyHannigan Oct 24, 2026
4fbf180
feat(engine): serve a batch partially when a backend throttles some e…
LeeroyHannigan Oct 24, 2026
2c87bf8
docs: describe partial batch success under a backend throttle
LeeroyHannigan Oct 24, 2026
6285b81
feat(storage): a StorageError::Service variant the engine passes through
LeeroyHannigan Oct 29, 2026
d994093
docs: describe StorageError::Service in the storage design, the manua…
LeeroyHannigan Oct 29, 2026
32028eb
Merge origin/main into feat/storage-service-error
LeeroyHannigan Nov 5, 2026
2715696
Merge origin/main into feat/storage-service-error
LeeroyHannigan Nov 5, 2026
eca7b86
Merge feat/throttling-reasons into feat/partial-batch-throttle
LeeroyHannigan Nov 17, 2026
542d073
fix: adapt the partial batch throttle code to the merged interfaces
LeeroyHannigan Nov 17, 2026
f5ef794
docs(adr): number the backend-classified client error ADR 0028
LeeroyHannigan Nov 17, 2026
fa7a1e5
fix: record a partial batch throttle only for throttled tables
LeeroyHannigan Nov 17, 2026
3cd1be4
docs: describe the BatchWriteItem throttle answer in the differences …
LeeroyHannigan Nov 17, 2026
a4ab5e8
Merge origin/main into feat/storage-service-error
LeeroyHannigan Nov 17, 2026
4ef952e
style(engine): keep the backup module declarations in rustfmt order
LeeroyHannigan Nov 17, 2026
e63887d
docs: say which BatchWriteItem batches with nothing applied answer 503
LeeroyHannigan Nov 17, 2026
f55f560
Merge origin/main into feat/storage-service-error
LeeroyHannigan Nov 25, 2026
3bcee8d
fix(engine): one Service mapping for every site, which drops a condit…
LeeroyHannigan Nov 25, 2026
5f54a42
fix(engine): a BatchExecuteStatement entry keeps the listed code of i…
LeeroyHannigan Nov 25, 2026
dbeb02a
fix(server): a backend's not-found on the authorization key read is a…
LeeroyHannigan Nov 25, 2026
5d14699
docs: ADR-0028 counts the mapping functions and says what the log tes…
LeeroyHannigan Nov 25, 2026
f5457b6
docs: name every variant whose backend text reaches the client
LeeroyHannigan Nov 25, 2026
87aa815
test(engine): count fault log lines under the global subscriber the b…
LeeroyHannigan Nov 25, 2026
816e456
fix(engine): leave the contended statement entry to #487
LeeroyHannigan Nov 25, 2026
999b71d
docs: name the table-state variants whose backend text reaches the cl…
LeeroyHannigan Nov 25, 2026
ea4efd4
test(engine): keep only the ALL_OLD case in the conditional check test
LeeroyHannigan Nov 25, 2026
87b9a82
Merge origin/feat/throttling-reasons into feat/partial-batch-throttle
LeeroyHannigan Nov 25, 2026
f7a2ada
fix: compile the engine tests against the merged throttling-reasons head
LeeroyHannigan Nov 25, 2026
6287ab4
Merge origin/feat/storage-service-error into feat/partial-batch-throttle
LeeroyHannigan Nov 25, 2026
523e3b4
test(engine): build the throttle errors of the merged service error t…
LeeroyHannigan Nov 25, 2026
0890859
fix: count each backend-throttled batch entry as a throttle event
LeeroyHannigan Nov 25, 2026
15805a7
test(engine): compare the partial batch lists in request order for ev…
LeeroyHannigan Nov 25, 2026
2a0676b
test(server): drive a backend-throttled batch through handle_request …
LeeroyHannigan Nov 25, 2026
c9fae6a
docs: state the backend rule for a throttle on a batch in the storage…
LeeroyHannigan Nov 25, 2026
5e16c28
test(server): name the row type of the partial batch metrics test
LeeroyHannigan Nov 25, 2026
0923371
fix(server): record the throttle events of a batch whose every entry …
LeeroyHannigan Nov 25, 2026
17dab89
refactor(engine): count the throttled entries of a batch only in the …
LeeroyHannigan Nov 25, 2026
cf240c3
test(server): read the throttle metrics of both batch tests through o…
LeeroyHannigan Nov 25, 2026
f9e372a
docs: cite the measured all-throttled batch answers in the comments
LeeroyHannigan Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/core/src/metrics/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum MetricName {
SuccessfulRequestLatency,
SystemErrors,
UserErrors,
/// Throttled request count. Recorded when token bucket rejects a request.
/// Throttled request count. Recorded when the token bucket rejects a request or a backend serves a batch partially.

Copy link
Copy Markdown
Collaborator

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.

ThrottledRequests,
/// Read throttle events. Recorded when a read operation is throttled.
ReadThrottleEvents,
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ tokio = { workspace = true, features = ["test-util"] }
extenddb-storage-sqlite = { path = "../storage-sqlite" }
# Scratch directories that are removed when a test panics.
tempfile = "3"
# A subscriber that counts the fault log lines the error mappings write.
tracing-subscriber = { workspace = true }

# `tests/private_modes.rs` sets umask 0.
[target.'cfg(unix)'.dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,8 @@ mod overrides;
pub mod reconciler;
mod restore;
mod runtime;
#[cfg(test)]
mod service_error_tests;
pub mod store_identity;
pub mod store_maintenance;
pub mod sync;
Expand Down
21 changes: 21 additions & 0 deletions crates/engine/src/backup/service_error_tests.rs
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:?}");
}
}
45 changes: 4 additions & 41 deletions crates/engine/src/backup/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13137,48 +13137,11 @@ async fn a_second_create_over_the_job_bound_is_limit_exceeded() {
#[derive(Clone, Default)]
struct LogLines(Arc<Mutex<Vec<(tracing::Level, String)>>>);

/// The process's global `tracing` subscriber while these tests run:
/// interested in every callsite and enabled for none. `tracing` caches each
/// callsite's interest the first time any thread reaches it; while exactly
/// one scoped subscriber is registered in the process, that cache is
/// computed from the default of the thread that got there first. A test
/// without a subscriber running beside a `LogLines` test on another thread
/// would so cache the job's log callsites as "never", and the `LogLines`
/// test would then see no line from them (tokio-rs/tracing#2743). With this
/// global default the cache reads "sometimes" instead, and each event asks
/// the thread's own default, the `LogLines` where one is set.
struct InterestedInEveryCallsite;

impl tracing::Subscriber for InterestedInEveryCallsite {
fn register_callsite(
&self,
_: &'static tracing::Metadata<'static>,
) -> tracing::subscriber::Interest {
tracing::subscriber::Interest::sometimes()
}
fn enabled(&self, _: &tracing::Metadata<'_>) -> bool {
false
}
fn new_span(&self, _: &tracing::span::Attributes<'_>) -> tracing::span::Id {
tracing::span::Id::from_u64(1)
}
fn record(&self, _: &tracing::span::Id, _: &tracing::span::Record<'_>) {}
fn record_follows_from(&self, _: &tracing::span::Id, _: &tracing::span::Id) {}
fn event(&self, _: &tracing::Event<'_>) {}
fn enter(&self, _: &tracing::span::Id) {}
fn exit(&self, _: &tracing::span::Id) {}
}

impl LogLines {
/// A fresh `LogLines` set as this thread's `tracing` default until the
/// guard drops, with the process's global default installed once.
fn capture() -> (Self, tracing::subscriber::DefaultGuard) {
static GLOBAL: std::sync::Once = std::sync::Once::new();
GLOBAL.call_once(|| {
// Another global may already be set by a test outside this
// module; then its interest rule applies and this one is moot.
let _ = tracing::subscriber::set_global_default(InterestedInEveryCallsite);
});
crate::test_tracing::interest_in_every_callsite();
let lines = Self::default();
let guard = tracing::subscriber::set_default(lines.clone());
(lines, guard)
Expand Down Expand Up @@ -13211,9 +13174,9 @@ struct MessageVisitor<'a>(&'a mut String);

/// A callsite met first by a thread without a scoped subscriber is still
/// seen by a `LogLines` on another thread (the global default's interest
/// rule; the doc of `InterestedInEveryCallsite`). Without that default the
/// callsite's interest is cached as "never" whenever this is the only
/// `LogLines` alive in the process, and nothing is captured.
/// rule; the doc of `test_tracing::InterestedInEveryCallsite`). Without that
/// default the callsite's interest is cached as "never" whenever this is the
/// only `LogLines` alive in the process, and nothing is captured.
#[test]
fn a_callsite_first_met_on_another_thread_still_reaches_the_lines() {
fn shared_callsite(n: u32) {
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/backup_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ pub(crate) fn storage_err_to_dynamo(e: StorageError) -> DynamoDbError {
StorageError::Unsupported(msg) => DynamoDbError::ValidationException(msg),
StorageError::LimitExceeded(msg) => DynamoDbError::LimitExceededException(msg),
StorageError::BackupInUse(msg) => DynamoDbError::BackupInUseException(msg),
StorageError::Service(e) => crate::create_table::service_err_to_dynamo(e),
other => {
tracing::error!(internal_error = %other, "backup storage error");
DynamoDbError::InternalServerError("Internal server error".to_owned())
Expand Down
78 changes: 69 additions & 9 deletions crates/engine/src/batch_get_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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(),
},
);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A table whose every key was throttled is put in Responses as []. The service leaves it out: in 29 of 29 live responses where every key of a drained 1 RCU table came back unprocessed, Responses held only the other table, and the throttled table had no ConsumedCapacity entry. A table whose keys are all missing, rather than throttled, stays as [] on the service (2 of 2), and head already matches that. Inserting the table only when at least one of its keys was not throttled would match; tests/batch_partial.rs:186 asserts the current shape and its comment notes that the service's shape was unmeasured.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 ReturnConsumedCapacity: TOTAL. With both keys of T throttled beside a served U, the body has "Responses":{"T":[],"U":[...]}, and ConsumedCapacity has an entry for U only. With both keys of T missing, it has "Responses":{"T":[],"U":[...]} and "UnprocessedKeys":{}. So the difference from your 29 responses is the "T":[] entry. ConsumedCapacity already leaves T out.

The change for your answer is to insert a table into Responses only when at least one of its keys was not throttled. That is about four lines in handle_batch_get_item, and the Responses assertion of batch_get_one_table_throttled_beside_a_served_table loses T.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment records the difference, but the shape is unchanged: through handle_request this head answers "Responses":{"T":[],"U":[...]} twice, and on the service 24 of 24 responses left a table whose 15 keys all came back unprocessed out of Responses and out of ConsumedCapacity. tests/batch_partial.rs:202-205 asserts the [] entry; leaving the table out, with the test expecting that, would match.

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)),
Expand All @@ -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)?;
Expand All @@ -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()
},
})
Expand Down
Loading
Loading