Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ffb8f0e
fix: answer TTL and tag calls during a table's DELETING window as the…
LeeroyHannigan Oct 30, 2026
705f000
Merge fix/505-deleting-window-answers into fix/551-552-deleting-windo…
LeeroyHannigan Nov 14, 2026
c880756
refactor(engine): read the DELETING status once and keep one copy of …
LeeroyHannigan Nov 14, 2026
8ad7b93
Merge fix/505-deleting-window-answers into fix/551-552-deleting-windo…
LeeroyHannigan Nov 14, 2026
c5985c5
build(storage-mongodb): declare the engine dev-dependency by path
LeeroyHannigan Nov 14, 2026
191684b
Merge fix/505-deleting-window-answers into fix/551-552-deleting-windo…
LeeroyHannigan Nov 24, 2026
8015c6d
test(storage-mongodb): move the TTL and tag window tests to their own…
LeeroyHannigan Nov 24, 2026
9adeb6d
refactor(core): build the DescribeTimeToLive state refusal from one m…
LeeroyHannigan Nov 24, 2026
9a35e65
test: put the window's UpdateTimeToLive rows in one data table per ba…
LeeroyHannigan Nov 24, 2026
34e328a
test: retry DeleteTable after a tag write in the window tests
LeeroyHannigan Nov 24, 2026
a75c9cd
fix(engine): serve only the latest stream ARN of a DELETING table, an…
LeeroyHannigan Nov 24, 2026
9fb240d
fix(engine): read the table status after the UpdateTimeToLive write
LeeroyHannigan Nov 24, 2026
02a7a25
fix(storage-mongodb): refuse a TTL index build on a DELETING document…
LeeroyHannigan Nov 24, 2026
ec4c09c
docs: describe the TTL and tag calls in a table's DELETING window
LeeroyHannigan Nov 24, 2026
e4465ec
test(engine): drop the direct unit test of arn_storage_error
LeeroyHannigan Nov 24, 2026
fd12d6c
Merge fix/505-deleting-window-answers into fix/551-552-deleting-windo…
LeeroyHannigan Nov 25, 2026
992cca4
Merge fix/505-deleting-window-answers into fix/551-552-deleting-windo…
LeeroyHannigan Dec 3, 2026
7fd3aad
fix(engine): drop the TTL index of a disable whose status read failed
LeeroyHannigan Dec 3, 2026
1910108
docs: the UpdateTimeToLive phase of the DELETING window
LeeroyHannigan Dec 3, 2026
8831eaa
Merge fix/505-deleting-window-answers into fix/551-552-deleting-windo…
LeeroyHannigan Dec 3, 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.

