Skip to content

feat(storage): a StorageError::Service variant the engine passes through - #529

Open
LeeroyHannigan wants to merge 16 commits into
mainfrom
feat/storage-service-error
Open

LeeroyHannigan wants to merge 16 commits into
mainfrom
feat/storage-service-error

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

StorageError gains a Service(DynamoDbError) variant, marked #[error(transparent)]. It carries a client error the backend has already classified. Ten engine functions map a StorageError to a client error. Five end in a catch-all: the backup mapping in backup_requests.rs, the UpdateTable mapping, the streams and TTL mappings, and sanitize_storage_error. The last one maps the metadata and tagging paths. The data path mapping in create_table.rs names every variant. Each of these six gains a Service arm that calls create_table::service_err_to_dynamo. That function returns the error with its variant and message unchanged and without the fault log line. The other four delegate the rest to one of the six. They are the conditional check mapping, the create-backup and restore mappings, and the shard lookup mapping in streams.rs. The server's authorization read delegates to the data path mapping.

The engine keeps one rule for itself, in service_err_to_dynamo: a ConditionalCheckFailedException loses its item, as the engine's own ConditionFailed does on the generic path. Only the conditional check mapping returns the item, to a request that set ReturnValuesOnConditionCheckFailure to ALL_OLD. The message does not change.

In a BatchExecuteStatement response, a statement's entry carries the code that the API Reference lists for the error's class (BatchStatementError). The codes are ProvisionedThroughputExceeded, ThrottlingError, RequestLimitExceeded, ItemCollectionSizeLimitExceeded and InternalServerError. Before this change each of these classes got ValidationError. So did the engine's own internal errors in a batch entry, which now get InternalServerError. TransactionConflictException and ServiceUnavailable keep ValidationError in this PR. #487 gives them the entry measured for a contended statement. The server reads a table's key schema before the IAM decision. That read treats a Service error carrying ResourceNotFoundException as a missing table, as it treats TableNotFound. A caller the IAM decision refuses gets the refusal and not the backend's not-found.

The redaction rule for every other variant is unchanged: an Internal error is logged at error level and reaches the client as the fixed InternalServerError text.

The storage design lists the variant beside the redaction rule. The security model's Error Message Security section names it beside the other variants whose message reaches a client as the backend wrote it. The backend author manual's DataEngine section says when to return it. RFC-0003 section 9.2 adds the obligation to the error fidelity criteria. RFC-0002 states that variants may be added to StorageError in a minor release. ADR-0028 records the decision and the options not taken.

Why

A backend that can classify its own failure into the service's error vocabulary had no way to return that error with its own message. An example is a hosted database that reports a documented capacity or unavailability condition. Every unrecognised StorageError reaches the client as the fixed Internal server error string after an error-level log line. So the client learns nothing about what to do, and the operator's log counts a documented condition among storage faults. Transient is also redacted, and the in-tree queue workers read it as the retry signal, so it is not a substitute.

The doc comment, the design, both manuals and RFC-0003 state the obligation that comes with the variant. The message inside crosses the wire verbatim, so it must be service-shaped text with no driver output, host names, connection strings or credentials. A failure the backend cannot classify stays Internal. The status code and the body shape still come from the DynamoDbError variant through the one serializer. So a backend cannot produce a status or a shape outside the service's catalog through this variant. No in-tree backend returns Service yet.

Testing done

One set of rows (service_error_log_tests::rows) holds five backend-classified errors, each with a message that the engine never writes. Each row holds the body the client gets (error_document). The conditional check row carries an item that the body must not have. The rows run through all ten mappings: seven from the crate root, and the create-backup, restore and shard lookup mappings in their own modules. At the seven, a subscriber also counts error-level log events (tracing-subscriber as a dev-dependency). It counts zero for a Service error and one for Internal("driver text"), whose body must be the fixed text. The subscriber is the thread default under a global one with an interest in every callsite (test_tracing). So a callsite that another thread met first still counts. a_backend_conditional_check_error_keeps_its_item_only_under_all_old covers the ALL_OLD arm. an_error_of_the_item_operation_keeps_the_listed_code_of_its_class has one row per class that batch_code maps. Two key_info_for_authz tests gain rows for a backend's not-found and for a Service fault.

