Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
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
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
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: 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
59 changes: 57 additions & 2 deletions crates/engine/src/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ pub fn storage_err_to_dynamo(e: extenddb_storage::error::StorageError) -> Dynamo
tracing::error!(internal_error = %msg, "storage internal error");
DynamoDbError::InternalServerError("Internal server error".to_owned())
}
StorageError::Service(e) => service_err_to_dynamo(e),
}
}

/// The client error inside a [`StorageError::Service`], as every mapping in
/// the engine returns it. The backend already classified the failure and
/// chose the message, so the error keeps its variant and message, and it is
/// not logged as a storage fault. The one rule the engine keeps for itself is
/// the item on a conditional check error: it is dropped here, as the generic
/// path drops the item of the engine's own `ConditionFailed`, and only
/// [`storage_err_to_dynamo_with_ccf`] returns it, to a request that set
/// `ReturnValuesOnConditionCheckFailure` to `ALL_OLD`.
///
/// [`StorageError::Service`]: extenddb_storage::error::StorageError::Service
pub(crate) fn service_err_to_dynamo(e: DynamoDbError) -> DynamoDbError {
match e {
DynamoDbError::ConditionalCheckFailedException(msg, _) => {
DynamoDbError::ConditionalCheckFailedException(msg, None)
}
other => other,
}
}

Expand All @@ -253,16 +273,26 @@ pub(crate) fn storage_err_to_dynamo_with_ccf(
return_item,
)
}
// A backend-classified conditional check error keeps its message, and
// its item crosses only when the caller asked for ALL_OLD, which only
// this mapper can see. Without ALL_OLD the generic mapping drops it.
StorageError::Service(DynamoDbError::ConditionalCheckFailedException(msg, item))
if ccf == ReturnValuesOnConditionCheckFailure::AllOld =>
{
DynamoDbError::ConditionalCheckFailedException(msg, item)
}
other => storage_err_to_dynamo(other),
}
}

#[cfg(test)]
mod storage_error_mapping_tests {
use extenddb_core::error::DynamoDbError;
use extenddb_core::error::{DynamoDbError, error_document};
use extenddb_core::types::{AttributeValue, Item, ReturnValuesOnConditionCheckFailure};
use extenddb_storage::error::StorageError;
use serde_json::json;

use super::storage_err_to_dynamo;
use super::{storage_err_to_dynamo, storage_err_to_dynamo_with_ccf};

/// A snapshot the backend discarded is retryable, like a transient error.
#[test]
Expand All @@ -273,4 +303,29 @@ mod storage_error_mapping_tests {
"{err:?}"
);
}

/// Only this mapper reads `ReturnValuesOnConditionCheckFailure`: a
/// backend's conditional check error reaches a request that set it to
/// `ALL_OLD` with its own message and its item. The mappings that drop
/// the item, this one without `ALL_OLD` among them, are checked in
/// `service_error_log_tests`.
#[test]
fn a_backend_conditional_check_error_keeps_its_item_only_under_all_old() {
let message = "The stored item does not match the condition.";
let mut item = Item::new();
item.insert("pk".to_owned(), AttributeValue::S("stored".to_owned()));
let error = DynamoDbError::ConditionalCheckFailedException(message.to_owned(), Some(item));
let got = storage_err_to_dynamo_with_ccf(
StorageError::Service(error),
ReturnValuesOnConditionCheckFailure::AllOld,
);
assert_eq!(
error_document(&got),
json!({
"__type": "com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException",
"message": message,
"Item": {"pk": {"S": "stored"}},
})
);
}
}
34 changes: 34 additions & 0 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ mod read_helpers;
mod request_limits;
mod scan;
mod search_vectors;
#[cfg(test)]
mod service_error_log_tests;
mod start_key;
pub mod stream_capture;
mod streams;
mod streams_iterator_params;
mod tagging;
#[cfg(test)]
mod test_tracing;
mod transact_get_items;
mod transact_write_helpers;
mod transact_write_items;
Expand Down Expand Up @@ -200,7 +204,13 @@ pub(crate) fn serialize_output(
///
/// Use this for storage calls that don't go through `storage_err_to_dynamo`
/// (e.g., tagging, metadata operations that return `StorageError` directly).
/// A [`StorageError::Service`] error is the backend's own classification of
/// the failure and reaches the client through
/// [`create_table::service_err_to_dynamo`], without the fault log line.
pub(crate) fn sanitize_storage_error(e: extenddb_storage::error::StorageError) -> DynamoDbError {
if let extenddb_storage::error::StorageError::Service(e) = e {
return create_table::service_err_to_dynamo(e);
}
tracing::error!(internal_error = %e, "storage internal error");
DynamoDbError::InternalServerError("Internal server error".to_owned())
}
Expand Down Expand Up @@ -640,3 +650,27 @@ pub async fn dispatch(
_ => Err(DynamoDbError::UnknownOperationException(String::new())),
}
}

