Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions crates/core/src/types/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ pub struct StreamDescription {
pub stream_arn: String,
#[serde(rename = "StreamLabel")]
pub stream_label: String,
/// When the stream was requested, epoch seconds. The service returns it
/// on every stream, enabled or disabled. Backends leave it `None`; the
/// engine derives it from `stream_label` at the response boundary.
#[serde(
rename = "CreationRequestDateTime",
skip_serializing_if = "Option::is_none"
)]
pub creation_request_date_time: Option<f64>,
#[serde(rename = "StreamStatus")]
pub stream_status: StreamStatus,
#[serde(rename = "StreamViewType")]
Expand Down
103 changes: 88 additions & 15 deletions crates/engine/src/gsi_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,45 @@ pub(crate) fn validate_gsi_updates(input: &UpdateTableInput) -> Result<(), Dynam
.to_owned(),
));
}
let attr_defs = input.attribute_definitions.as_deref().unwrap_or(&[]);
for ks in &create.key_schema {
if !attr_defs
.iter()
.any(|ad| ad.attribute_name == ks.attribute_name)
{
// Every key attribute must be in AttributeDefinitions. The
// service's sentence depends on the member's shape (measured
// 2026-10-25 and 2026-11-25): absent names the index; fewer
// definitions than the index has keys has its own sentence;
// otherwise the sentence lists every key of the index and every
// definition (the CreateTable sentence, whose CreateTable copy
// lives in core's validation and is not shared with this path).
let defs = match &input.attribute_definitions {
None => {
return Err(DynamoDbError::ValidationException(format!(
"One or more parameter values were invalid: Some index key attributes \
are not defined in AttributeDefinitions. Keys: [{}], \
AttributeDefinitions: [{}]",
ks.attribute_name,
attr_defs
.iter()
.map(|ad| ad.attribute_name.as_str())
.collect::<Vec<_>>()
.join(", ")
"One or more parameter values were invalid: AttributeDefinitions is not specified for index: {}",
create.index_name
)));
}
Some(defs) if defs.len() < create.key_schema.len() => {
return Err(DynamoDbError::ValidationException(
"Invalid KeySchema: Some index key attribute have no definition".to_owned(),
));
}
Some(defs) => defs,
};
if !create
.key_schema
.iter()
.all(|ks| defs.iter().any(|ad| ad.attribute_name == ks.attribute_name))
{
let keys: Vec<&str> = create
.key_schema
.iter()
.map(|ks| ks.attribute_name.as_str())
.collect();
let defined: Vec<&str> = defs.iter().map(|ad| ad.attribute_name.as_str()).collect();
return Err(DynamoDbError::ValidationException(format!(
"One or more parameter values were invalid: Some index key attributes \
are not defined in AttributeDefinitions. Keys: [{}], \
AttributeDefinitions: [{}]",
keys.join(", "),
defined.join(", ")
)));
}
}
if let Some(delete) = &update.delete {
Expand Down Expand Up @@ -536,6 +557,58 @@ mod tests {
);
}

/// A created index whose key attribute is not in AttributeDefinitions is
/// refused with the sentence the service picks by the member's shape
/// (measured 2026-10-25 and 2026-11-25): absent names the index, fewer
/// definitions than the index has keys has its own sentence, and
/// otherwise the sentence lists every key of the index and every
/// definition.
#[test]
fn a_created_gsi_on_an_undefined_key_attribute_is_refused_by_member_shape() {
const FEWER: &str = "Invalid KeySchema: Some index key attribute have no definition";
const LISTED: &str = "One or more parameter values were invalid: Some index key \
attributes are not defined in AttributeDefinitions. Keys: [r, g], \
AttributeDefinitions: [r, pk]";
const ABSENT: &str = "One or more parameter values were invalid: AttributeDefinitions \
is not specified for index: gix";
let input = |keys: [&str; 2], defs: Option<&str>| -> UpdateTableInput {
let mut v = serde_json::json!({
"TableName": "t",
"GlobalSecondaryIndexUpdates": [{ "Create": {
"IndexName": "gix",
"KeySchema": [
{ "AttributeName": keys[0], "KeyType": "HASH" },
{ "AttributeName": keys[1], "KeyType": "RANGE" },
],
"Projection": { "ProjectionType": "ALL" },
}}],
});
if let Some(d) = defs {
v["AttributeDefinitions"] = d
.split_whitespace()
.map(|n| serde_json::json!({ "AttributeName": n, "AttributeType": "S" }))
.collect();
}
serde_json::from_value(v).unwrap()
};
// Definitions as space-separated names; `None` leaves the member out.
let cases = [
(["g", "r"], None, ABSENT),
(["g", "r"], Some(""), FEWER),
(["g", "r"], Some("g"), FEWER),
(["g", "r"], Some("other"), FEWER),
(["r", "g"], Some("r pk"), LISTED),
];
for (keys, defs, expected) in cases {
assert_eq!(
message(validate_gsi_updates(&input(keys, defs))),
expected,
"keys {keys:?}, definitions {defs:?}"
);
}
validate_gsi_updates(&input(["g", "r"], Some("g r"))).unwrap();
}

#[test]
fn an_index_name_outside_the_pattern_is_reported_at_its_member_path() {
let cases = [
Expand Down
13 changes: 11 additions & 2 deletions crates/engine/src/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use extenddb_core::error::DynamoDbError;
use extenddb_core::types::{
DescribeStreamInput, DescribeStreamOutput, GetRecordsInput, GetRecordsOutput,
GetShardIteratorInput, GetShardIteratorOutput, ListStreamsInput, ListStreamsOutput,
ShardIteratorType,
ShardIteratorType, StreamDescription,
};
use extenddb_storage::error::StorageError;
use extenddb_storage::util::stream_label_creation_date_time;
use serde_json::Value;

use crate::OperationContext;
Expand Down Expand Up @@ -44,11 +45,19 @@ pub async fn handle_describe_stream(
.map_err(storage_to_dynamo)?;

let output = DescribeStreamOutput {
stream_description: desc,
stream_description: with_creation_request_date_time(desc),
};
serialize_output(&output)
}

/// The service returns `CreationRequestDateTime` on every stream, enabled or
/// disabled. The label is the creation instant to the millisecond, so it is
/// derived here for every backend rather than stored by each.
fn with_creation_request_date_time(mut desc: StreamDescription) -> StreamDescription {
desc.creation_request_date_time = stream_label_creation_date_time(&desc.stream_label);
desc
}

/// Handle `ListStreams`.
///
/// # Errors
Expand Down
43 changes: 43 additions & 0 deletions crates/engine/src/streams_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@
//! Unit tests for the streams request handlers: iterator tokens, the measured
//! constraint sentences and the not-found answers.

/// `DescribeStream` renders `CreationRequestDateTime` as the label's
/// instant in epoch seconds, next to the members it already had, and
/// omits the member only when the label is not a timestamp.
#[test]
fn describe_stream_output_carries_creation_request_date_time() {
use extenddb_core::types::{
DescribeStreamOutput, StreamDescription, StreamStatus, StreamViewType,
};
let desc = StreamDescription {
creation_request_date_time: None,
stream_arn: "arn:aws:dynamodb:us-east-1:1:table/T/stream/2026-10-24T11:31:45.748"
.to_owned(),
stream_label: "2026-10-24T11:31:45.748".to_owned(),
stream_status: StreamStatus::Disabled,
stream_view_type: StreamViewType::KeysOnly,
table_name: "T".to_owned(),
key_schema: Vec::new(),
shards: Vec::new(),
last_evaluated_shard_id: None,
};
let v = crate::serialize_output(&DescribeStreamOutput {
stream_description: super::with_creation_request_date_time(desc.clone()),
})
.unwrap();
let sd = &v["StreamDescription"];
assert_eq!(sd["CreationRequestDateTime"], 1_792_841_505.748);
assert_eq!(sd["StreamLabel"], "2026-10-24T11:31:45.748");
assert_eq!(sd["StreamStatus"], "DISABLED");

let v = crate::serialize_output(&DescribeStreamOutput {
stream_description: super::with_creation_request_date_time(StreamDescription {
stream_label: "not-a-label".to_owned(),
..desc
}),
})
.unwrap();
assert!(
v["StreamDescription"]
.get("CreationRequestDateTime")
.is_none()
);
}

#[test]
fn shard_iterator_round_trip_backward_compat_and_fail_closed() {
let stream = "arn:aws:dynamodb:us-east-1:1:table/T/stream/2026-10-20T16:17:40.188";
Expand Down
39 changes: 27 additions & 12 deletions crates/engine/src/update_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ pub async fn handle_update_table(
));
}

// Validate: enabling streams requires a view type.
if let Some(spec) = &input.stream_specification
&& spec.stream_enabled
&& spec.stream_view_type.is_none()
{
return Err(DynamoDbError::ValidationException(
"StreamViewType must be specified when StreamEnabled is true".to_owned(),
));
}
// A disable carries no view type (measured 2026-10-24 on a never-streamed
// table and on an enabled one alike; checked before the no-stream rule).
if let Some(spec) = &input.stream_specification
Expand All @@ -131,7 +122,7 @@ pub async fn handle_update_table(
&& input.provisioned_throughput.is_none()
{
return Err(DynamoDbError::ValidationException(
"One or more parameter values were invalid: ProvisionedThroughput must be specified when changing BillingMode to PROVISIONED".to_owned(),
"One or more parameter values were invalid: ProvisionedThroughput must be specified when BillingMode is PROVISIONED".to_owned(),

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 12 update_table unit tests pass with this sentence reverted; only the wire ordering row catches 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.

The wire row missing-throughput-before-the-view-type of NEVER_CREATED_ROWS in tests/python/test_update_table_sentences.py asserts this sentence by equality. CI runs that file in the --comprehensive suite (devtools/run-tests --extenddb --pytest --comprehensive, .github/workflows/integration.yml lines 246 and 425), and the MongoDB and Cassandra jobs run it too. A server built with the old sentence fails that row. The check reads the request inside handle_update_table, so a unit test would only repeat the sentence that the wire row holds.

));
}

Expand All @@ -153,14 +144,18 @@ pub async fn handle_update_table(
));
}

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

// A table-level WarmThroughput stands alone in its request, with the
// measured per-companion sentences (measured 2026-10-23). Checked before
// the value rules, as the service does: it fired on requests whose values
// were otherwise valid. GlobalSecondaryIndexUpdates is accepted beside it.
// The index rules and the view type check above come first: the service
// answers their sentences beside WarmThroughput, with or without
// DeletionProtectionEnabled or BillingMode (measured 2026-11-25).
extenddb_core::validation::validate_warm_throughput_is_only_operation(&input)?;

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 view-type check now runs after validate_warm_throughput_is_only_operation, and the service runs it first. Twice each, on an existing and a missing table:

  • StreamSpecification: {StreamEnabled: true} with no view type, plus WarmThroughput: the service answers If stream is being enabled then UpdateViewType is required, and head answers WarmThroughput must be the only operation in the request.
  • Adding DeletionProtectionEnabled: head answers DeletionProtection modification must be the only operation.
  • Adding a GSI Create with no AttributeDefinitions: the service answers AttributeDefinitions is not specified for index: idx1, and head answers the warm sentence.

The measured order is the billing rules, the index rules, the view type, then the warm rule. Running validate_gsi_updates and validate_stream_specification ahead of the warm check would match; wire rows for these three shapes, and a rerun of the 2026-10-23 warm rows, would hold 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 ae5072c: validate_gsi_updates and validate_stream_specification now run before validate_warm_throughput_is_only_operation.

The three shapes from this thread are rows of NEVER_CREATED_ROWS in tests/python/test_update_table_sentences.py, sent to a table name that does not exist. A fourth row sends WarmThroughput, BillingMode PAY_PER_REQUEST and a GSI Create without AttributeDefinitions. The service answers it with the index sentence (measured 2026-11-25), and main answered the warm sentence. The four rows fail on the previous head and pass here.

test_warm_throughput.py and test_warm_throughput_updates.py pass on a SQLite build of this head. I did not rerun them on the service, because they create tables.


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
Expand Down Expand Up @@ -288,6 +283,26 @@ pub async fn handle_update_table(
serialize_output(&output)
}

/// Enabling a stream requires a view type. The sentence is the service's
/// ([`extenddb_storage::stream_lineage::STREAM_VIEW_TYPE_REQUIRED`]). The
/// service reports a defective index Create and a missing
/// ProvisionedThroughput before this, and this before the warm throughput
/// rule and the table lookup (measured 2026-10-25 and 2026-11-25), so the call
/// sits after the billing and index rules and before the warm rule and the
/// backend call, where it also precedes the already-enabled refusal. The
/// `CreateTable` form has its own sentence.
fn validate_stream_specification(input: &UpdateTableInput) -> Result<(), DynamoDbError> {
if let Some(spec) = &input.stream_specification
&& spec.stream_enabled
&& spec.stream_view_type.is_none()
{
return Err(DynamoDbError::ValidationException(
extenddb_storage::stream_lineage::STREAM_VIEW_TYPE_REQUIRED.to_owned(),
));
}
Ok(())
}

/// 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
Expand Down
27 changes: 27 additions & 0 deletions crates/engine/src/update_table_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@
use super::*;
use extenddb_storage::error::StorageError;

/// Enabling a stream without a view type is refused with the service's
/// sentence; a view type, or a disable, passes this check.
#[test]
fn enabling_a_stream_without_a_view_type_is_refused() {
let input = |spec: Value| -> UpdateTableInput {
serde_json::from_value(serde_json::json!({
"TableName": "t",
"StreamSpecification": spec,
}))
.unwrap()
};
match validate_stream_specification(&input(serde_json::json!({ "StreamEnabled": true })))
.unwrap_err()
{
DynamoDbError::ValidationException(m) => assert_eq!(
m,
"One or more parameter values were invalid: If stream is being enabled then UpdateViewType is required"
),
other => panic!("{other:?}"),
}
validate_stream_specification(&input(serde_json::json!({
"StreamEnabled": true, "StreamViewType": "NEW_IMAGE"
})))
.unwrap();
validate_stream_specification(&input(serde_json::json!({ "StreamEnabled": false }))).unwrap();
}

/// 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.
Expand Down
24 changes: 12 additions & 12 deletions crates/storage/src/stream_lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ use crate::util::{
/// Fixed shards per stream (hash-based partition-key assignment).
pub const SHARDS_PER_STREAM: u32 = 4;

/// The service's refusal of an `UpdateTable` that enables a stream without a
/// `StreamViewType` (measured 2026-10-24 on a never-streamed table and on a
/// table whose stream is enabled). The engine answers it before storage is
/// called; [`stream_change`] answers it for a caller that reaches storage
/// without that check.
pub const STREAM_VIEW_TYPE_REQUIRED: &str = "One or more parameter values were invalid: If stream is being enabled then UpdateViewType is required";

/// A `CreateTable` request with a disabled `StreamSpecification` dropped.
///
/// The service does not store `{StreamEnabled: false}`: `DescribeTable` on
Expand Down Expand Up @@ -85,21 +92,13 @@ pub fn stream_change(
(false, false) => Err(StorageError::Validation(format!(
"Table has no stream to disable: TableName: {table_name}"
))),
// Unreachable through the engine, which refuses an enable without a
// view type before storage with this same sentence. The service's
// sentence for that case, measured 2026-10-24, is "One or more
// parameter values were invalid: If stream is being enabled then
// UpdateViewType is required", and it precedes the already-enabled
// check; the engine's sentence pre-dates this change and is not
// changed here.
// Unreachable through the engine, whose `validate_stream_specification`
// refuses an enable without a view type before storage with this same
// sentence, and before the already-enabled check.
(true, false) => requested

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 test checks this sentence. With the old sentence put back, the 31 storage stream tests and every wire row pass.

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.

Added in 34b6c92. an_enable_without_a_view_type_is_the_measured_sentence in stream_lineage_tests.rs calls stream_change with an enable and no view type, once with no stored specification and once with a disabled one. It asserts the sentence by equality. With the old sentence put back in the arm, that test fails and the other 33 storage stream tests pass.

.stream_view_type
.map(StreamChange::Enable)
.ok_or_else(|| {
StorageError::Validation(
"StreamViewType must be specified when StreamEnabled is true".to_owned(),
)
}),
.ok_or_else(|| StorageError::Validation(STREAM_VIEW_TYPE_REQUIRED.to_owned())),
(false, true) => Ok(StreamChange::Disable),
}
}
Expand Down Expand Up @@ -500,6 +499,7 @@ pub fn describe_stream(
(remaining.len() > limit).then(|| remaining[limit - 1].shard_id.clone());
remaining.truncate(limit);
Ok(StreamDescription {
creation_request_date_time: None,
stream_status: stream_status(table, &label),
stream_view_type: stream.view_type,
stream_arn,
Expand Down
13 changes: 13 additions & 0 deletions crates/storage/src/stream_lineage_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ fn the_two_refusals_are_the_measured_sentences() {
);
}

#[test]
fn an_enable_without_a_view_type_is_the_measured_sentence() {
for current in [None, Some(spec(false, None))] {
match stream_change("t", current.as_ref(), &spec(true, None)) {
Err(StorageError::Validation(m)) => assert_eq!(
m,
"One or more parameter values were invalid: If stream is being enabled then UpdateViewType is required"
),
other => panic!("{other:?}"),
}
}
}

#[test]
fn a_refused_disable_of_a_disabled_stream_closes_the_current_label_first() {
let label = "2026-10-20T10:00:00.000";
Expand Down
Loading
Loading