Negative controls ran on a clean committed tree, and I restored each one after:

  • The old Service(e) => e arm put back at any of the five sites that passed the item fails the rows test at that site.
  • The engine's text in place of the backend message fails 4 tests in service_err_to_dynamo and 1 in the ALL_OLD arm.
  • Removing the ALL_OLD arm fails its test.
  • Removing the Service arm in streams.rs fails the rows test with the error logged and redacted.
  • A mutant of each named arm of batch_code fails the code table test, and a mutant of its default arm fails an_error_of_the_item_operation_names_the_batch_table.
  • Without the global subscriber, the test with a callsite that another thread meets first counts 0 events.
  • With the old key_info_for_authz arm, its missing-table test fails with the backend's not-found returned.

Against main, the branch adds 8 tests and removes or renames none of main's (test attributes in git diff a417b2f82: 8 added, 0 removed).

cargo +1.97.0 fmt --all -- --check
cargo +1.97.0 clippy -p extenddb-engine -p extenddb-server --all-targets -- -D warnings
cargo +1.97.0 test -p extenddb-engine --lib                    # 898 passed
cargo +1.97.0 test -p extenddb-server --lib                    # 514 passed at 87aa815462 (see below)
cargo +1.97.0 test --locked -p extenddb-wasm-adapter           # 3 unit tests and the parity corpus
cargo +1.97.0 check --locked -p extenddb-engine --no-default-features --lib
cargo +1.91.1 check --locked -p extenddb-engine -p extenddb-server -p extenddb-storage

Five backup_store tests of the server crate fail on the test host because another user owns its /tmp. They fail the same way on every branch there, and CI runs them. The no-default-features and Rust 1.91.1 checks ran at 87aa815. The later commits remove two match arms and change tests and docs only.

Changes since the 24 November review

Other open PRs:

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace --lib; the integration suites run in CI)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy --all-targets -- -D warnings)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: docs/adr/0028-backend-classified-client-error.md; RFC-0003 section 9.2 and RFC-0002 (release model) updated in this PR.

Breaking changes

None for the wire protocol or any in-tree backend. StorageError gains a variant: a backend crate outside this workspace that matches on it exhaustively needs a catch-all arm, which RFC-0002 now states as the policy for minor releases.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

A backend that can classify its own failure into the service's error
vocabulary (a hosted database reporting a documented unavailability or
capacity condition) had no way to return that error with its own message:
every unrecognised StorageError variant reaches the client as the fixed
"Internal server error" string after an error-level log line.

StorageError::Service(DynamoDbError) carries a fully formed client error.
Nine engine functions map a StorageError to a client error. Six own a
catch-all and gain a Service arm that returns the error with its variant
and message unchanged and without the fault log line: the data path mapping
in create_table.rs, the backup mapping in backup.rs, the UpdateTable
mapping, the streams and TTL mappings, and sanitize_storage_error for the
metadata and tagging paths. The other three (the condition-check variant of
the data path mapping, the create-backup and restore mappings) delegate
their catch-all to one of the six. The server's authorization read
delegates to the data path mapping.

The engine keeps one rule for itself. A ConditionalCheckFailedException
carries its item to the client only when the request set
ReturnValuesOnConditionCheckFailure to ALL_OLD, which the condition-check
mapping applies to a backend's error as it does to the engine's own
ConditionFailed; the generic data path mapping, which has no such value to
read, discards the item as it does for ConditionFailed. The message is kept.