14 changes: 14 additions & 0 deletions crates/core/src/error/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ pub enum ErrorMessageKey {
/// `UpdateTable` during the window, and 2026-11-30 for a second
/// `DeleteTable`.
TableBeingDeleted,
/// `DescribeTimeToLive` refused because the table is in the state
/// `args[0]`, `DELETING` or `CREATING`. Measured on the service for
/// `DELETING` on 2026-10-25 on three tables, every call inside the window,
/// and for `CREATING` on 2026-10-26, five calls, each while `DescribeTable`
/// read `CREATING`. `UpdateTimeToLive` has no such refusal: it runs its
/// ordinary rules.
DescribeTtlInState,
MissingKeySchema,
KeySchemaTooMany,
KeySchemaFirstNotHash,
Expand Down Expand Up @@ -107,6 +114,13 @@ pub fn error_message(key: ErrorMessageKey, args: &[&str]) -> String {
args[0]
)
}
ErrorMessageKey::DescribeTtlInState => {
format!(
"Cannot describe time to live while table is in {0} state: \
Current table state is {0}",
args[0]
)
}
ErrorMessageKey::MissingKeySchema => {
"1 validation error detected: Value null at 'keySchema' failed to satisfy constraint: \
Member must not be null"
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod start_key;
pub mod stream_capture;
mod streams;
mod streams_iterator_params;
mod table_lifecycle;
mod tagging;
mod transact_get_items;
mod transact_write_helpers;
Expand Down
48 changes: 48 additions & 0 deletions crates/engine/src/table_lifecycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2026 ExtendDB contributors
// SPDX-License-Identifier: Apache-2.0

//! The catalog's lifecycle status for a table, for handlers that decide on it.
//!
//! `TableKeyInfo` carries no status, and the key-info read reports a `DELETING`
//! row as not found on MongoDB and Cassandra, so a handler that has to tell a
//! `DELETING` table from a missing one cannot get the answer from it. The
//! description carries the status on every backend, and the table's latest
//! stream ARN, which the tag path checks a stream ARN against in the window.
//! The callers (the two TTL handlers and the tag path) are control-plane
//! calls, so the read is not on a data-plane path.
//!
//! The read is `describe_table`: four catalog queries on PostgreSQL and SQLite
//! (`tables`, `indexes`, `vector_indexes`, `table_restores`) and two on MongoDB
//! and Cassandra (`tables`, `indexes`). `DescribeTimeToLive`,
//! `UpdateTimeToLive`, `TagResource`, `UntagResource` and `ListTagsOfResource`
//! each make it once per call. `DescribeTimeToLive` on an `ACTIVE` table sends
//! five and three, where it sent one. `UpdateTimeToLive` sends the four or two
//! more, after its write, and on a `DELETING` table it skips the TTL read after
//! the write and the index statements.

use extenddb_core::types::{DescribeTableInput, TableDescription};
use extenddb_storage::error::StorageError;

use crate::OperationContext;

/// Read `table_name`'s catalog description, for its `table_status` and its
/// `latest_stream_arn`.
///
/// # Errors
///
/// Returns [`StorageError::TableNotFound`] when no catalog row exists, and
/// whatever the backend raised otherwise. The caller maps it, so each operation
/// keeps the message it already answers for a missing table.
pub(crate) async fn read_table_description(
table_name: &str,
ctx: &OperationContext,
) -> Result<TableDescription, StorageError> {
ctx.storage
.describe_table(
&ctx.account_id,
DescribeTableInput {
table_name: table_name.to_owned(),
},
)
.await
}
102 changes: 72 additions & 30 deletions crates/engine/src/tagging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

use extenddb_core::error::DynamoDbError;
use extenddb_core::types::{
ListTagsOfResourceInput, ListTagsOfResourceOutput, TagResourceInput, UntagResourceInput,
ListTagsOfResourceInput, ListTagsOfResourceOutput, TableStatus, TagResourceInput,
UntagResourceInput,
};
use serde_json::Value;

Expand Down Expand Up @@ -92,32 +93,54 @@ enum WhileDeleting {
Refuse,
}

/// Refuse a tag change on a table that is being deleted. The service answers
/// `TagResource` and `UntagResource` on a `DELETING` table with
/// Answer a tag operation on a table that is being deleted. The service
/// answers `TagResource` and `UntagResource` on a `DELETING` table's ARN with
/// `ResourceInUseException` and the sentence `DeleteTable` and `UpdateTable`
/// give in that window, and serves `ListTagsOfResource` (measured
/// 2026-11-03). The key info carries no status, and the data plane reads a
/// `DELETING` table as found on PostgreSQL and SQLite, so the status is read
/// with `describe_table`. Any other answer from it is left to the existence
/// check that follows.
/// 2026-11-03). These are its answers for the first 0.6 to 2.3 s after
/// `DeleteTable` returns. After that it answers all three with
/// `ResourceNotFoundException` while `DescribeTable` still reads `DELETING`
/// (measured 2026-11-20, five runs). ExtendDB keeps the first answers for the
/// whole window. On the table's stream ARN both writes are served in the same
/// window (measured 2026-10-26), so `resource` decides: a stream's tags belong
/// to the stream, which stays describable after its table is deleted. That
/// holds for the table's latest stream only. Any other label is
/// `ResourceNotFoundException`, the service's answer for a label that names no
/// stream (measured 2026-11-20 on a `DELETING` table). The key info carries no
/// status, and the data plane reads a `DELETING` table as found on PostgreSQL
/// and SQLite, so the status is read from the catalog
/// (`table_lifecycle::read_table_description`). A failed read answers as the
/// key-info read below would: a missing table names the ARN, and any other
/// error is a fault.
///
/// Returns whether the table is `DELETING` and the request is served: the
/// key-info read reports a `DELETING` row as not found on MongoDB and
/// Cassandra, so such a request skips it and every backend answers the window
/// the same way.
async fn refuse_while_deleting(
table_name: &str,
arn: &str,
resource: &str,
ctx: &OperationContext,
) -> Result<(), DynamoDbError> {
if let Ok(desc) = ctx
.storage
.describe_table(
&ctx.account_id,
extenddb_core::types::DescribeTableInput {
table_name: table_name.to_owned(),
},
)
while_deleting: WhileDeleting,
) -> Result<bool, DynamoDbError> {
let desc = crate::table_lifecycle::read_table_description(table_name, ctx)
.await
&& desc.table_status == extenddb_core::types::TableStatus::Deleting
{
.map_err(|e| arn_storage_error(e, arn))?;
if desc.table_status != TableStatus::Deleting {
return Ok(false);
}
if tag_subresource_is_stream(resource) {
if desc.latest_stream_arn.as_deref() != Some(arn) {
return Err(arn_storage_error(
extenddb_storage::error::StorageError::TableNotFound(table_name.to_owned()),
arn,
));
}
} else if while_deleting == WhileDeleting::Refuse {
return Err(crate::create_table::table_being_deleted(table_name));
}
Ok(())
Ok(true)
}

/// Validate that the ARN refers to an existing table owned by the caller.
Expand All @@ -136,7 +159,9 @@ async fn refuse_while_deleting(
/// | Table ARN with a different partition, service, or region | `ValidationException` (invalid `TableArn`) |
/// | Stream ARN with a different partition, service, or region | `ValidationException` (`Invalid StreamArn`) |
/// | Table does not exist | `ResourceNotFoundException` |
/// | Table is `DELETING`, for `TagResource` and `UntagResource` (`while_deleting` is `Refuse`) | `ResourceInUseException` (`Table is being deleted`) |
/// | Table is `DELETING`, for `TagResource` and `UntagResource` on the table ARN (`while_deleting` is `Refuse`) | `ResourceInUseException` (`Table is being deleted`) |
/// | Table is `DELETING`, for `ListTagsOfResource` and for the table's latest stream ARN | served |
/// | Table is `DELETING`, for a stream ARN whose label is not the table's latest stream | `ResourceNotFoundException` |
///
/// Account is checked before the partition, service, and region, matching the
/// service: a cross-account ARN is denied without revealing whether its other
Expand Down Expand Up @@ -212,30 +237,41 @@ async fn validate_resource_arn(
))
})?;

