Skip to content
13 changes: 7 additions & 6 deletions crates/core/src/validation/warm_throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,13 @@ pub fn validate_warm_throughput_on_update(
/// `ResourceNotFoundException` (S10, T5a, T5c).
///
/// TableClass, DeletionProtection and SSE have the same "only operation" rule
/// on their own, without WarmThroughput (measured), but ExtendDB does not apply
/// it elsewhere yet; here the companion's own sentence is used only when
/// WarmThroughput is present, so a request without WarmThroughput is never
/// refused by this function. `VectorIndexUpdates` is an ExtendDB extension and
/// is grouped with the WarmThroughput sentence, unmeasured. `AttributeDefinitions`
/// is not an operation.
/// on their own, without WarmThroughput (measured); ExtendDB applies it
/// elsewhere only to TableClass and DeletionProtection beside a stream change,
/// in the engine's UpdateTable handler. Here the companion's own sentence is
/// used only when WarmThroughput is present, so a request without
/// WarmThroughput is never refused by this function. `VectorIndexUpdates` is
/// an ExtendDB extension and is grouped with the WarmThroughput sentence,
/// unmeasured. `AttributeDefinitions` is not an operation.
///
/// # Errors
///
Expand Down
105 changes: 59 additions & 46 deletions crates/engine/src/update_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,39 +161,24 @@ pub async fn handle_update_table(

crate::gsi_updates::validate_gsi_updates(&input)?;

// A stream change travels alone. Measured 2026-10-24: beside BillingMode or
// ProvisionedThroughput the service refuses with the IOPS sentence, beside
// any GlobalSecondaryIndexUpdates entry with the index sentence, and
// applies nothing. The per-index definition checks above come first, and
// the already-enabled refusal (`Table already has an enabled stream`) comes
// before the IOPS sentence, so the table's stored specification is read
// here when a companion change is present. DeletionProtectionEnabled beside
// a stream change is refused with the service's only-operation sentence
// (measured 2026-10-24); the general rule for DeletionProtection beside any
// other change is PR #474's and is not claimed here. TableClass and
// OnDemandThroughput beside a stream change are not measured and stay
// accepted.
if let Some(companion) = stream_change_companion(&input) {
let existing = ctx
.storage
.describe_table(
&ctx.account_id,
extenddb_core::types::DescribeTableInput {
table_name: input.table_name.clone(),
},
)
.await
.map_err(|e| update_table_err_to_dynamo(e, &input.table_name))?;
if let Some(spec) = &input.stream_specification {
extenddb_storage::stream_lineage::stream_change(
&input.table_name,
existing.stream_specification.as_ref(),
spec,
)
.map_err(|e| update_table_err_to_dynamo(e, &input.table_name))?;
}
return Err(DynamoDbError::ValidationException(companion.to_owned()));
// A stream change is refused beside some other changes, and nothing
// applies (measured 2026-10-24 and 2026-11-11). TableClass gets its
// only-operation sentence before the table is read, as the service answers
// for a missing table. Billing or throughput (the IOPS sentence), an index
// Create or Delete (the index sentence), and an index WarmThroughput or
// DeletionProtection (their only-operation sentences) are refused by
// `stream_change_companion`, after the index checks above and the stream
// state check below. Not measured: the order of TableClass against those;
// the order of the stream state refusals against the index, WarmThroughput
// and DeletionProtection sentences (measured against the IOPS sentence and
// a bare index Update only); and OnDemandThroughput beside a stream change,
// which stays accepted.
if input.stream_specification.is_some() && input.table_class.is_some() {
return Err(DynamoDbError::ValidationException(
extenddb_core::validation::TABLE_CLASS_MUST_BE_ONLY_OPERATION.to_owned(),
));
}
let companion = stream_change_companion(&input);

// A created GSI's projected attributes count toward the table's limit
// together with the indexes it already has: the total CreateTable checks,
Expand All @@ -219,7 +204,12 @@ pub async fn handle_update_table(
// A switch to PAY_PER_REQUEST stores the on-demand minimum as the warm
// throughput of a provisioned table that is below it, so it needs the table.
let switches_to_on_demand = matches!(input.billing_mode, Some(BillingMode::PayPerRequest));
if projects_attributes || touches_warm || bare_update || switches_to_on_demand {
if companion.is_some()
|| projects_attributes
|| touches_warm
|| bare_update
|| switches_to_on_demand
{
let existing = ctx
.storage
.describe_table(
Expand All @@ -230,6 +220,21 @@ pub async fn handle_update_table(
)
.await
.map_err(|e| update_table_err_to_dynamo(e, &input.table_name))?;
// The stream state refusals (`Table already has an enabled stream`,
// `Table has no stream to disable`) come before the companion sentence
// (measured for the IOPS one, 2026-10-24) and before a bare index
// Update's (measured 2026-11-11).
if let Some(spec) = &input.stream_specification {
extenddb_storage::stream_lineage::stream_change(
&input.table_name,
existing.stream_specification.as_ref(),
spec,
)
.map_err(|e| update_table_err_to_dynamo(e, &input.table_name))?;
}
if let Some(companion) = companion {
return Err(DynamoDbError::ValidationException(companion.to_owned()));
}
if let Some(updates) = &input.global_secondary_index_updates
&& projects_attributes
{
Expand Down Expand Up @@ -290,12 +295,17 @@ pub async fn handle_update_table(

/// The sentence the service refuses a stream change with when the same
/// `UpdateTable` also changes the table's billing or throughput, creates or
/// deletes an index, or changes deletion protection. `None` when the request
/// carries no stream change or no such companion. With both the billing and
/// the index companion present the IOPS sentence is answered (measured); the
/// deletion-protection sentence's order against the other two is not measured
/// and comes last.
/// deletes an index, sets an index's `WarmThroughput`, or changes deletion
/// protection. `None` when the request carries no stream change or no such
/// companion; an index `Update` without `WarmThroughput` is not one (measured
/// 2026-11-11). With both the billing and the index companion present the
/// IOPS sentence is answered (measured); the order of the WarmThroughput and
/// deletion-protection sentences against the others is not measured.
fn stream_change_companion(input: &UpdateTableInput) -> Option<&'static str> {
use extenddb_core::validation::{
DELETION_PROTECTION_MUST_BE_ONLY_OPERATION, INDEX_CHANGE_WITH_STREAM_CHANGE,
WARM_THROUGHPUT_MUST_BE_ONLY_OPERATION,
};
input.stream_specification.as_ref()?;
if input.billing_mode.is_some() || input.provisioned_throughput.is_some() {
return Some(
Expand All @@ -304,17 +314,20 @@ fn stream_change_companion(input: &UpdateTableInput) -> Option<&'static str> {
}
if input
.global_secondary_index_updates
.as_ref()
.is_some_and(|u| !u.is_empty())
.iter()
.flatten()
.any(|u| u.create.is_some() || u.delete.is_some())
{
return Some(
"One or more parameter values were invalid: You cannot create or delete index while changing stream status",
);
return Some(INDEX_CHANGE_WITH_STREAM_CHANGE);
}
// An index Update's, since a Create answered above; a table-level
// WarmThroughput beside a stream change is refused earlier, by
// `validate_warm_throughput_is_only_operation`.
if crate::warm_throughput::touches_warm_throughput(input) {
return Some(WARM_THROUGHPUT_MUST_BE_ONLY_OPERATION);
}
if input.deletion_protection_enabled.is_some() {
return Some(
"One or more parameter values were invalid: DeletionProtection modification must be the only operation in the request",
);
return Some(DELETION_PROTECTION_MUST_BE_ONLY_OPERATION);
}
None
}
Expand Down
95 changes: 57 additions & 38 deletions crates/engine/src/update_table_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ use super::*;
use extenddb_storage::error::StorageError;

/// Measured 2026-10-24: a stream change beside a billing or throughput
/// change, beside an index create or delete, or beside a deletion protection
/// change is refused with its own sentence; alone it is not.
/// change, beside an index create, or beside a deletion protection change is
/// refused with its own sentence; alone it is not. Measured 2026-11-11:
/// beside an index delete it answers the index sentence, beside an index
/// Update carrying WarmThroughput the WarmThroughput sentence, and beside an
/// index Update of ProvisionedThroughput it is not refused. A Create beside an
/// Update (not measured) answers the index sentence: any Create or Delete
/// decides it.
#[test]
fn a_stream_change_travels_alone() {
let with = |extra: Value| -> UpdateTableInput {
fn a_stream_change_refuses_its_companions() {
let with = |extra: &Value| -> UpdateTableInput {
let mut body = serde_json::json!({
"TableName": "t",
"StreamSpecification": {"StreamEnabled": false},
Expand All @@ -23,41 +28,55 @@ fn a_stream_change_travels_alone() {
};
let iops = "One or more parameter values were invalid: You cannot modify stream status while updating table IOPS";
let index = "One or more parameter values were invalid: You cannot create or delete index while changing stream status";
assert_eq!(
stream_change_companion(&with(serde_json::json!({"BillingMode": "PROVISIONED"}))),
Some(iops)
);
assert_eq!(
stream_change_companion(&with(serde_json::json!({
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}
}))),
Some(iops)
);
assert_eq!(
stream_change_companion(&with(serde_json::json!({
"GlobalSecondaryIndexUpdates": [{"Delete": {"IndexName": "g"}}]
}))),
Some(index)
);
assert_eq!(
stream_change_companion(&with(serde_json::json!({
"GlobalSecondaryIndexUpdates": [{"Create": {
let warm = "One or more parameter values were invalid: WarmThroughput must be the only operation in the request";
let protection = "One or more parameter values were invalid: DeletionProtection modification must be the only operation in the request";
let units = serde_json::json!({"ReadCapacityUnits": 5, "WriteCapacityUnits": 5});
let create = serde_json::json!({"Create": {
"IndexName": "g",
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"}
}});
let gsi = |update: Value| serde_json::json!({"GlobalSecondaryIndexUpdates": [update]});
for (extra, expected) in [
(
serde_json::json!({"BillingMode": "PROVISIONED"}),
Some(iops),
),
(
serde_json::json!({"ProvisionedThroughput": units}),
Some(iops),
),
(
gsi(serde_json::json!({"Delete": {"IndexName": "g"}})),
Some(index),
),
(gsi(create.clone()), Some(index)),
(
serde_json::json!({"GlobalSecondaryIndexUpdates": [
create,
{"Update": {"IndexName": "h", "ProvisionedThroughput": units}}
]}),
Some(index),
),
(
gsi(serde_json::json!({"Update": {"IndexName": "g", "ProvisionedThroughput": units}})),
None,
),
(
gsi(serde_json::json!({"Update": {
"IndexName": "g",
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"}
}}]
}))),
Some(index)
);
assert_eq!(stream_change_companion(&with(serde_json::json!({}))), None);
assert_eq!(
stream_change_companion(&with(
serde_json::json!({"DeletionProtectionEnabled": true})
)),
Some(
"One or more parameter values were invalid: DeletionProtection modification must be the only operation in the request"
)
);
"WarmThroughput": {"ReadUnitsPerSecond": 5, "WriteUnitsPerSecond": 5}
}})),
Some(warm),
),
(
serde_json::json!({"DeletionProtectionEnabled": true}),
Some(protection),
),
(serde_json::json!({}), None),
] {
assert_eq!(stream_change_companion(&with(&extra)), expected, "{extra}");
}
let no_stream: UpdateTableInput =
serde_json::from_value(serde_json::json!({"TableName": "t", "BillingMode": "PROVISIONED"}))
.unwrap();
Expand Down
39 changes: 39 additions & 0 deletions crates/storage-sqlite/src/stream_lifecycle_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,42 @@ async fn a_disable_refused_on_a_disabled_stream_closes_the_shards_it_left_open()
assert_eq!(closed_by_enable, 4);
engine.pool.close().await;
}

/// A refused disable writes none of the request's other members, on a table
/// that never had a stream (the transaction rolls back) and on one whose
/// stream is already disabled (the transaction commits the shard close). The
/// engine refuses TableClass beside a stream change before storage is
/// reached; OnDemandThroughput reaches this path through it.
#[tokio::test]
async fn a_refused_disable_writes_no_other_member() {
let engine = engine().await;
create(&engine, "never", false).await;
create(&engine, "off", true).await;
set_stream(&engine, "off", serde_json::json!({"StreamEnabled": false}))
.await
.unwrap();
for name in ["never", "off"] {
let input = serde_json::json!({
"TableName": name,
"StreamSpecification": {"StreamEnabled": false},
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"OnDemandThroughput": {"MaxReadRequestUnits": 100, "MaxWriteRequestUnits": 100},
});
match engine
.update_table(ACCOUNT, serde_json::from_value(input).unwrap())
.await
{
Err(StorageError::Validation(m)) => {
assert_eq!(
m,
format!("Table has no stream to disable: TableName: {name}")
);
}
other => panic!("{name}: {other:?}"),
}
let table = describe_table(&engine, name).await;
assert_eq!(table.table_class_summary, None, "{name}");
assert_eq!(table.on_demand_throughput, None, "{name}");
}
engine.pool.close().await;
}
38 changes: 20 additions & 18 deletions crates/storage-sqlite/src/update_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ impl SqliteEngine {
}
}

// The stream change is decided before any other column is written, so a
// refused one writes nothing else. A disable of an already disabled
// stream is refused, and the transaction then holds only the close of
// the shards the first disable left open, which is committed.
if let Some(spec) = &input.stream_specification
&& let Some(refusal) = Self::apply_stream_specification(
&mut tx,
account_id,
&input.table_name,
&table_id,
spec,
)
.await?
{
tx.commit()
.await
.map_err(|e| StorageError::Internal(e.to_string()))?;
return Err(refusal);
}

if let Some(bm) = &input.billing_mode {
let s = match bm {
BillingMode::Provisioned => "PROVISIONED",
Expand Down Expand Up @@ -314,24 +334,6 @@ impl SqliteEngine {
)
.await?;
}
if let Some(spec) = &input.stream_specification
&& let Some(refusal) = Self::apply_stream_specification(
&mut tx,
account_id,
&input.table_name,
&table_id,
spec,
)
.await?
{
// A disable of an already disabled stream: the request is refused,
// and the transaction holds only the close of the shards the first
// disable left open (a stream change travels alone in the request).
tx.commit()
.await
.map_err(|e| StorageError::Internal(e.to_string()))?;
return Err(refusal);
}

// WarmThroughput on the table and on updated indexes: stored as sent,
// nothing acts on it. Validated by the engine against the current values.
Expand Down
Loading
Loading