Tests: a Service pass-through test at every one of the nine mappings; at
each of the six with a catch-all, a control that Internal("driver text")
still becomes the fixed string, and a subscriber-based test that counts
error-level log events (none for a Service error, one for an Internal
error). tracing-subscriber becomes a dev-dependency of the engine crate for
that test. The condition-check item rule has a test per
ReturnValuesOnConditionCheckFailure value and one for the generic path.

The doc comment states the backend's obligation: the message crosses the
wire verbatim, so it must be service-shaped text with no driver output, host
names, connection strings or credentials; an unclassified failure stays
Internal, and Transient remains the queue workers' retry signal.
…ls, the RFCs and an ADR

The storage design lists the variant beside the Internal redaction rule and
states the backend's obligation for the message. The security model's error
message section names it as the one path that carries backend-chosen text
to a client, under the same wording rule as the engine's own messages. The
backend author manual's DataEngine section states when to return it and
when a failure stays Internal. RFC-0003 section 9.2 adds the obligation to
the error fidelity criteria. RFC-0002 states that variants may be added to
StorageError in a minor release, so a backend crate matching on it
exhaustively carries a catch-all arm. ADR-0023 records the decision, the
options not taken and the consequences.
@LeeroyHannigan
LeeroyHannigan force-pushed the feat/storage-service-error branch from 1fd29a0 to d994093 Compare October 30, 2026 09:51
crates/engine/src/lib.rs: main added the start_key module to the module
list. This branch added the service_error_log_tests module under
cfg(test) at the same place. The merged file declares both, in name
order.

docs/adr/README.md: main added rows for ADR-0023 (catalog migrations),
ADR-0026 (credential cryptography on AWS-LC) and ADR-0027 (Cassandra
index row version stamps). This branch added its ADR as 0023. Main
owns number 0023, and the open read-options and Cassandra consistency
branches hold 0024 and 0025, so the ADR of this branch moves to 0028.
The file is renamed to 0028-backend-classified-client-error.md, its
title line reads ADR-0028, and the README keeps main's three rows and
lists the new row after them. No other file names the number.
crates/engine/Cargo.toml: main added `futures` to the engine's
dependencies for the backup catalog work. This branch added a
`[dev-dependencies]` section with `tracing-subscriber` for the log
test at the mapping sites. The result lists `futures` with the other
dependencies and keeps the dev-dependency section below it.

Cargo.lock is main's file with `tracing-subscriber` added to the
engine's dependency list, the one entry this branch brings.
crates/engine/Cargo.toml keeps the tokio test-util, extenddb-storage-sqlite, tempfile and libc dev-dependencies from main and the tracing-subscriber dev-dependency from this branch.
crates/engine/src/streams.rs keeps the tests module in streams_tests.rs from main and the Service arm from this branch. The Service pass-through tests from this branch move into streams_tests.rs.
crates/engine/src/update_table.rs keeps the tests module in update_table_tests.rs from main and the Service arm from this branch. The Service pass-through tests from this branch move into update_table_tests.rs.
docs/adr/README.md keeps the ADR-0029 row from main and the ADR-0028 row from this branch.
Main added the runtime, store_identity, store_maintenance and sync modules
to backup.rs. The merge placed this branch's service_error_tests declaration
after them, where rustfmt wants it before store_identity. This commit moves
the declaration. Nothing else changes.
@demohan demohan self-assigned this Nov 24, 2026
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
ADR-0031 records the stored form: the escape of the item documents, the
refusal of U+0000 in a PostgreSQL key, the MongoDB mark, and migration 13.
0031 is the first number that no open PR claims: #529 and #536 add 0028,
and #954 adds 0030.

- differences-from-dynamodb.md lists the refusal of U+0000 in a key on
  PostgreSQL.
- The upgrade manual's entry is now a v1.1.0 entry. It says what an
  operator sees when the data body fails after the catalog body committed,
  and describes the MongoDB mark. The Current Status paragraph about 1.0.0
  and migrations 1 to 12 is as main has it.
- 04-component-storage.md and the escape module's comment no longer say
  that the key columns hold escaped text. The escape's byte order and
  prefix tests go with that claim. map_json checks a key with needs_escape.