if while_deleting == WhileDeleting::Refuse {
refuse_while_deleting(table_name, ctx).await?;
// A served request on a DELETING table skips the key-info read, which
// reports such a row as not found on MongoDB and Cassandra.
if refuse_while_deleting(table_name, arn, resource, ctx, while_deleting).await? {
return Ok(());
}
// Verify the table exists via table_key_info (lightweight check).
ctx.storage
.table_key_info(&ctx.account_id, table_name)
.await
.map_err(|e| match e {
extenddb_storage::error::StorageError::TableNotFound(_) => {
DynamoDbError::ResourceNotFoundException(format!(
"Requested resource not found: ResourceArn: {arn} not found"
))
}
other => sanitize_storage_error(other),
})?;
.map_err(|e| arn_storage_error(e, arn))?;

Ok(())
}

/// Report a storage error from the table lookup behind a resource ARN: a
/// missing table names the ARN, as the service does, and anything else is a
/// fault.
fn arn_storage_error(e: extenddb_storage::error::StorageError, arn: &str) -> DynamoDbError {
match e {
extenddb_storage::error::StorageError::TableNotFound(_) => {
DynamoDbError::ResourceNotFoundException(format!(
"Requested resource not found: ResourceArn: {arn} not found"
))
}
other => sanitize_storage_error(other),
}
}