#[cfg(test)]
mod sanitize_storage_error_tests {
use super::sanitize_storage_error;
use extenddb_core::error::DynamoDbError;
use extenddb_storage::error::StorageError;

// Control: every other variant is still redacted behind the fixed string.
#[test]
fn other_variants_are_redacted() {
for e in [
StorageError::Internal("driver text".to_owned()),
StorageError::Connection("host unreachable".to_owned()),
StorageError::Transient("pool timeout".to_owned()),
] {
match sanitize_storage_error(e) {
DynamoDbError::InternalServerError(msg) => {
assert_eq!(msg, "Internal server error");
}
other => panic!("expected InternalServerError, got {other:?}"),
}
}
}
}
27 changes: 24 additions & 3 deletions crates/engine/src/partiql/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,10 @@ impl StatementError {
include_table_name: true,
item: None,
},
// Everything else a well-formed statement can raise per-statement is
// a validation error (partial key, bad value, key-type mismatch).
// Every other error keeps its class as the code the API Reference
// lists for a batch statement's error (see `batch_code`).
other => Self {
code: "ValidationError",
code: batch_code(other),
message: other.message().to_owned(),
include_table_name: false,
item: None,
Expand Down Expand Up @@ -573,5 +573,26 @@ impl StatementError {
}
}

/// The `Code` of a batch statement's error for an error that
/// [`StatementError::from_error`] has no arm of its own for: the code the API
/// Reference lists for its class (`BatchStatementError`), so a throttle or a
/// fault that a backend reports for one statement keeps its class. Any other
/// class is a validation error: the failures a well-formed statement raises
/// on its own (partial key, bad value, key-type mismatch).
fn batch_code(err: &DynamoDbError) -> &'static str {
match err {
DynamoDbError::ProvisionedThroughputExceededException { .. } => {
"ProvisionedThroughputExceeded"
}
DynamoDbError::ThrottlingException { .. } => "ThrottlingError",
DynamoDbError::RequestLimitExceeded { .. } => "RequestLimitExceeded",
DynamoDbError::ItemCollectionSizeLimitExceededException { .. } => {
"ItemCollectionSizeLimitExceeded"
}
DynamoDbError::InternalServerError { .. } => "InternalServerError",
_ => "ValidationError",
}
}

#[cfg(test)]
mod tests;
48 changes: 48 additions & 0 deletions crates/engine/src/partiql/common/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,54 @@ fn an_error_of_the_item_operation_names_the_batch_table() {
}
}

/// An error of the item operation keeps its class as the code the API
/// Reference lists for a batch statement's error (BatchStatementError), with
/// its message and the statement's table: a backend throttle or fault on one
/// statement is not a validation error.
#[test]
fn an_error_of_the_item_operation_keeps_the_listed_code_of_its_class() {
for (error, code) in [
(
DynamoDbError::ProvisionedThroughputExceededException(
"The level of configured provisioned throughput for the table was exceeded."
.to_owned(),
),
"ProvisionedThroughputExceeded",
),
(
DynamoDbError::ThrottlingException(
"Throughput exceeds the current capacity.".to_owned(),
),
"ThrottlingError",
),
(
DynamoDbError::RequestLimitExceeded("Throughput exceeds the account quota.".to_owned()),
"RequestLimitExceeded",
),
(
DynamoDbError::ItemCollectionSizeLimitExceededException(
"Item collection size limit exceeded.".to_owned(),
),
"ItemCollectionSizeLimitExceeded",
),
(
DynamoDbError::InternalServerError(
"The server encountered an internal error.".to_owned(),
),
"InternalServerError",
),
] {
assert_eq!(
StatementError::from_item_error(&error).into_entry(Some("t")),
json!({
"Error": { "Code": code, "Message": error.message() },
"TableName": "t",
}),
"{error:?}"
);
}
}

#[test]
fn a_conditional_failure_without_an_item_has_none() {
let err = DynamoDbError::ConditionalCheckFailedException(
Expand Down
Loading
Loading