@demohan demohan left a comment

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.

No backend in the tree returns StorageError::Service yet, so no request changes on the wire today. The findings below are on the paths a backend reaches once it returns the variant for a capacity condition, as the PR intends. They were measured in process with the engine's Scripted double and compared with the service's answer to the same throttle.

  • The item rule the PR copies holds where it is applied: on PutItem, UpdateItem and DeleteItem, ALL_OLD returns Item and NONE does not, with "The conditional request failed", on the service and on a SQLite build of this head.
  • Throttled TransactWriteItems and ExecuteStatement answer 400 ProvisionedThroughputExceededException on the service, which is the class a Service error passes through on those paths.
  • The nine mapping functions cover every place a StorageError becomes a client error, StorageError stays 56 bytes, and the key-info cache stores no errors.
  • fmt, clippy and the 1.91.1 check are clean. 4,258 tests pass across 13 library binaries, and CI is green on 66 of 66 checks.

I will approve once the items below are done.

crates/engine/src/batch_write_item.rs:421

is_deferrable knows only the engine's own retryable variants. With the double scripted [Ok, Err(Service(ProvisionedThroughputExceededException)), Ok], the batch answers 400 for the whole request after the first write has committed, and the third is never tried, so a client retry repeats the first. Service(ServiceUnavailable) behaves the same way. The service, on a 1 WCU table with 25 puts of 100 KB, answered 200 with 14 and then 13 of 25 in UnprocessedItems, and answered the exception only when nothing applied. batch_get_item.rs:178 and :191 have the same shape. Treating the retryable Service classes as deferrable would match.

crates/engine/src/partiql/common.rs:521

BatchExecuteStatement turns ProvisionedThroughputExceededException, ThrottlingException, RequestLimitExceeded, InternalServerError, TransactionConflictException, ItemCollectionSizeLimitExceededException and ServiceUnavailable from a Service error into {"Code": "ValidationError"}. The service answers 5 throttled INSERTs with Code ProvisionedThroughputExceeded and TableName on each entry. Mapping each class to its BatchStatementErrorCodeEnum code would carry it through, as the PR body says.

Conditional check item outside create_table

The doc comment, ADR-0028, the design doc and the backend manual say a conditional check error carries its item only for ALL_OLD. Only the two create_table.rs mappers apply that. Service(ConditionalCheckFailedException(msg, Some(item))) reaches the client with its item through the mappers in backup.rs:2168, update_table.rs:397, streams.rs:493, ttl.rs:232 and lib.rs:188. One helper that every Service arm calls would apply the rule everywhere.

crates/server/src/request_helpers.rs:143

Optional. A Service error from the key-info read is returned before the cross-account refusal and the IAM decision. A backend that answers Service(ResourceNotFoundException) there would tell a caller without access that the table does not exist. Nothing tests this hand-off.