/// Handle `TagResource` — add or overwrite tags on a resource.
///
/// # Errors
///
/// Returns `ResourceNotFoundException` if the resource does not exist.
/// Returns `ResourceInUseException` if the ARN names a table that is being
/// deleted.
/// Returns `ValidationException` if the resource ARN is empty.
/// Returns `InternalServerError` on storage failures.
pub async fn handle_tag_resource(
Expand Down Expand Up @@ -272,6 +308,8 @@ pub async fn handle_tag_resource(
/// # Errors
///
/// Returns `ResourceNotFoundException` if the resource does not exist.
/// Returns `ResourceInUseException` if the ARN names a table that is being
/// deleted.
/// Returns `ValidationException` if the resource ARN is empty.
/// Returns `InternalServerError` on storage failures.
pub async fn handle_untag_resource(
Expand Down Expand Up @@ -322,6 +360,10 @@ pub async fn handle_list_tags_of_resource(
));
}

// Served while the table is DELETING, with the tags, as the service serves

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Measured 2026-11-20 against Amazon DynamoDB in us-east-1 and against this PR (c5985c5) on SQLite and PostgreSQL. Each table had a stream and one table tag (k1=v1). Each request shape was sent at least twice, and DescribeTable read DELETING before and after every round quoted.

ListTagsOfResource, TagResource (new key k9) and UntagResource (absent key nokey) on the table ARN in a loop right after DeleteTable returned. +t is seconds after DeleteTable returned.

Run +t List Tag k9 Untag nokey
1 0.73 s 200 with k1 ResourceInUseException 200
1 1.39 s ResourceNotFoundException ResourceNotFoundException ResourceNotFoundException
2 0.70 s 200 with k1 ResourceInUseException 200
2 1.36 s 200 with k1 ResourceNotFoundException ResourceNotFoundException
2 2.03 s ResourceNotFoundException ResourceNotFoundException ResourceNotFoundException

DescribeTable read DELETING in every row, and the table was gone at +6.0 s and +6.7 s. The ResourceNotFoundException text is Requested resource not found: ResourceArn: <arn> not found. In the same rounds the stream ARN answered 200 throughout. Three further runs gave the same shape (the flip at 0.63 s, 1.28 s to 1.91 s and 2.3 s).

So the service serves the table-ARN tag calls as this comment, the PR body and the wire test describe them for the first 0.6 to 2.3 s of the window, and answers ResourceNotFoundException for the rest. This PR serves ListTagsOfResource and refuses tag writes for the whole window. The text needs the phase, and the wire test needs to assert only the first answer after DeleteTable returns.

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.

The phase is now stated in the doc comment of refuse_while_deleting (a75c9cd) and in the docstrings of the wire file and of test_tag_changes_are_being_deleted_and_tags_are_listed (ec4c09c). The window row of docs/differences-from-dynamodb.md and the PR body state it too. These answers hold for the first 0.6 to 2.3 s after DeleteTable returns, and then the service answers ResourceNotFoundException.

The wire tests assert the first answer after DeleteTable. ExtendDB keeps the first answers for the whole window, and that is filed as #1456 with your runs.

// it in the first seconds of the window (measured 2026-10-25; the later
// answers are in `refuse_while_deleting`): the read is not a change to the
// resource.
validate_resource_arn(&input.resource_arn, ctx, WhileDeleting::Serve).await?;

let tags = ctx
Expand Down
Loading
Loading