Skip to content

fix(streams): disabling a stream closes its shards; enabling makes a new one - #515

Merged
LeeroyHannigan merged 19 commits into
mainfrom
fix/482-stream-disable-closes-shards
Nov 10, 2026
Merged

LeeroyHannigan merged 19 commits into
mainfrom
fix/482-stream-disable-closes-shards

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

UpdateTable StreamEnabled=false left the stream ENABLED with every shard open on all four backends, and a later enable reused the same stream ARN, label and shard ids (#482). Measured on the service: a disable closes the stream (DISABLED, every shard with an EndingSequenceNumber, DescribeTable without StreamSpecification, LatestStreamArn still naming it), an enable afterwards creates a new stream with a later label and four new shards, both streams stay listed, and enabling an enabled table or disabling one with no stream is refused.

A table now has a sequence of streams. Each stream's identity is carried in its shard ids (shardId-{table_id}-{label_millis}{view_type}{index}), so no backend needs a schema change, a migration or a catalog version bump; ids written before this scheme, including the shardId-{table_name}-{index} form from before v0.1.14, belong to the table's current stream until its first enable under this release. The rules shared by the four backends (grouping shards into streams, status, paging, the refusals) live in extenddb_storage::stream_lineage; each backend has a stream_lifecycle.rs that reads its rows and calls them.

What a client sees

Every sentence below was measured on the service (two repeats each) and is answered byte for byte on all four backends:

  • Disable: DescribeStream reports DISABLED with the stream's own view type; each shard's EndingSequenceNumber is its last record's sequence number, or its starting number when empty; DescribeTable and the UpdateTable response omit StreamSpecification; LatestStreamArn keeps the closed stream. Writes record only to open shards.
  • Enable: a new stream with a later label and four new shard ids; ListStreams lists both, newest first; a shard id of one stream on the other's ARN is Requested resource not found: Shard does not exist.
  • Refusals: Table already has an enabled stream: TableName: <name>; Table has no stream to disable: TableName: <name>; a stream change beside BillingMode or ProvisionedThroughput (You cannot modify stream status while updating table IOPS), beside GlobalSecondaryIndexUpdates (You cannot create or delete index while changing stream status), beside DeletionProtectionEnabled (DeletionProtection modification must be the only operation in the request), nothing applied; a disable carrying a view type (If stream is being disabled, then UpdateViewType must not be specified); CreateTable with a stream enabled and no view type (Table is being created with a stream enabled, UpdateViewType is required); a StreamSpecification object without StreamEnabled (the model's null-member sentence); a table created with {StreamEnabled: false} stores nothing of it.
  • Paging and constraints: ListStreams carries LastEvaluatedStreamArn whenever Limit cut the page, refuses a start ARN of another table, Limit under 1 and a start ARN under 37 characters; GetShardIterator refuses a ShardId under 28 or over 65 characters and a SequenceNumber under 21, answers AT_SEQUENCE_NUMBER without a number with SequenceNumber cannot be null and an unknown stream ARN with Stream does not exist; DescribeStream refuses a short ExclusiveStartShardId and answers an unknown stream of an existing table with Stream: <arn> not found.

Consistency under concurrency

  • A write racing a disable: on the service every write accepted before the stream reports DISABLED lands before the ending number. On PostgreSQL the write path reads the open shards without a lock, locks the one shard its record goes to FOR KEY SHARE while re-checking that it is still open, and the close locks the open rows FOR UPDATE before taking the ending numbers, so a raced write lands before the ending number or records nothing; on Cassandra a new stream starts one above the larger of the enabling server's next clock value and the last ending number among the table's shards, so on one server a raced record of the closed stream falls in neither stream rather than in the new one; with several servers, a record written by a server whose clock is ahead of the enabling server's can land in the new stream (part of the cross-instance consistency item in the design document). Measured with twelve writer threads under the earlier lock shape: 0 records past the ending number and 0 in the next stream on both (before: 5 of 837 and 1); a storage test now runs eight writers against a disable on PostgreSQL and checks that no record is past its shard's ending number. MongoDB keeps a one-transaction window (see below).
  • Two overlapping stream changes: on MongoDB and Cassandra the catalog write is conditioned on the specification and label it read, so exactly one applies and the other is refused (20 of 20 pairs, before: 15 and 17 of 20 both applied). An enable re-reads the row after inserting its shards and closes them when a disable got in between, so a DISABLED stream has every shard closed (0 of 60 rounds on PostgreSQL and 0 of 30 on MongoDB; before: 11 of 30 and 2 of 30).
  • A disable closes only the stream it decided on, so a disable applying after an overlapping enable does not close the new stream; a PostgreSQL storage test applies such a disable's shard changes after the enable and checks the new stream's four shards stay open. On Cassandra a close writes a shard's ending number only when the shard has none (IF ending_sequence_number = null), so a disable whose close runs after an overlapping enable started the next stream cannot raise the closed shard's ending number above the new stream's start.
  • A stream disabled by an earlier release (stored {StreamEnabled: false}, four open shards), or left so by a close that failed after its catalog write, keeps recording writes. A disable on that table is refused as before and closes the current label's open shards first; an enable closes them too. Storage tests on SQLite and PostgreSQL seed that state. On PostgreSQL, MongoDB and Cassandra an enable closes the open shards of every earlier stream of the table, legacy rows included, so a stream left open after two failed closes in a row (a disable's, then the next enable's) is closed by the enable after that; a PostgreSQL storage test seeds that state. SQLite closes every open shard of the table in the transaction that writes the catalog row.

Compatibility

A stream created by an earlier release keeps working: DescribeStream, ListStreams, GetShardIterator, GetRecords and writes before any change; a disable closes it and keeps its view type; an enable replaces it with a labelled stream. Pinned by a PostgreSQL storage test that seeds the pre-v0.1.14 rows. One limitation: such a stream's label lived only in the table row, so after a disable and a re-enable its ARN no longer resolves: DescribeStream answers Stream: <arn> not found, ListStreams omits it, and an iterator still reading it answers Stream does not exist, so drain such a stream before enabling it again (a disable alone keeps it describable). Recording it would need a per-table stream history column and a migration on three backends; documented in the differences table.

There is no catalog version gate, so a server still on the earlier release writes records past a closed shard's ending number and re-enables a stream under its old ARN. The upgrade manual says to upgrade every server before changing a table's stream, and that rollback is a restore of the pre-upgrade database.

DescribeBackup for a backup taken after a disable keeps showing StreamDescription: {StreamEnabled: false}, as before; the view type the backends now keep for the closed stream is not added there, since the service's answer for that backup is not measured.

Re-cut onto #543

#543 (877ef39) resolves the shard against its stream inside the GetRecords read, with the table's one label deciding ownership. This branch is re-cut on top of it:

  • One set of not-found helpers, main's in extenddb_storage::util. GetShardIterator with a shard of the table's other stream, or a well-formed shard id the stream never had, answers Requested resource not found: Shard does not exist (both measured 2026-10-24); main answered Stream: <arn> not found. with a period there.
  • util::shard_in_stream reads the shard id: a labelled id belongs to the label it carries, and a legacy id to the table's current label while the table has no labelled shard. From a table's first enable under this release every later stream is labelled, which makes legacy rows beside a labelled row the earlier, closed stream. So a closed stream stays readable under its own ARN after the table has a newer one, and a token pairing the newer ARN with an older stream's shard id, labelled or legacy, is refused, as GetShardIterator refuses the same pairing. The labelled-shard check runs only for a legacy id: an EXISTS on stream_shards on SQLite and PostgreSQL (byte order, COLLATE "C" on PostgreSQL), a find_one on the {table_id, shard_id} index on MongoDB, the table's shard rows on Cassandra; a labelled id keeps fix(streams): resolve the shard against its stream inside the GetRecords read #543's statements. Unit tests on the rule, SQLite engine tests on a re-enabled table and on a table whose legacy stream was closed by a disable and replaced by an enable; the wire fixture's reread after the re-enable covers the first on every backend.
  • Cassandra get_stream_records keeps main's ownership check (the shard row's table id and shard_in_stream) and its two round trips, reading the records from the shard's physical partition in parallel with the shard row and applying the shard's sequence range to the rows it gets back. One stream_table_row.
  • Main's wire test that pinned a re-enable to the same ARN moves to the new ARN the service answers; main's PostgreSQL and Cassandra ownership tests pin a label by moving the shard rows to the ids that label gives them, since a shard id carries its stream's label.
  • The engine keeps main's constraint helper beside the shard id length constants.

Review changes

  • GetShardIterator applies the 65-character ShardId maximum only when the shard is not found, so the shardId-{table_name}-{index:016} shards of a table named with more than 40 characters stay readable.
  • A StreamSpecification that is not an object keeps SerializationException from deserialisation; the null-member check applies to objects.
  • PostgreSQL writes lock one shard row FOR KEY SHARE instead of all four FOR SHARE (above).
  • Cassandra's new stream starts one above the larger of the enabling server's clock value and the closed streams' ending numbers (above); the design document's two sentences on the start now agree with the code.
  • MongoDB gets a {table_id: 1, shard_id: 1} index on stream_shards: the open-shard read on every write to a streamed table, and the shard reads behind DescribeStream, GetShardIterator and ListStreams, otherwise scan the whole collection. extenddb init creates it; an existing deployment gets it from extenddb migrate --yes, which reports it pending while it is missing.
  • The lifecycle comments and the design document say what a disable stores ({StreamEnabled: false} with the view type, omitted from responses) instead of "clears the specification".

Tests

  • Wire: tests/python/test_stream_disable.py (21), test_stream_disable_fold.py (16), test_stream_disable_validation.py (14), dual-target. Against the live service: 51 of 51 (measured 2026-10-24). Against a server of each backend built from this head: the three files with test_stream_shard_ownership.py, test_streams.py and test_streams_transactions.py give 71 passed, 4 xfailed on each of SQLite, PostgreSQL, MongoDB and Cassandra (the four GetRecords terminal-page rows wait on End GetRecords iterators after closed shard exhaustion #372's rule; every other assertion in them runs). On main at 1d0d8f4, the first file, at 21 rows, fails 14 against a SQLite server (3 pass, 4 xfail).
  • Rust: extenddb-storage --lib 158 (stream_lineage 15, shard_stream 7); extenddb-storage-sqlite --lib 169, 1 ignored (stream_lifecycle 4, stream_tests 10); extenddb-storage-postgres --test stream_disable 5 (lifecycle, scope, the write race, an enable closing an earlier stream left open, a disable applying after an overlapping enable) and --test stream_disable_legacy 2 (the legacy upgrade, the refused disable of a disabled stream), stream_shard_ownership 6, stream_records_page_order 1, stream_shard_retention 1, table_snapshot 81; extenddb-storage-cassandra --test direct_integration stream_disable 2, stream_endings 2, stream_ownership 3, streams 14; extenddb-storage-mongodb live tests 9 (#[ignore] without a server).
  • Controls: each change that alters behaviour has a test that fails on the code before it (the lineage rule, a legacy shard under a newer labelled stream, the shard id maximum, the non-object specification, the refused disable, the write race lock, the Cassandra start, the Cassandra close guard, an enable closing an earlier stream left open), and the late-disable test fails when a close takes every open labelled shard of the table.
  • cargo fmt, clippy 1.97.0 with -D warnings on every target, check on 1.88.0: clean. No dependency change. Every added source file is under 600 lines; crates/engine/src/streams.rs, crates/storage/src/stream_lineage.rs and Cassandra's stream_lifecycle.rs were split by concern to stay under it, and the PostgreSQL and Cassandra stream disable tests are split the same way, the PostgreSQL ones with a shared fixture.
  • CI passed all 35 checks on a42aeb77c after one rerun each of the Test and Cassandra jobs. The first runs failed shape_gate_tests::serve_refuses_a_file_database_with_pending_shape_migrations (SQLite answered "database is locked" to the test's ALTER TABLE) and tests/test_abac.py::TestLeadingZeroCidr::test_leading_zero_octet_accepted_and_matches_decimal (creating the test user's access key answered HTTP 500 on Cassandra); both passed on the rerun.

Merge notes

Re-cut on main at 1d0d8f4 after #543 (877ef39); see the section above. #372 (end GetRecords iterators on a closed shard): its rule is what the four xfail rows wait for.

Related behaviour

Pre-existing on main, measured during this work, filed separately: DescribeStream omits CreationRequestDateTime on every backend; the service keeps a disabled stream of a deleted table describable and listed, every backend removes it with the table; the missing-view-type sentence on UpdateTable (StreamViewType must be specified when StreamEnabled is true here, If stream is being enabled then UpdateViewType is required on the service); the undefined-index-key sentence; AT_SEQUENCE_NUMBER past a closed shard's ending number returns the last record on the service and nothing here. MongoDB's write-race window (a write whose transaction read the shard as open and commits after the close lands past the ending number; 4 of 320 under twelve writers) stays, documented: closing it needs the write transaction to touch the shard document and the stream path to classify the resulting conflict as retryable. No ExtendDB UpdateTable answers TableStatus UPDATING, so the two UpdateTable responses say ACTIVE where the service says UPDATING.

A drained closed shard keeps returning NextShardIterator (#372). Closed streams and their shard rows are never removed while the table exists, so ListStreams and DescribeStream keep them; about 1.5 ms to 3 ms after 50 disable and enable cycles and about 20 ms after 500 on SQLite, about 8 ms after 500 on PostgreSQL (robinnsc's measurements in the review).

A write takes its stream view type from the table's key info, which a server that did not run the stream change keeps cached for up to 30 seconds (auth.cache.soft_ttl_seconds). After a disable and an enable with the other view type, writes through a second PostgreSQL server landed in the new stream with the earlier view type: 140 of 186 writes from NEW_AND_OLD_IMAGES to KEYS_ONLY and 141 of 186 the other way, the last at 29.87 s and 30.17 s after the enable. MongoDB and Cassandra build the record from the same cached key info. On Cassandra, from reading the commit path (transact_stream_statement, #576), a transaction prepared under one stream and committed after a disable and an enable does the same on one server, since that path does not read the shard rows. Before this change such records went into the same stream after its view type changed. Filed as #698.

Closes #482

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

One thing for whoever merges this after #576 (Cassandra transacted writes now record stream records).

The race probe for this branch's disable path measured single-item writers, where the window between resolving the stream capture and writing the record is one request. On the transaction path that window is the whole PREPARE phase: a row read and condition evaluation per op, the marker LWTs, up to five create-race retries with 50 ms polls, the ledger update and the state transition. The Cassandra write path computes the shard from the table id and partition key and does not read the shard rows, so a transacted write acked before a disable lands in the same physical partition as always; whether a consumer can read it depends on its sequence number falling inside a stream's range, and after a disable and a re-enable a number between the closed shard's EndingSequenceNumber and the next stream's start is in neither.

So on the merged tree the count of transacted writes acked before DISABLED and readable in no stream is not bounded by what the single-item probe measured. One run of the race probe with a TransactWriteItems writer mode on the merged tree, on Cassandra and PostgreSQL, would give that count.

@robinnsc robinnsc 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.

The lifecycle itself looks solid. On local SQLite, PostgreSQL, MongoDB and Cassandra, a disable gives DISABLED with the original view type, correct ending numbers, no StreamSpecification and LatestStreamArn kept, and records nothing after. An enable gives a new label and four new shards, newest first in ListStreams, and cross-stream shard ids and forged iterators are refused. Writers racing a disable plus immediate enable (about 40k acked writes, TransactWriteItems included on SQLite and PostgreSQL) lost nothing from before the disable, put nothing in the old stream after it, and every post-enable write was found. Overlapping UpdateTable calls applied exactly one of two identical changes. The three new wire files plus test_streams.py give 62 passed / 4 xfailed on SQLite, PostgreSQL and MongoDB. Backup and restore, delete-and-recreate, TTL deletes, GSI and TransactWriteItems recording all landed in the right stream. The shard id parser round-tripped on 200k generated ids, and the 5 mutants of stream_lineage.rs we tried were all caught.

Merge notes, since the branch conflicts with main now (mostly against #543, 877ef39). The merge notes in the description mention #463/#466/#468/#475, which aren't on main, and not #543:

  • PostgreSQL, SQLite and MongoDB get_stream_records all auto-merge main's body with no conflict marker, ending in main's shard_in_stream, which is table_label == Some(arn_label). Main's handle_get_records also no longer calls validate_shard. After a textual resolution, a closed stream's ARN answers "Stream does not exist" once the table is re-enabled, and a token pairing the new ARN with an old shard id reads the old stream. shard_in_stream on top of parse_shard_id would fix it: a labelled id matches its own label, a legacy id matches when the ARN is the current label. The wire file's _reread catches it, but no Rust test does.
  • Cassandra: main's private stream_table_row and this PR's stream_table_row in stream_lifecycle.rs:387 collide (E0592). Main's get_stream_records takes stream_arn, which breaks read_all in tests/direct/stream_disable.rs:96. Main's records query keys on the client's shard id, which returns nothing for labelled ids. Since physical_shard_id only needs the id, the records read could still start in parallel with the shard-row read, keeping #543's two round trips, with the bounds applied after.
  • From reading only: #576's transacted Cassandra records take the view type at request time and the sequence at commit, so a transaction committing across a disable plus enable could land in the new stream with the old view type.

Other notes:

  • A drained closed shard keeps returning NextShardIterator. That's deferred to #372, but it matters more once disables produce closed shards in normal use (KCL and Lambda finish a shard on the null), so it might be worth landing #372 right after this.
  • Closed streams and their shard rows are never removed while the table exists, so ListStreams and DescribeStream keep them indefinitely. DescribeStream, GetShardIterator and ListStreams group every shard row the table ever had: about 1.5 ms to 3 ms after 50 cycles and about 20 ms after 500 on SQLite, and about 8 ms after 500 on PostgreSQL. Probably fine at realistic cycle counts.
  • test_stream_disable.py has 21 rows rather than 20.


A table has a sequence of streams. `UpdateTable StreamEnabled=false` closes the current one: the stored specification is cleared (DescribeTable omits `StreamSpecification`), `LatestStreamArn` and `LatestStreamLabel` keep naming the closed stream, DescribeStream reports it `DISABLED` with its original view type, and every open shard gets an `EndingSequenceNumber` (its last record's sequence number, or its starting number when it holds none). `StreamEnabled=true` afterwards creates a new stream: a new label later than the previous one, four new shard ids, the requested view type. The closed stream stays describable and listed; ListStreams lists every stream of a table, newest first. Enabling a table whose stream is enabled, and disabling a table with no enabled stream, are refused with `ValidationException`.

Each stream's identity is carried in its shard ids, `shardId-{table_id}-{label_millis:013}{view_type:1}{index:02}`, so no backend stores a stream table. Shard ids from before this scheme (`shardId-{table_id}-{index}`, and the `shardId-{table_name}-{index}` form SQLite and PostgreSQL wrote before v0.1.14) belong to the table's current stream. Writes record only to open shards. The rules shared by the four backends live in `extenddb_storage::stream_lineage`; each backend reads its table row and shard rows and calls them.

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 catalog bump also means no gate for an earlier release. On SQLite: base, then head disables and re-enables, then base again. Base wrote 4 of 8 records into the closed legacy shards past their EndingSequenceNumber. On a table head created and disabled, base re-enabled the same ARN and every record landed past the ending numbers. A multi-server deployment upgraded one server at a time would do the same once an upgraded server changes a stream. A bump seems heavy here (forced migrate, and Cassandra has no startup gate), so maybe just a line in the upgrade manual: upgrade every server before changing a table's stream, and roll back by restoring the pre-upgrade database.

// then falls between the old shard's ending number and the new
// shard's starting number: in neither stream, rather than in the new
// one under the old view type.
let start = engine

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.

With more than one server, I think this start is only right per server. generate() reads only the local wall clock (stream_util.rs:60), while the close takes the last record's sequence from whichever server wrote it. With skew between servers, a writer whose clock is behind writes new-stream records below this start, so they're in no stream. A writer whose clock is ahead can leave the old shard ending above this start, so records in that window show up in both streams. Base had no ranges, so skew only reordered records. Could consider taking max(local, last sequence of each open shard) + 1 at close time, which removes the overlap case, and noting the rest beside the deferred cross-instance item. Design doc line 100 ("starts where the closed one on the same index ended") also doesn't match line 104 or the code. Read from code, not reproduced.

Comment thread crates/engine/src/streams.rs Outdated
SHARD_ID_TOO_SHORT.to_owned(),
));
}
if shard_len > SHARD_ID_MAX_LEN {

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.

This check runs before validate_shard, so pre-v0.1.14 shardId-{table_name}-{index:016} ids of tables whose name is over 40 characters are now refused, though the PR keeps them as the current stream's shards. On PostgreSQL, a 49-character table name with name-form shards was readable by base and gets ValidationException on head. botocore only enforces the minimum (a 74-character id passes ParamValidator), so SDK clients do reach this. Might be worth applying the max only when the shard isn't found.

(true, true) => Err(StorageError::Validation(format!(
"Table already has an enabled stream: TableName: {table_name}"
))),
(false, false) => Err(StorageError::Validation(format!(

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.

A stream disabled by an earlier release (stored {StreamEnabled: false}, four open shards) reads as DISABLED, KEYS_ONLY, with no EndingSequenceNumber. This refusal then means only an enable closes it. Reproduced on SQLite: created NEW_AND_OLD_IMAGES, disabled on base, and head answered "Table has no stream to disable". A post-commit close that fails (PostgreSQL update_table.rs:851, then the SDK retry) gets to the same state, and writes keep recording into it until the key-info cache expires. Could the decide step close the current label's open shards when the stored spec is already disabled, while still answering this refusal? A storage test that seeds base's disabled state would pin it. Right now a mutant that skips the close on enable passes the SQLite suite.

let mut cursor = shards_coll
.find(doc! { "table_id": table_id })
.find(
doc! { "table_id": table_id, "ending_sequence_number": mongodb::bson::Bson::Null },

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.

stream_shards only has the {shard_id: 1} index, so this filter FETCHes the whole collection across all accounts. With about 20k shard docs the explain shows 20,008 examined and 4 returned, and PutItem p50 went from 7.9 ms to 40 ms. Most of that already happens on main with many streamed tables, but this PR adds 4 docs per enable that are never pruned (1,000 cycles on one table doubled PutItem p50 on an unrelated table). A {table_id: 1, shard_id: 1} index in the bootstrapper would cover this filter and its sort, plus describe, validate and list.

WHERE table_id = $1 \
ORDER BY shard_id",
WHERE table_id = $1 AND ending_sequence_number IS NULL \
ORDER BY shard_id FOR SHARE",

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.

Every write to a streamed table now share-locks all four open shard rows, so concurrent writers on a table keep extending MultiXacts on the same rows, though the record only goes into one shard. In an isolated pgbench run (this SELECT plus one record insert, 32 clients) it was about 30% fewer transactions/s on one hot table and about 8% across 20 tables. End to end over boto3 it was hidden by the client. Could consider selecting the open set unlocked, then SELECT 1 ... WHERE shard_id = <chosen> AND ending_sequence_number IS NULL FOR KEY SHARE on the chosen row only. That still conflicts with the close's FOR UPDATE and re-checks the predicate, and it got back to about 14k tps against 15k unlocked. The race check held either way: 0 records past an ending number in 40 cycles with 12 writers.

Comment thread crates/engine/src/lib.rs
/// deserialised, where the missing field would otherwise surface as a
/// serialization error; its order against the other request checks is not
/// measured.
pub(crate) fn require_stream_enabled_member(body: &serde_json::Value) -> Result<(), DynamoDbError> {

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.

nit: for a StreamSpecification that isn't an object ("x", 1, []), spec.get("StreamEnabled") is None, so this answers the null-member ValidationException where main answered SerializationException. SDKs can't send those shapes, so it hardly matters, but if spec.is_object() would keep it. Also, the new doc block sits inside deserialize_error's doc comment, so the "Enum validation errors ... SerializationException" lines now document this function, and deserialize_error has none.

/// Apply an `UpdateTable` `StreamSpecification` within the caller's
/// transaction.
///
/// Disabling clears the stored specification, so DescribeTable omits

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.

nit: disabling now stores {StreamEnabled: false, StreamViewType} (stored_specification) rather than clearing the spec. The same wording is at storage-postgres/src/stream_lifecycle.rs:219, storage-mongodb/src/stream_lifecycle.rs:196 ("sets the specification to null") and design doc line 96. Similarly, engine/src/backup.rs:494-497 says the member is omitted "as it was before the specification was kept", but main stored {StreamEnabled: false} too, so DescribeBackup of a backup taken after a disable now omits a member main showed.

…a new stream

On UpdateTable StreamEnabled=false the stream is closed: DescribeStream
reports DISABLED with the stream's own view type, every shard carries an
EndingSequenceNumber (its last record's sequence number, or its starting
number when it holds none), DescribeTable omits StreamSpecification, and
LatestStreamArn keeps naming the closed stream. Writes record only to
open shards.

UpdateTable StreamEnabled=true afterwards creates a new stream with a
later label and four new shard ids; the closed stream stays describable
and listed. ListStreams lists every stream of a table, newest first.
Enabling a table whose stream is enabled is refused with "Table already
has an enabled stream: TableName: <name>", and disabling a table with
no enabled stream with "Table has no stream to disable: TableName:
<name>". GetShardIterator on a stream ARN with a shard of the table's
other stream answers "Requested resource not found: Shard does not
exist".

A stream change travels alone: an UpdateTable carrying
StreamSpecification beside BillingMode or ProvisionedThroughput is
refused with "You cannot modify stream status while updating table
IOPS", beside any GlobalSecondaryIndexUpdates entry with "You cannot
create or delete index while changing stream status", beside
DeletionProtectionEnabled with "DeletionProtection modification must be
the only operation in the request", and nothing is applied. A disable
beside a StreamViewType is refused ("If stream is being disabled, then
UpdateViewType must not be specified"). CreateTable with a stream
enabled and no view type is refused ("Table is being created with a
stream enabled, UpdateViewType is required"); a StreamSpecification
without StreamEnabled on CreateTable or UpdateTable gets the model's
null-member sentence; a table created with StreamSpecification
{StreamEnabled: false} stores nothing of it.

ListStreams carries LastEvaluatedStreamArn whenever Limit cut the page,
refuses an ExclusiveStartStreamArn of another table ("ExclusiveStartStreamArn
provided is invalid: <arn>"), Limit under 1 and a start ARN under 37
characters. GetShardIterator refuses a ShardId under 28 or over 65
characters and a SequenceNumber under 21 with the service's constraint
sentences, answers AT_SEQUENCE_NUMBER without a number with
"SequenceNumber cannot be null", and an unknown stream ARN with
"Requested resource not found: Stream does not exist". DescribeStream
refuses a short ExclusiveStartShardId and answers an unknown stream of an
existing table with "Stream: <arn> not found".

Shard ids written before v0.1.14 (shardId-{table_name}-{index}) are the
table's shards: that stream stays describable, listed and readable after
the upgrade, and keeps its view type when disabled (the disable stores
{StreamEnabled: false} with the view type and responses omit the
member). A disable closes only the stream it decided on. On MongoDB and
Cassandra the catalog write of a stream change is conditioned on the
specification and label it read, so of two overlapping changes exactly
one applies and the other is refused; an enable re-reads the row after
inserting its shards and closes them when a disable got in between, so a
DISABLED stream has every shard closed. A write racing a disable
lands before the ending number on PostgreSQL (the open shards are read
FOR SHARE and locked FOR UPDATE by the close) and in no stream on
Cassandra (a new stream starts at a clock value drawn at enable time);
MongoDB keeps a one-transaction window.

Each stream's identity is carried in its shard ids
(shardId-{table_id}-{label_millis}{view_type}{index}), so no backend
needs a schema change; ids written before this scheme belong to the
table's current stream. The rules shared by the four backends live in
extenddb_storage::stream_lineage. On Cassandra, whose write paths
compute a record's partition without reading the shard rows, a stream's
shard is a range of its index's partition.

Re-cut on main after 877ef39 (resolving the shard against its stream
inside the GetRecords read). The not-found sentences use the one set of
helpers in extenddb_storage::util; GetShardIterator with a shard of the
table's other stream answers "Requested resource not found: Shard does
not exist" (util::SHARD_DOES_NOT_EXIST, measured 2026-10-24), replacing
the "Stream: <arn> not found." sentence main kept there. The Cassandra
get_stream_records keeps main's ownership check (the shard row's table
id and util::shard_in_stream) and its two round trips, and reads the
records from the shard's physical partition in parallel with the shard
row, applying the shard's sequence range to the rows it gets back. The
engine keeps main's constraint helper beside the shard id length
constants.

Closes #482
…ames

util::shard_in_stream decided ownership by the table's current label
alone, which was right while a table had one stream. With a stream per
enable, that rule made a closed stream unreadable as soon as the table
was enabled again (its ARN answered "Stream does not exist") and let an
iterator pairing the new ARN with an old shard id read the old stream.

The rule now reads the shard id with stream_lineage::parse_shard_id: a
labelled id belongs to the label it carries, and an id from before
streams were named in shard ids belongs to the table's current stream
while the table has no labelled shard. From a table's first enable under
this release every later stream is labelled, so legacy rows beside a
labelled row are the earlier, closed stream, which is how DescribeStream
and GetShardIterator already group them. All four backends call it from
get_stream_records, so a closed stream stays readable under its own ARN
after the table has a newer one, and a token pairing the newer ARN with
an older stream's shard id, labelled or legacy, is refused.

Whether the table has a labelled shard is read only for a legacy id, so
a labelled id keeps #543's statements: an EXISTS on stream_shards over
the byte-order range of the table's labelled ids on SQLite and
PostgreSQL (stream_lineage::labelled_shard_id_range; COLLATE "C" on
PostgreSQL), a find_one on the {table_id, shard_id} index with the
labelled id pattern on MongoDB, whose legacy ids have 12-digit suffixes,
and the table's shard rows on Cassandra.

Unit tests on the rule (a legacy shard under a table that has a labelled
stream for the current label is not its stream; a labelled shard is
decided without reading the table's shards) and on the labelled range,
and SQLite engine tests reading a re-enabled table: the closed stream
under its own ARN, the new stream under its, the two cross pairings
refused, and the new ARN with a legacy shard of a closed stream refused.
…s they carry

The wire test that pinned a re-enable to the same stream ARN moves to the
new ARN the service answers: the iterators issued before the disable read
the closed stream (the same records a fresh iterator on each of its
shards reads) and none of the keys written after the enable, which are
in the new stream's shards alone.

The Cassandra direct tests read a stream's records by the stream's own
shard id for the partition a key lands in, not by the partition id,
since get_stream_records resolves the shard row the id names. The
ownership tests' relabel moves the table's shard rows to the ids the new
label gives them, as a shard id carries its stream's label, and the
disable test checks that a token pairing one stream's ARN with the other
stream's shard id is refused.
…alizationException

The StreamEnabled member check ran on any non-null StreamSpecification,
so a string, number or array there answered the null-member
ValidationException where main answered SerializationException from
deserialisation. The check now applies to objects only. The doc block
that had landed inside deserialize_error's comment documents the member
check it describes.
GetShardIterator refused a ShardId over 65 characters before looking it
up. The shards a release before v0.1.14 wrote are named after the table
(shardId-{table_name}-{index:016}), so a table whose name is over 40
characters had its stream refused with a ValidationException after the
upgrade, where the previous release read it. botocore enforces only the
minimum, so SDK clients reach this check.

The minimum and the SequenceNumber length are still checked first; the
maximum is applied when the lookup finds no such shard, which is the
answer the service gives since it never has a shard that long. A found
shard over the maximum gets its iterator.
…s left open

A release that stored {StreamEnabled: false} without closing the shards,
or a close that failed after its catalog write, leaves a stream that
DescribeStream reports as DISABLED with four open shards, and writes
keep recording into it until the key info cache expires. A disable on
that table was refused with "Table has no stream to disable" and changed
nothing, so only an enable closed the shards.

The decide step on each backend now closes the current label's open
shards when the stored specification is already disabled, then answers
the same refusal. SQLite closes in the request's transaction and commits
it before answering; PostgreSQL, MongoDB and Cassandra close in the
shard store, as the first disable would have, with no catalog write.

Tests on SQLite and PostgreSQL seed that state: the refusal stands, the
ending numbers are the last record or the starting number, a write after
it records nothing, a second refusal has nothing left to close, and on
SQLite an enable met with the same state closes the open shards too.
Every write to a streamed table locked all four open shard rows FOR
SHARE, so concurrent writers on one table kept extending the same
MultiXacts for a record that goes into one shard. The open set is now
read without a lock, and the chosen row alone is locked FOR KEY SHARE
with its ending_sequence_number re-checked. The close still locks the
open rows FOR UPDATE before taking the ending numbers, which conflicts
with this lock, so a write either commits before the ending number is
taken or finds its row closed and records nothing.

A storage test runs eight writers against a disable and checks that no
record is past its shard's ending number.
stream_shards had the unique shard_id index alone, so the open-shard
read on every write to a streamed table, and the shard reads behind
DescribeStream, GetShardIterator and ListStreams, scanned the whole
collection across all accounts: with about 20k shard documents a write
examined 20,008 to return 4, and PutItem p50 went from 7.9 ms to 40 ms
(measured in review). Each enable now adds four documents that stay, so
the collection grows with every disable and enable cycle.

A {table_id: 1, shard_id: 1} index covers the filter and the sort of
those reads. extenddb init creates it in create_data_db. MongoDB's data
migration, which extenddb migrate --yes runs on every upgrade, creates
it too, so an existing deployment gets it; creating it again is a no-op,
and the migration reports it pending while it is missing. A live test
drops the index, checks it is reported pending, runs the migration and
finds it.
…umbers

A new stream's shards started at a value drawn from the enabling
server's clock alone. With several servers, a record of the closed
stream written by a server whose clock is ahead could sit above that
start, and so read in both the closed stream and the new one.

The start is now one above the larger of this server's next clock value
and the last ending number among the table's shards, taken after the
close. A server whose clock is behind the start can still write a
new-stream record below it, which no stream reads, and on several
servers a raced record from a server whose clock is ahead can still land
above the start; the module and the design document note both cases
beside the deferred cross-instance item. The design document also said
the new shard starts where the closed one ended, which neither the code
nor its later paragraph did.

A close writes a shard's ending number only when the shard has none
(UPDATE ... IF ending_sequence_number = null). An open shard's range has
no upper bound, so a disable whose close read the old shards as open and
took their ending numbers after an overlapping enable had closed them
and started the next stream would otherwise set them to a record of the
new stream from the shared partition, above the new stream's start.

Cassandra direct tests: one moves a closed stream's ending numbers an
hour ahead of the clock and checks that the new stream starts above
them; one runs a close with the old stream's rows as read before the
disable, after the enable and eight writes to the new stream, and checks
that the old shards keep their ending numbers.
…tores

The upgrade manual gets a behaviour change entry: a server on the earlier
release writes records past a closed shard's ending number and re-enables
a stream under its old ARN, so every server is upgraded before any
UpdateTable changes a StreamSpecification, and rollback is a restore of
the pre-upgrade database. No catalog version gate stops the earlier
release, since the change needs no catalog migration. The entry also
says an existing MongoDB deployment gets the new stream_shards index
from extenddb migrate --yes.

The PostgreSQL and MongoDB lifecycle comments and the design document
said a disable clears the specification; it stores {StreamEnabled: false}
with the stream's view type, which DescribeTable omits. DescribeBackup
for a backup taken after a disable keeps showing StreamDescription as
{StreamEnabled: false}, as before the view type was kept, since the
service's answer there is not measured.
…first

A disable on PostgreSQL closes the shards of its stream in one READ
COMMITTED transaction. The transaction locks the open shard rows FOR
UPDATE, numbers the records waiting in stream_pending, and then takes the
ending numbers.

- crates/storage-postgres/src/stream_lifecycle.rs: before that
  transaction, the close numbers each shard's backlog with number_shard,
  the numbering worker's path. Its batches are separate transactions,
  bounded by NUMBER_BATCH_BYTES. Each locks the shard row FOR NO KEY UPDATE
  SKIP LOCKED, and writers do not wait for that lock. The locked numbering
  then moves only what those batches left, normally the records committed
  after them. Before this change, a write that still carried the enabled
  stream specification waited while the close numbered the whole backlog.
  The close functions take the engine instead of the data pool, so they
  can call number_shard.
- Same file: the locking select has ORDER BY shard_id COLLATE "C". The
  close then locks the rows in the byte order of their ids, whatever the
  database collation.
- crates/storage-postgres/src/data/transactions.rs and data/tx_helpers.rs:
  TransactWriteItems first chooses the shard of each stream record. It then
  stores the records in the same byte order of shard ids. Two records on one
  shard keep their request order. Before this change, a transaction with
  items on shard 2 and then shard 0 held shard 2 and waited for shard 0. A
  close that held shard 0 waited for shard 2, and PostgreSQL cancelled one
  of the two after deadlock_timeout.
- crates/storage-postgres/tests/stream_disable_lock_order.rs: two tests
  hold a transaction after its first stream record and start a disable.
  Each checks that both calls succeed and that the close numbered both
  records. One test puts its items in descending shard order. The other
  writes a new version of the lowest shard row after the rest. It also
  disables index scans, so a close without ORDER BY reads that row last.
  Without its half of the change, each test fails with "deadlock detected".
- crates/storage-postgres/tests/stream_disable.rs: a new test checks that
  the closing transaction numbers none of six pending records.
- SQLite, MongoDB and Cassandra have no such cycle. SQLite runs the close
  and every write under one engine write lock. The MongoDB close writes
  only shard documents, which write transactions only read. Cassandra
  writes never read or lock shard rows.
- docs/manuals/07-upgrade-manual.md: the streams section points to the rule
  that migrations 1 to 7 are breaking, instead of advice for servers of two
  releases. It drops the claim that no reader finds a record written past
  an EndingSequenceNumber. It names the first UpdateTable that sets a
  StreamSpecification as the call that closes shards the earlier release
  left open.
- docs/design/07-component-streams.md: the PostgreSQL paragraph describes
  the numbering before the lock and the shard lock order.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@jcshepherd I merged main in (6164f06) and added one follow-up commit (8f5d98d). These are the conflict resolutions and the changes the merge needed:

  • MongoDB: main moved init into the migration runner. The new {table_id: 1, shard_id: 1} index on the data database's stream_shards is now in the data body of migration 1. RELEASED_THROUGH is 0, so that body can still change. extenddb migrate --yes adds the index to a 0.1.x deployment, and --reconverge adds it to a store that an earlier main build migrated. If the v1.0 release PR merges first, the index needs its own migration id.
  • PostgreSQL: with fix(storage-postgres): number stream records after their writes commit #819, a record waits in stream_pending until it gets its number. The close now numbers the pending records of each shard before it sets the ending numbers. Then a record committed before a disable cannot get a number past the end of its shard. Without that step, 3 of the 5 stream_disable tests fail.
  • PostgreSQL lock order (8f5d98d): the close locks its shard rows in shard id order, and TransactWriteItems stores its stream records in the same order. Before, a transaction with items on two shards could deadlock with a disable. Without either half of the change, stream_disable_lock_order.rs fails with "deadlock detected".
  • Before the close takes the FOR UPDATE lock, it numbers the backlog through the path of the numbering worker. Writers do not wait for the whole backlog.
  • stream_commit_order.rs from fix(storage-postgres): number stream records after their writes commit #819 takes the stream label from table creation instead of a pinned label.
  • The streams section of the upgrade manual now follows the rule on main that migrations 1 to 7 are breaking.

One gap is older than the merge: no filter in devtools/run-mongodb-tests selects the MongoDB stream live tests, so CI does not run them. I ran them against a local replica set, and both pass.

CI passed on 6164f06 (45 checks) and is running on 8f5d98d. The PR is ready for your review.

Two files conflicted.

crates/engine/src/update_table.rs:
- main moved validate_gsi_updates and its test to gsi_updates.rs. The
  merge keeps stream_change_companion and drops the old body of
  validate_gsi_updates. The call site calls
  crate::gsi_updates::validate_gsi_updates.
- The unit tests stay in update_table_tests.rs. The merge deletes
  a_created_gsi_throughput_below_one_is_refused, which main moved to
  gsi_updates.rs. It adds warm_throughput and warm_throughput_record to
  the two GsiDescription literals.

crates/storage-cassandra/src/update_table.rs:
- The table and index WarmThroughput reads from main come before the
  stream preamble. The index WarmThroughput writes from main come before
  the shard changes of the stream change.
- The write of the tables row combines the two conditions. With a
  WarmThroughput, the write is conditional on table_id and on the warm
  throughput record that the request read. A pending stream change adds
  the stream specification and the stream label that the request read.
  With neither, the condition is IF EXISTS. tables_write_condition makes
  the condition and its bound values in the same order. write_tables_row
  runs one attempt of the write.
- A write that does not apply found the row gone, a committed stream
  change, or a new warm throughput record. The retry loop from main
  merges the record again only when the stream fields are still the
  values that the request read. Otherwise the loop stops. Then
  refuse_overlapping_stream_change answers a stream change, and
  TableNotFound answers the other requests.

The merge also changes two files that did not conflict:
- crates/storage-cassandra/src/stream_lifecycle.rs gets
  stream_condition_fields, the read of the stream fields at LOCAL_SERIAL
  that the retry loop uses.
- docs/manuals/07-upgrade-manual.md: the stream section said that
  migrations 1 to 7 are breaking. main now carries migrations 1 to 9
  and says in The Catalog Status which of them are breaking. The
  sentence now points there and gives no count.
A table created without a stream has both stream columns null. Its
first enable binds null for the stream specification and the stream
label that it read. Cassandra meets a condition that compares a column
with null on a row that does not exist, and an UPDATE then writes the
row. A DeleteTable can remove the row between the read and the
lightweight transaction. An enable that ran in that window wrote a
catalog row that held only the columns that the write sets.

The write of the tables row is now conditional on table_id when it
carries a WarmThroughput or a stream change. A missing row fails the
condition. A table created again under the same name has a different
table_id and fails the condition too. For a request with a stream
change, the read after a failed write and
refuse_overlapping_stream_change answer TableNotFound for such a row.
They give the same answer for a missing row. A WarmThroughput without a
stream change keeps main's retry loop. A missing row ends that loop. On
a table created again under the same name, the loop tries again until
MERGE_ATTEMPTS and then answers Internal, as on main.
refuse_overlapping_stream_change reads the row at LOCAL_SERIAL through
the same query as the retry loop.

Tests:
- A unit test pins the condition and the order of its bound values. It
  covers four cases: no part, a WarmThroughput only, a stream change
  only, and both.
- A direct test runs the stream enable write with null stream values
  against a key that has no row. The write does not apply and no row
  appears. The same write applies to a table created without a stream.
  On a local Cassandra 4.1.12 the test fails without the table_id part
  and passes with it.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@jcshepherd I merged main in again (c74eba2) and added one fix (23a02ea). CI passes on 23a02ea.

Merge notes:

  • crates/engine/src/update_table.rs: main moved validate_gsi_updates and its test to gsi_updates.rs. The merge keeps stream_change_companion and drops the old body. The unit tests stay in update_table_tests.rs, with main's two new fields in the GsiDescription literals.
  • crates/storage-cassandra/src/update_table.rs: main's WarmThroughput reads and writes come before the stream change's. The tables write combines the two conditions: main's table_id and warm_throughput when the request carries a WarmThroughput, and this PR's stream_specification and stream_label when a stream change is pending. When the write does not apply, the loop reads the row again at LOCAL_SERIAL (stream_condition_fields, new in stream_lifecycle.rs). It retries only when the warm throughput record moved.
  • docs/manuals/07-upgrade-manual.md: the stream section no longer counts the breaking migrations. It points to The Catalog Status, which main updated.

The fix: a stream enable on a table created without a StreamSpecification binds null for both stream columns. Cassandra holds a condition on null columns true for a row that does not exist. So a DeleteTable between the read and the write let the enable write a partial catalog row for the deleted table. The write is now also conditional on table_id. A direct test runs the write against a missing row. On Cassandra 4.1.12 it fails without the table_id part and passes with it. #912 is the same rule in drop_ttl_index on main.

After the merge, a StreamSpecification beside an index Update that carries WarmThroughput gets this PR's create-or-delete sentence. Main accepted that request. I did not measure either answer on DynamoDB.

@jcshepherd jcshepherd 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.

Revisions look good. One minor note: streams created before this fix will not readable once they are disabled. I believe the PR itself mentions this, but we should make sure the documentation is clear about this ("loses its ARN" may not have be direct enough). This can be done as a follow-up PR.

@pdf-amzn

Copy link
Copy Markdown
Collaborator

Some additional things to consider for a follow-up PR:

Should fix

Blocking: a GSI Update beside a stream change is refused, but DynamoDB accepts it. stream_change_companion (crates/engine/src/update_table.rs:297) refuses any non-empty GlobalSecondaryIndexUpdates with "You cannot create or delete index while changing stream status". I probed DynamoDB (2026-11-10, provisioned table with one GSI): {StreamEnabled: false} plus a GSI Update of ProvisionedThroughput is accepted and applies both (stream DISABLED, GSI throughput changed), and the same with {StreamEnabled: true, StreamViewType: NEW_IMAGE} on a table without a stream is accepted too (new stream, GSI throughput changed). Main accepted both; this branch refuses both. Please count only Create/Delete entries and add these two as dual-target rows.

TableClass beside a stream change is accepted, but DynamoDB refuses it, and on SQLite the refused-disable path applies it. Same probe: {StreamEnabled: false} plus TableClass: STANDARD_INFREQUENT_ACCESS is refused with "One or more parameter values were invalid: TableClass modification must be the only operation in the request", both on a table with a stream and on one whose stream is already disabled, and nothing changes. ExtendDB accepts the first and applies both changes; the constant already exists (TABLE_CLASS_MUST_BE_ONLY_OPERATION) but is only checked when WarmThroughput is present. That part is also on main, but since this PR adds the stream companion rules it's the natural place to add TableClass to them. Separately, crates/storage-sqlite/src/update_table.rs:317-334 commits the transaction before returning the "Table has no stream to disable" refusal, after table_class (line 302) and on_demand_throughput (line 305) are written in it, so on SQLite that refusal applies those fields (PostgreSQL, MongoDB and Cassandra apply nothing). The engine refusal makes the TableClass case unreachable, but OnDemandThroughput (not measured beside a stream change) still reaches it; please also decide the stream change before the other column updates, or roll back and close the shards in a fresh transaction, and fix the "a stream change travels alone in the request" comment.

MongoDB: the stream-change catalog write isn't conditioned on table_id. Same class as the Cassandra fix in 23a02ea. stream_guard (crates/storage-mongodb/src/table_engine.rs:945-973) holds only the spec and label, and the filter is by {account_id, table_name}. If the table is deleted and recreated (without a stream) between the read and the update_one, the enable applies to the new table while the shards are inserted under the old table_id. Narrow window, but the fix is small: add table_id to the guard and answer TableNotFound when it differs on the re-read.

Two versions of the legacy-shard rule. table_streams (crates/storage/src/stream_lineage.rs:353-356, behind DescribeStream / ListStreams / GetShardIterator) gives legacy rows the current label unless a labelled stream holds it; shard_in_stream (crates/storage/src/util/shard_stream.rs:52-60, GetRecords) only while the table has no labelled shard. They disagree after an enable whose shard insert failed on a table that already has a labelled stream: DescribeStream shows the closed legacy shards as the new stream's, GetShardIterator accepts them, GetRecords refuses them. Attaching legacy rows in table_streams only when there's no labelled stream would make them agree.

Upgrade manual: the pre-upgrade stream limitation. Following up on jcshepherd's note: docs/manuals/07-upgrade-manual.md doesn't say that every stream existing at upgrade time becomes unreadable after a disable and a re-enable (DescribeStream → Stream: not found, ListStreams omits it, iterators → Stream does not exist). A disable alone keeps it readable. Please add "drain before re-enabling" there and make the differences-table row say the data becomes unreadable, not just that the ARN changes. Worth also saying that a stream disabled by an earlier release keeps recording writes while it reports DISABLED, and that one disable per such table closes it.

Fine as follow-ups

  • shard_lookup_error (crates/engine/src/streams.rs:222-230) turns any storage error for a >65-char ShardId into a 400, including internal errors; limit it to the not-found case.
  • The PR body says migrate --yes reports the MongoDB stream_shards index pending while missing; that holds for released stores, but a store migrated by an unreleased build only gets it from --reconverge with no warning. The upgrade manual has this right; the body could match.
  • Cassandra write_tables_row and close_shards_as_read are pub + #[doc(hidden)]; PostgreSQL gates the same hooks behind #[cfg(feature = "test-hooks")].
  • Stale comments: crates/storage-mongodb/src/stream_lifecycle.rs:229-231 (says two concurrent changes can both pass), "close every open shard of the table" on PostgreSQL/MongoDB/Cassandra (they close only the label's shards), and the test_stream_shard_ownership.py docstring (line 10) that still says the table keeps its ARN.
  • test_stream_disable.py:407: own in (expected, []) can fail if the 100-stream page splits the table's two streams.
  • Small Rust cleanups: name the bare 37/21 limits in streams.rs and the repeated 16/13-digit widths in the shard id parsing, drop the unneeded #[allow(clippy::too_many_arguments)] at stream_lineage.rs:479, and call stream_change(...)? directly instead of let _would_apply = ... at table_engine.rs:994.

Merged via the queue into main with commit 359718b Nov 10, 2026
78 of 82 checks passed
@LeeroyHannigan
LeeroyHannigan deleted the fix/482-stream-disable-closes-shards branch November 10, 2026 21:49
@pdf-amzn pdf-amzn removed their assignment Nov 10, 2026
LeeroyHannigan added a commit that referenced this pull request Nov 10, 2026
Main at 359718b is 13 commits ahead of the last merge. Three files
conflicted.

- crates/storage-postgres/src/stream_engine.rs: #515 rewrote
  describe_stream around stream_table_row and
  stream_lineage::describe_stream. The merge takes that code and
  decodes the key schema with from_catalog_json, as this branch did in
  the old describe_stream.
- docs/differences-from-dynamodb.md: the U+0000 row of this branch and
  the stream disable and enable row of #515 both stay.
- docs/manuals/07-upgrade-manual.md: the migration 10 paragraph of this
  branch stays, followed by the [backup.store] paragraph as #855 wrote
  it.

The other stream code that #515 adds reads only the stream
specification, which holds no attribute name. Against main, the merged
tree changes the same 43 files with the same line counts as this
branch did against its merge base.
LeeroyHannigan added a commit that referenced this pull request Nov 10, 2026
Main is 3 commits ahead of the last merge (b5858c7), up to cbc3680:
#515 (disabling a stream closes its shards), #355 (auth) and #896
(npm). The textual merge is clean and the merged tree compiles with no
change. Seven files changed on both sides: crates/engine/src/
create_table.rs, data_engine.rs, lib.rs, stream_engine.rs and
table_engine.rs in crates/storage-mongodb/src, and
docs/design/13-storage-mongodb.md and docs/differences-from-dynamodb.md.

In assign_shard_in_session, #515 reads only the open shards and returns
None when the table has none. This branch maps the errors of the
table read, the shard find and the cursor in that function through
write_conflict::transaction_error. The merge keeps both. The stream
record path in data_engine.rs takes the let-else of #515, so a write
that finds no open shard records nothing. The record insert keeps
transaction_error.

#515 adds no code that runs inside a write transaction. The new
stream_lifecycle.rs and the UpdateTable stream change in
table_engine.rs run without a session, because UpdateTable has no
transaction on this backend. So their driver errors stay Internal.
A plain CreateTable runs no transaction. The CreateTable of a restore
calls init_stream_shards after it commits its registration
transaction. The close of a stream updates stream_shards
documents, and a write transaction only reads those documents. So a
close does not abort a write with WriteConflict. The counter
documents in the counters collection, which writers do conflict on,
are not touched by a close.

In lib.rs the module list gets stream_lifecycle from main and keeps
write_conflict. In create_table.rs main adds
require_stream_enabled_member and this branch's comment on the
TransactionConflict arm stays.
amrith pushed a commit to amrith/extenddb that referenced this pull request Nov 20, 2026
…tendDB#1068)

* test(migrations): stop forgetting migrations a release will freeze

The release that freezes catalog migrations 1 to 12 raises
RELEASED_THROUGH from 0 to 12, and Runner::forget then refuses every id
from 1 to 12. Ten tests and two devtools scripts forget one of those ids
and expect success, and two extenddb-storage unit tests assume no id is
released. Each now passes with the bound at 0 and at 12.

Where forget only made a migration pending again, the test deletes the
migration's ledger row with the backend's own client (the version row
is left as it was; the next run rewrites it):
- migration 6's backfill tests on SQLite, PostgreSQL and Cassandra;
- the PostgreSQL re-registration on a changed status;
- the Cassandra check that the status before the lock reads no policy;
- the backup commands' exit 3 on a catalog behind the binary
  (tests/test_backup_store_config.py).

Where the test is about forget, it keeps its purpose with a runner given
a released bound of 0: PostgreSQL's forget-and-reapply test, MongoDB's,
SQLite's in changed_ahead_and_forgotten_ledgers, SQLite's
one-transaction test, and the "nothing to forget" case of
forget_refuses_an_id_it_cannot_forget. Runner::with_released_through is
exposed under the existing test-util feature for this, and SQLite's
forget takes the runner through a new forget_with. Release builds do
not enable test-util, and nothing a release binary reads can change the
bound. each_refusal_names_its_command checks the Changed advice on both
sides of the bound: --forget for RELEASED_THROUGH + 1, and "run the
ExtendDB release that recorded it" for RELEASED_THROUGH.

The PostgreSQL and Cassandra catalog lock scripts ran
`migrate --forget <id>` and expected exit 0. They now check that
`--forget` of an id the binary does not carry exits 1 and leaves the
lock free, delete the migration's ledger row themselves, and check that
`migrate --yes` applies it again, as before.

Since every forget test sets its own bound, none checked the bound a
release binary uses: Runner::new could set 0 and every test would pass.
the_default_runner_refuses_every_id_this_binary_released checks that
Runner::new refuses each id from 1 to RELEASED_THROUGH with "has been
released" and forgets the first id above the bound, so it holds at any
bound. devtools/check-postgres-catalog-lock reads the bound from
registry.rs and, when it is above 0, checks that the binary's
`migrate --forget 1` exits 1 with that message and leaves both ledgers
unchanged.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

* docs: name 0.1.15 as the release that brings the migration ledger

The docs, the messages the binary prints and the comments beside them
were written for the migration ledger arriving in 1.0. It arrives in
0.1.15, which is itself a 0.1.x release and a release before 1.0, so
"a release before 1.0", "a 0.1.x release" and "the v1.0 schema" would
include the release that brings the ledger.

Statements about which releases predate the ledger, the frozen
migrations or the 14-digit backup ids now name 0.1.14 and earlier, or
0.1.15 and later. Migration 1's schema is called that instead of the
v1.0 schema. The printed messages that change:
- "a release before 1.0" becomes "a release before 0.1.15" in the
  status, the migrate advice and preview, and --reconverge's help;
- migrate-legacy's refusal and its --help name "the 13-digit shape
  that 0.1.14 and earlier releases issued";
- PostgreSQL's and Cassandra's check after migration 1 compare with
  migration 1's schema;
- migration 1's description in migrate --list drops "v1.0".
The tests and devtools scripts that match these messages change with
them. The CI steps that run the 0.1.14 images are named for 0.1.14.
README.md and docs/cassandra-setup.md say the Cassandra image is
published from 0.1.15.

docs/versioning.md stated its rules for every release: a patch release
adds no configuration key and no breaking catalog migration, and rolls
back with the earlier binary. 0.1.15 does both, and rolling it back
needs the backup taken before the upgrade. The page now says the rules
apply from 1.0 and what a 0.x release can change, and that the crates
are published to crates.io from 0.1.15.

The upgrade manual gains a 0.1.15 entry for ExtendDB#511: a Query whose
partition key condition is not an equality now gets
AccessDeniedException where a LeadingKeys fence does not cover its
operand, where 0.1.14 answered ValidationException. The six 0.1.15
entries whose headings named no release (ExtendDB#515, ExtendDB#384, ExtendDB#471, ExtendDB#692, ExtendDB#581,
note says one server per catalog "in this release", as README.md does.
CONTRIBUTING step 7 lists Cassandra's checksum test, and
differences-from-dynamodb.md no longer says "this branch".

Statements about 1.0 as a milestone (scope, support policy) are
unchanged. So are the migration bodies, whose checksums the release
freezes, the ADRs, which are not edited after acceptance, the design
document's revision log, and the RELEASED_THROUGH and RELEASED comments
that the release commit rewrites.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

* fix(release): keyless Cassandra signing note, crate SHA-256 target dir

The Cassandra image's Docker Hub overview said every image is signed
with the KMS release key and showed `cosign verify --key`.
release-image.yml signs every backend's image keyless through
.github/actions/sign-image, and the first Cassandra image is published
after the keyless migration, so no Cassandra image carries a key
signature. The overview now gives the keyless verify command and signer
identities that the PostgreSQL and MongoDB overviews give.

devtools/release-dry-run's SHA-256 record step ran `cd target/package`,
which fails when CARGO_TARGET_DIR (or a cargo config) moves the target
directory, as `cargo package` then writes elsewhere. The step now reads
target_directory from `cargo metadata`, as devtools/check-crate-packages
does. release-crates.yml runs with the default target directory and is
not affected.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

---------

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
amrith pushed a commit to amrith/extenddb that referenced this pull request Nov 20, 2026
…tendDB#1069)

* test(migrations): stop forgetting migrations a release will freeze

The release that freezes catalog migrations 1 to 12 raises
RELEASED_THROUGH from 0 to 12, and Runner::forget then refuses every id
from 1 to 12. Ten tests and two devtools scripts forget one of those ids
and expect success, and two extenddb-storage unit tests assume no id is
released. Each now passes with the bound at 0 and at 12.

Where forget only made a migration pending again, the test deletes the
migration's ledger row with the backend's own client (the version row
is left as it was; the next run rewrites it):
- migration 6's backfill tests on SQLite, PostgreSQL and Cassandra;
- the PostgreSQL re-registration on a changed status;
- the Cassandra check that the status before the lock reads no policy;
- the backup commands' exit 3 on a catalog behind the binary
  (tests/test_backup_store_config.py).

Where the test is about forget, it keeps its purpose with a runner given
a released bound of 0: PostgreSQL's forget-and-reapply test, MongoDB's,
SQLite's in changed_ahead_and_forgotten_ledgers, SQLite's
one-transaction test, and the "nothing to forget" case of
forget_refuses_an_id_it_cannot_forget. Runner::with_released_through is
exposed under the existing test-util feature for this, and SQLite's
forget takes the runner through a new forget_with. Release builds do
not enable test-util, and nothing a release binary reads can change the
bound. each_refusal_names_its_command checks the Changed advice on both
sides of the bound: --forget for RELEASED_THROUGH + 1, and "run the
ExtendDB release that recorded it" for RELEASED_THROUGH.

The PostgreSQL and Cassandra catalog lock scripts ran
`migrate --forget <id>` and expected exit 0. They now check that
`--forget` of an id the binary does not carry exits 1 and leaves the
lock free, delete the migration's ledger row themselves, and check that
`migrate --yes` applies it again, as before.

Since every forget test sets its own bound, none checked the bound a
release binary uses: Runner::new could set 0 and every test would pass.
the_default_runner_refuses_every_id_this_binary_released checks that
Runner::new refuses each id from 1 to RELEASED_THROUGH with "has been
released" and forgets the first id above the bound, so it holds at any
bound. devtools/check-postgres-catalog-lock reads the bound from
registry.rs and, when it is above 0, checks that the binary's
`migrate --forget 1` exits 1 with that message and leaves both ledgers
unchanged.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

* docs: name 0.1.15 as the release that brings the migration ledger

The docs, the messages the binary prints and the comments beside them
were written for the migration ledger arriving in 1.0. It arrives in
0.1.15, which is itself a 0.1.x release and a release before 1.0, so
"a release before 1.0", "a 0.1.x release" and "the v1.0 schema" would
include the release that brings the ledger.

Statements about which releases predate the ledger, the frozen
migrations or the 14-digit backup ids now name 0.1.14 and earlier, or
0.1.15 and later. Migration 1's schema is called that instead of the
v1.0 schema. The printed messages that change:
- "a release before 1.0" becomes "a release before 0.1.15" in the
  status, the migrate advice and preview, and --reconverge's help;
- migrate-legacy's refusal and its --help name "the 13-digit shape
  that 0.1.14 and earlier releases issued";
- PostgreSQL's and Cassandra's check after migration 1 compare with
  migration 1's schema;
- migration 1's description in migrate --list drops "v1.0".
The tests and devtools scripts that match these messages change with
them. The CI steps that run the 0.1.14 images are named for 0.1.14.
README.md and docs/cassandra-setup.md say the Cassandra image is
published from 0.1.15.

docs/versioning.md stated its rules for every release: a patch release
adds no configuration key and no breaking catalog migration, and rolls
back with the earlier binary. 0.1.15 does both, and rolling it back
needs the backup taken before the upgrade. The page now says the rules
apply from 1.0 and what a 0.x release can change, and that the crates
are published to crates.io from 0.1.15.

The upgrade manual gains a 0.1.15 entry for ExtendDB#511: a Query whose
partition key condition is not an equality now gets
AccessDeniedException where a LeadingKeys fence does not cover its
operand, where 0.1.14 answered ValidationException. The six 0.1.15
entries whose headings named no release (ExtendDB#515, ExtendDB#384, ExtendDB#471, ExtendDB#692, ExtendDB#581,
note says one server per catalog "in this release", as README.md does.
CONTRIBUTING step 7 lists Cassandra's checksum test, and
differences-from-dynamodb.md no longer says "this branch".

Statements about 1.0 as a milestone (scope, support policy) are
unchanged. So are the migration bodies, whose checksums the release
freezes, the ADRs, which are not edited after acceptance, the design
document's revision log, and the RELEASED_THROUGH and RELEASED comments
that the release commit rewrites.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

* fix(release): keyless Cassandra signing note, crate SHA-256 target dir

The Cassandra image's Docker Hub overview said every image is signed
with the KMS release key and showed `cosign verify --key`.
release-image.yml signs every backend's image keyless through
.github/actions/sign-image, and the first Cassandra image is published
after the keyless migration, so no Cassandra image carries a key
signature. The overview now gives the keyless verify command and signer
identities that the PostgreSQL and MongoDB overviews give.

devtools/release-dry-run's SHA-256 record step ran `cd target/package`,
which fails when CARGO_TARGET_DIR (or a cargo config) moves the target
directory, as `cargo package` then writes elsewhere. The step now reads
target_directory from `cargo metadata`, as devtools/check-crate-packages
does. release-crates.yml runs with the default target directory and is
not affected.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

* chore(release): bump version to 0.1.15 and freeze migrations 1-12

Moves the workspace version from 0.1.14 to 0.1.15 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins in
[workspace.dependencies], the 14 workspace entries in Cargo.lock (no
third-party entry changes), packaging/npm/package.json (version and the
five platform pins), the four licence-notice files (regenerated with
the scripts and cargo-about 0.9.0; each lists the 11 workspace crates
its binary links), and the example `extenddb version` and `serve`
output in docs/getting-started.md and
docs/manuals/04-quickstart-setup-guide.md.

Raises RELEASED_THROUGH from 0 to 12, the last migration id, and fills
the RELEASED tables of SQLite, PostgreSQL, MongoDB and Cassandra (12,
14, 13 and 13 entries) with the checksum, kind and convergent flag of
each body or not-applicable reason of migrations 1 to 12, and a code
body's fingerprint, as each backend's
the_released_bodies_match_their_checksums test prints them. From this
release on those bodies are frozen, `extenddb migrate --forget` refuses
ids 1 to 12, and devtools/check-released-through, which the release
workflows' gate jobs run, passes.

The tests that depended on the bound changed in the commits before this
one; this commit changes no test.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>

---------

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
jgaul3 pushed a commit to jgaul3/extenddb that referenced this pull request Dec 2, 2026
…ExtendDB#963)

* fix(streams): answer a stream change's companions as the service does

An UpdateTable that carries a StreamSpecification answered the index
sentence for every GlobalSecondaryIndexUpdates entry and accepted
TableClass. On SQLite, a disable refused with "Table has no stream to
disable" committed the request's TableClass and OnDemandThroughput
before it answered.

Measured on Amazon DynamoDB on 2026-11-11 (us-east-1, a provisioned
table with one GSI, each refusal sent twice):

- The service accepts an index Update of ProvisionedThroughput beside
  {StreamEnabled: false}. It also accepts one beside {StreamEnabled:
  true, StreamViewType: NEW_IMAGE} on a table whose stream is
  disabled. Both changes apply.
- An index Create or Delete beside a stream change answers "You cannot
  create or delete index while changing stream status".
- An index Update that carries WarmThroughput beside a stream change
  answers "WarmThroughput must be the only operation in the request".
- TableClass beside {StreamEnabled: false} answers "TableClass
  modification must be the only operation in the request". The answer
  is the same on a table with an enabled stream and on one whose stream
  is already disabled.

The engine counts only Create and Delete entries for the index
sentence. It answers the WarmThroughput sentence for an index Update
that carries WarmThroughput. It refuses TableClass beside a stream
change before it reads the table. All three reuse the existing
constants. SQLite applies the stream change before it writes any other
column. A refused disable then commits only the close of the shards
that a disabled stream left open. OnDemandThroughput beside a stream
change is not measured and stays accepted.

ExtendDB does not change an index's ProvisionedThroughput, so the two
accepted requests answer "UpdateGlobalSecondaryIndex is not yet
supported", as they did before ExtendDB#515. Their wire rows are marked xfail
on ExtendDB.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>

* fix(streams): answer the stream state beside an index Update

The previous commit stopped treating an index Update without
WarmThroughput as a companion of a stream change. The handler then
skipped the table read that checks the stream state. Such a request
answered "UpdateGlobalSecondaryIndex is not yet supported". The service
refuses the stream change itself when the table cannot take it. These
are a disable on a table without an enabled stream, and an enable on a
table with one. Main answered the stream state sentence.

Measured on Amazon DynamoDB on 2026-11-11 (us-east-1, a provisioned
table with one GSI):

- R9: the table's stream is disabled. An index Update of
  ProvisionedThroughput beside {StreamEnabled: false} answers "Table
  has no stream to disable: TableName: <table>". The index keeps its
  units.
- R10: the table's stream is enabled. An index Update of
  ProvisionedThroughput beside {StreamEnabled: true, StreamViewType:
  NEW_IMAGE} answers "Table already has an enabled stream: TableName:
  <table>". The index keeps its units.

The handler now reads the table once, for a companion, for an index
Update without WarmThroughput, or for one of the earlier reasons. It
checks the stream state first, then answers the companion sentence,
then runs the existing checks. R9 and R10 are rows of the F5 data
table.

The F5 file keeps one copy of each sentence: the index sentence is one
module constant, and the TableClass and WarmThroughput sentences come
from warm_throughput_helpers. The handler comment is shorter, and the
engine data table has a row for a Create beside an Update.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>

* test(streams): put the table class back to STANDARD before each F5 row

The F5 rows share one provisioned table, and each row brought only the
stream to its measured state. A row that main accepts leaves the
table at STANDARD_INFREQUENT_ACCESS, and every later refusal row then fails
its table class assertion. With main's engine handler, 6 rows failed: R5 to
R8 on their message, and R9 and R10 on the class the table-class row left
behind.

Each row now puts the table class back to STANDARD before it sends its
request, through the same _table_class reader the assertion uses. The
service refuses every row and the class stays STANDARD, so the reset never
runs there. With main's engine handler F5 now fails 4 rows, R5 to R8, on
their message. At this head the file passes: 23 passed, 2 xfailed.

* test(streams): make the index throughput xfail strict

NO_INDEX_THROUGHPUT marks R1 and R2 of F5 as expected failures while
ExtendDB does not change an index's ProvisionedThroughput (ExtendDB#716). Without
strict=True, pytest reports XPASS and passes once ExtendDB#716 lands, and the marker
stays. With strict=True that run fails and names the marker for removal.
Neither pytest.ini sets xfail_strict, so the marker carries it.

* docs(streams): name the unmeasured orders in the UpdateTable companion comment

The comment on the companion refusals listed as unmeasured only the order of
TableClass against the other sentences, and OnDemandThroughput beside a
stream change. The order of the stream state refusals against the index,
WarmThroughput and DeletionProtection sentences is unmeasured too. The
recorded rows put the stream state ahead of the IOPS sentence and ahead of a
bare index Update only.

On a table that does not exist the service answers the WarmThroughput
sentence for a stream change beside an index WarmThroughput Update. That
was measured 2026-11-25 in us-east-1, twice. It answers the IOPS sentence
there in the same way, and on an existing table the stream state refusal
still comes before the IOPS sentence. So the missing-table answer does not
settle the order on an existing table. The handler keeps the order it has
for the IOPS sentence, stream state first. No code change.

* docs(streams): list the companion refusals in the streams design doc

docs/design/07-component-streams.md said that the handler refuses any
GlobalSecondaryIndexUpdates entry beside a stream change with the index
sentence. The sentence now lists the refusals the handler gives. An index
Create or Delete gets the index sentence. An index Update that carries
WarmThroughput gets the WarmThroughput sentence. TableClass gets the
TableClass sentence. The service accepts an index Update of
ProvisionedThroughput beside a stream change, and ExtendDB answers that
request as it answers the Update alone (ExtendDB#716).

---------

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-blocker Must ship for its milestone's release v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabling a stream does not close its shards or change its status

5 participants