Comment thread crates/engine/src/create_table.rs Outdated
// is the item on a conditional check error: this generic path discards
// it, as it does for its own ConditionFailed, and
// `storage_err_to_dynamo_with_ccf` returns it when the caller asked.
StorageError::Service(DynamoDbError::ConditionalCheckFailedException(msg, _)) => {

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 tests give the backend error "The conditional request failed", which is the engine's own text, so replacing the backend's message with that text in this arm and in the _with_ccf arm leaves every test passing. A distinct backend message, asserted at the client, would hold the claim.

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.

Fixed in 3bcee8d. The tests now give every mapping one set of rows. Each backend message is text the engine never writes. The conditional check row uses "The stored item does not match the condition." The test compares each row with the body the client gets (error_document) by equality. With your mutant (the engine's "The conditional request failed" in place of the backend message), the old tests passed 21 of 21. Now the mutant in service_err_to_dynamo, the one arm that both mappers reach for a conditional check error, fails 4 tests. The same mutant in the ALL_OLD arm of storage_err_to_dynamo_with_ccf fails a_backend_conditional_check_error_keeps_its_item_only_under_all_old.

## Context

Every storage trait method returns `Result<T, StorageError>`. The engine maps a
`StorageError` to the client-facing `DynamoDbError` at nine functions

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.

Three of the nine functions delegate to another mapper, the create_table one is exhaustive with no catch-all, and streams::shard_lookup_error (streams.rs:222) is a tenth mapper. The log test covers 6 sites.

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.

Corrected in 5d14699. The ADR now counts ten functions. Five end in a catch-all: the backup mapping (now in backup_requests.rs), UpdateTable, streams, TTL and sanitize_storage_error. The data path mapping names every variant, and four delegate: the conditional check, create-backup, restore and shard lookup mappings. The log test runs at the seven mappings the crate root can reach, which include the six that write the fault log line. The three private ones write no log line of their own. Their modules run the same rows through them, and the ADR says so.

}

/// Runs `f` under a fresh subscriber and returns how many error events it logged.
fn error_events_during(f: impl FnOnce()) -> usize {

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. The test failed 7 times in 400 runs at 32 threads, always as "streams::storage_to_dynamo logged 0 fault events", and 0 times in 200 serial runs. Tracing's callsite interest cache, shared with other test threads, is the likely cause, and it would also let the "not logged" half pass without checking. One global subscriber with a per-thread counter avoids it.

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.

Fixed in 87aa815. The cause is the one you name. tracing computes a callsite's interest the first time any thread reaches it. While the counting subscriber is the only registered dispatcher in the process, it computes it from the default of that thread (tracing-core 0.1.36, callsite.rs, Rebuilder::JustOne). A test thread without a subscriber that reaches streams::storage_to_dynamo's log line first caches it as never, and the count reads 0.

The backup log tests on main already install a global subscriber that is interested in every callsite and enabled for none. I moved it to crates/engine/src/test_tracing.rs, and error_events_during installs it before it sets the thread default, so the interest is computed from every live dispatcher. The flake did not reproduce here: 0 failures in 400 runs at 32 threads on the review head merged with main (f55f560). The fix also gave 0 in 400. So I added an_event_from_a_callsite_another_thread_met_first_is_counted: another thread meets a fresh callsite first, and the test counts 1 event. Without the global subscriber it counts 0.

Comment thread docs/manuals/10-security-model.md Outdated
- DynamoDB-fidelity error messages reproduce real DynamoDB exactly (no additional information)
- Internal errors (database connection failures, SQL errors, I/O errors) are logged server-side but return generic messages to clients
- Stack traces, file paths, and SQL text are never exposed to clients
- One path carries backend-chosen text to a client: a backend may return `StorageError::Service(DynamoDbError)` when it has classified its own failure into a service error class, and the engine returns that error with its message unchanged. The message inside is client-facing text the backend author owns; it must not contain driver output, SQL text, paths or connection details, and it is reviewed as client-visible wording under the same rule as the engine's own messages

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. This and 12-extending-extenddb-storage.md:101 call Service the one path for backend text. Validation, IndexesInUse, Unsupported, LimitExceeded and BackupInUse already pass backend text to the client.

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.

Corrected in f5457b6 and 999b71d. Both pages now name the other variants whose message reaches the client as the backend wrote it. They are Validation, NoOpUpdate, Unsupported, IndexesInUse, LimitExceeded, BackupInUse and TransactionConflict, plus the cancellation reasons of TransactionCanceled. The backup and streams mappings also pass on the message of TableNotFound, and the backup mapping passes on that of TableAlreadyExists and TableNotActive. The same rule for the text applies to all of them. NoOpUpdate, TransactionConflict and the three table-state variants are the ones I added to your list. The data path mapping passes their message unchanged too.

crates/engine/src/backup.rs: main moved the backup error mapping
`storage_err_to_dynamo` from backup.rs to backup_requests.rs. The
result keeps main's backup.rs, and the Service arm of this branch moves
into the function in backup_requests.rs. backup.rs keeps this branch's
`service_error_tests` module declaration.

crates/engine/src/service_error_log_tests.rs names the backup mapping
by its new path, crate::backup_requests::storage_err_to_dynamo. The old
path is a private import of backup.rs and does not compile from the
crate root.
…ional check item

A ConditionalCheckFailedException inside StorageError::Service reached
the client with its item through the backup, UpdateTable, streams and
TTL mappings and through sanitize_storage_error. Only the two
create_table mappings applied the ALL_OLD rule that the variant's doc
comment states.

create_table::service_err_to_dynamo now holds the rule, and every
Service arm calls it. It returns the error unchanged, except that a
conditional check error loses its item. storage_err_to_dynamo_with_ccf
keeps one arm of its own, for a request that set
ReturnValuesOnConditionCheckFailure to ALL_OLD.

The tests now give every mapping the same rows: five backend-classified
errors, each with a message that the engine never writes. Each row
holds the body the client gets (error_document), and the CCF row has an
item. The rows run at the seven mappings that the crate root can reach.
The create-backup, restore and shard lookup mappings delegate to these,
and their own modules run the rows through them. This commit removes the
per-site tests that the rows replace. They used the engine's own text
"The conditional request failed" as the backend message. A mapping that
replaced the backend message with that text passed them.
…ts error class

A statement whose item operation failed with a throttle, a conflict or a
fault of the server got Code ValidationError in its BatchExecuteStatement
entry. A Service error from a backend reaches the entry this way, and so
do the engine's own conflict and internal errors.

StatementError::from_error now takes the Code from batch_code. That
function gives the code that the API Reference lists for each class
(BatchStatementError): ProvisionedThroughputExceeded, ThrottlingError,
RequestLimitExceeded, TransactionConflict, ItemCollectionSizeLimitExceeded
and InternalServerError. The list has no code for ServiceUnavailable,
which gets InternalServerError. Every other class keeps ValidationError.
The message and the TableName rule do not change: the entry names the
table when the failure reached the item.

The test has one row per class and compares the whole entry.
… missing table

authorize_request reads the table's key schema before the IAM decision,
which needs it for dynamodb:LeadingKeys. key_info_for_authz passed every
error of that read except TableNotFound to the caller. A backend that
answers StorageError::Service(ResourceNotFoundException) there told a
caller without access that the table does not exist, before the IAM
decision could refuse the caller.

key_info_for_authz now treats that error as it treats TableNotFound: the
key stays absent, the IAM decision runs, and a caller it refuses gets
the refusal. Every other Service error still fails closed with its own
class. Mapped to a missing table, such an error would reach the policy
evaluator with dynamodb:LeadingKeys absent. The doc comment gives that as
the reason for failing closed on transient and connection faults.

The tests gain a row for the backend's not-found and one for a
backend-classified ServiceUnavailable.
…t covers

The ADR said that nine functions map a StorageError to a client error
and that each ends in a catch-all. At this head there are ten. Five end
in a catch-all, and the data path mapping names every variant. Four
delegate to one of those six: the conditional check mapping, the
create-backup and restore mappings and the shard lookup mapping. The ADR
now lists them by file.

The decision section names create_table::service_err_to_dynamo as the
one function every Service arm calls, and the rule it applies to a
conditional check error's item. It also records the two answers that
depend on the error's class. One is the Code of a BatchExecuteStatement
entry. The other is the server's key schema read before the IAM decision,
which treats a backend's ResourceNotFoundException as a missing table.

The rationale section says that the log test runs at the seven mappings
the crate root reaches. The three private mappings write no log line of
their own, and their modules' tests cover them.
The security model and the backend author manual called
StorageError::Service the one path that carries backend-chosen text to
a client. The data path mapping also passes on the message of Validation,
NoOpUpdate, Unsupported, IndexesInUse, LimitExceeded, BackupInUse and
TransactionConflict as the backend wrote it. It passes on the cancellation
reasons of TransactionCanceled too. Both pages now list these variants and
apply the same rule to their text: service-shaped, with no driver output,
host names, connection strings or credentials.

The security model also records that the server reads a table's key
schema before the IAM decision. A backend's ResourceNotFoundException from
that read is a missing table, so a caller the IAM decision refuses gets
the refusal.
…ackup log tests use

The Service log test sets a counting subscriber as the thread's default.
tracing caches each callsite's interest when a thread first reaches it.
While one thread default is the only subscriber in the process, that
cache comes from the default of the thread that got there first. A test
without a subscriber that reaches a mapping's log callsite first caches
it as "never", and the count then reads 0. A count of 0 is also the
expected answer for a Service error, so that half of the test could
pass without checking.

The backup log tests already install a global subscriber that is
interested in every callsite (InterestedInEveryCallsite). This commit
moves it into crates/engine/src/test_tracing.rs, and both the backup
LogLines and error_events_during install it before they set a thread
default. The new test an_event_from_a_callsite_another_thread_met_first_is_counted
makes another thread meet a callsite first, and it counts 0 events
without the global subscriber.
#487 gives TransactionConflictException and ServiceUnavailable the
BatchExecuteStatement entry measured for a contended statement: Code
TransactionConflict, the message "Transaction is ongoing for the item" and no
TableName. batch_code gave the first TransactionConflict with the error's own
message and TableName, and the second InternalServerError. Once both PRs
merge, #487's arm matches first and those two arms are dead.

batch_code drops the two arms, so they keep ValidationError until #487
merges. The test drops their rows and the ValidationException row, which
main's an_error_of_the_item_operation_names_the_batch_table covers.
…ient

The backup mapping passes on the backend's message of TableNotFound,
TableAlreadyExists and TableNotActive, and the streams mapping that of
TableNotFound. The security model and the storage extension manual now list
them with the other variants.

ADR-0028 says which BatchExecuteStatement classes keep their listed code,
now that #487 maps the contended entry. It also says that the shard lookup
mapping checks the shard id length before it delegates, and names no
variant of its own.
The None case repeated service_error_log_tests, whose sites() runs the
conditional check mapping without ALL_OLD over the conditional check row.
The comment on sites() now says that this mapping also maps the engine's own
ConditionFailed.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

crates/engine/src/batch_write_item.rs:421: I reproduced it on this branch with the Scripted double. [Ok, Service(ProvisionedThroughputExceededException), Ok] answers 400 after the first write applied and never tries the third, and ServiceUnavailable answers 503 the same way. The API Reference puts these operations in UnprocessedItems: "If any requested operations fail because the table's provisioned throughput is exceeded or an internal processing failure occurs, the failed operations are returned in the UnprocessedItems response parameter" (https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html). The exception comes only when nothing could be processed. I left the deferral in #536, which merges this branch. #536 (4fbf180, and eca7b86 for its merge with #532) defers a throttle Service error in both handlers. When every entry was throttled, it answers the first throttle error. The tests are in crates/engine/tests/batch_partial.rs: batch_write_partial_echoes_entries_and_charges_applied_only, batch_write_every_entry_throttled_fails_with_the_throttle_error, batch_get_partial_echoes_request_fields_and_charges_served_only and batch_get_every_key_throttled_fails_with_the_throttle_error. That code tells a throttle by #532's is_throttle, which is not on main. The all-throttled answer needs #536's per-table throttle count. With the arm alone, a BatchWriteItem in which every write was throttled would answer 503 ServiceUnavailable. Main gives that answer when no write of a batch applied, and the API Reference names ProvisionedThroughputExceededException or ThrottlingException for that case. BatchGetItem defers no error on main. A copy of the arm would change the same lines #536 changes. #536 defers the three throttle classes, for a write the backend did not commit. Service(ServiceUnavailable) still fails the batch there, because the engine defers only an error that leaves the write unapplied.

crates/engine/src/partiql/common.rs:521: fixed in 5f54a42 and 816e456 for five of the classes. StatementError::from_error takes the code from batch_code, which gives each of them the code that the API Reference lists (https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchStatementError.html): ProvisionedThroughputExceeded, ThrottlingError, RequestLimitExceeded, ItemCollectionSizeLimitExceeded and InternalServerError. The TableName rule is main's: an entry names the table when the failure reached the item, so a throttled INSERT carries TableName. an_error_of_the_item_operation_keeps_the_listed_code_of_its_class has one row per class, and it fails with the old catch-all. The engine's own internal errors get InternalServerError as well. #487 (eaa83a5) gives the other two classes, TransactionConflictException and ServiceUnavailable, the entry you measured on 25 November for a contended statement. That entry has Code TransactionConflict, Message "Transaction is ongoing for the item", and no TableName. This PR leaves those two classes to #487, so that the two PRs do not give them different entries. Until #487 merges, they keep ValidationError.

Conditional check item outside create_table: fixed in 3bcee8d. create_table::service_err_to_dynamo holds the rule, and every Service arm calls it: the data path mapping, the backup mapping (now in backup_requests.rs), UpdateTable, streams, TTL and sanitize_storage_error. Only storage_err_to_dynamo_with_ccf returns the item, under ALL_OLD. One set of rows, with an item on the conditional check row, runs through all ten mappings. The test compares each result with the body the client gets. With any one of the five old arms put back, that test fails.

crates/server/src/request_helpers.rs:143: fixed in dbeb02a. The key schema read has to come before the IAM decision, which reads dynamodb:LeadingKeys from it, so I did not move it. key_info_for_authz now treats a Service error carrying ResourceNotFoundException as it treats TableNotFound. The key stays absent and the IAM decision runs. A caller it refuses gets the refusal, and an authorized caller gets the engine's not-found. Every other Service class still fails closed with its own class, as the transient and connection faults do. Mapped to a missing table, it would reach the policy evaluator with LeadingKeys absent, which a ForAllValues condition satisfies vacuously. key_info_for_authz_missing_table_returns_none has the backend's not-found as a second row. key_info_for_authz_lookup_error_fails_closed checks that a backend-classified ServiceUnavailable keeps its class. With the old arm, the first fails with the backend's not-found returned.

@demohan demohan left a comment

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.

Items 3 and 4 are resolved at ea4efd4, and five BatchExecuteStatement classes carry their codes; the batch deferral is in #536 and two classes are in #487, both still open.

  • Every backend-classified error now goes through one mapping that drops the item, and only the conditional check under ALL_OLD keeps it, as the service does on PutItem, UpdateItem and DeleteItem with ALL_OLD and NONE on SQLite and PostgreSQL. A backend's not-found on the authorization key read counts as a missing table and every other class fails closed: on 12 rows a refused caller gets AccessDenied and an authorized one ResourceNotFound, at this head and on main, on both backends. Putting back the old arm at each site, or treating every Service error as a missing table, fails a test, and the log test, the ADR's count of ten mappers and the two pages match the code. Head answers as main on 46 rows, twice, and engine (898) and server (519) tests pass.
  • Throttled INSERTs answer ProvisionedThroughputExceeded and a hot key ThrottlingError, each with TableName, as on the service. TransactionConflictException and ServiceUnavailable still answer ValidationError; on the service a contended statement answers TransactionConflict, "Transaction is ongoing for the item", with TableName, in 4 samples.
  • is_deferrable and batch_get_item.rs are unchanged: on the engine's test double a backend throttle in the middle of a batch fails the request with 400 after the first write committed, and the third write is not tried. On the service, 25 large puts on a throttled table answered 200 with 11 and 13 left in UnprocessedItems, and a BatchGetItem of 30 keys at 1 RCU answered 200 with 8 in UnprocessedKeys.

I will approve once the batch defers a throttled request as the service does, here or by #536 landing with this change, and the two classes answer as the service does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants