Repository navigation
fix(streams): disabling a stream closes its shards; enabling makes a new one - #515
Conversation
|
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 So on the merged tree the count of transacted writes acked before |
a484b48 to
5f22dc4
Compare
robinnsc
left a comment
There was a problem hiding this comment.
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_recordsall auto-merge main's body with no conflict marker, ending in main'sshard_in_stream, which istable_label == Some(arn_label). Main'shandle_get_recordsalso no longer callsvalidate_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_streamon top ofparse_shard_idwould fix it: a labelled id matches its own label, a legacy id matches when the ARN is the current label. The wire file's_rereadcatches it, but no Rust test does. - Cassandra: main's private
stream_table_rowand this PR'sstream_table_rowinstream_lifecycle.rs:387collide (E0592). Main'sget_stream_recordstakesstream_arn, which breaksread_allintests/direct/stream_disable.rs:96. Main's records query keys on the client's shard id, which returns nothing for labelled ids. Sincephysical_shard_idonly 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.pyhas 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| SHARD_ID_TOO_SHORT.to_owned(), | ||
| )); | ||
| } | ||
| if shard_len > SHARD_ID_MAX_LEN { |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
| /// 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> { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>
|
@jcshepherd I merged main in (6164f06) and added one follow-up commit (8f5d98d). These are the conflict resolutions and the changes the merge needed:
One gap is older than the merge: no filter in 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.
|
@jcshepherd I merged main in again (c74eba2) and added one fix (23a02ea). CI passes on 23a02ea. Merge notes:
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 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
left a comment
There was a problem hiding this comment.
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.
|
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
|
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.
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.
…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>
…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>
…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>
Summary
UpdateTable StreamEnabled=falseleft the streamENABLEDwith 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 anEndingSequenceNumber,DescribeTablewithoutStreamSpecification,LatestStreamArnstill 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 theshardId-{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 inextenddb_storage::stream_lineage; each backend has astream_lifecycle.rsthat 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:
DescribeStreamreportsDISABLEDwith the stream's own view type; each shard'sEndingSequenceNumberis its last record's sequence number, or its starting number when empty;DescribeTableand theUpdateTableresponse omitStreamSpecification;LatestStreamArnkeeps the closed stream. Writes record only to open shards.ListStreamslists both, newest first; a shard id of one stream on the other's ARN isRequested resource not found: Shard does not exist.Table already has an enabled stream: TableName: <name>;Table has no stream to disable: TableName: <name>; a stream change besideBillingModeorProvisionedThroughput(You cannot modify stream status while updating table IOPS), besideGlobalSecondaryIndexUpdates(You cannot create or delete index while changing stream status), besideDeletionProtectionEnabled(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);CreateTablewith a stream enabled and no view type (Table is being created with a stream enabled, UpdateViewType is required); aStreamSpecificationobject withoutStreamEnabled(the model's null-member sentence); a table created with{StreamEnabled: false}stores nothing of it.ListStreamscarriesLastEvaluatedStreamArnwheneverLimitcut the page, refuses a start ARN of another table,Limitunder 1 and a start ARN under 37 characters;GetShardIteratorrefuses aShardIdunder 28 or over 65 characters and aSequenceNumberunder 21, answersAT_SEQUENCE_NUMBERwithout a number withSequenceNumber cannot be nulland an unknown stream ARN withStream does not exist;DescribeStreamrefuses a shortExclusiveStartShardIdand answers an unknown stream of an existing table withStream: <arn> not found.Consistency under concurrency
DISABLEDlands before the ending number. On PostgreSQL the write path reads the open shards without a lock, locks the one shard its record goes toFOR KEY SHAREwhile re-checking that it is still open, and the close locks the open rowsFOR UPDATEbefore 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).DISABLEDstream has every shard closed (0 of 60 rounds on PostgreSQL and 0 of 30 on MongoDB; before: 11 of 30 and 2 of 30).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.{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,GetRecordsand 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:DescribeStreamanswersStream: <arn> not found,ListStreamsomits it, and an iterator still reading it answersStream 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.
DescribeBackupfor a backup taken after a disable keeps showingStreamDescription: {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
GetRecordsread, with the table's one label deciding ownership. This branch is re-cut on top of it:extenddb_storage::util.GetShardIteratorwith a shard of the table's other stream, or a well-formed shard id the stream never had, answersRequested resource not found: Shard does not exist(both measured 2026-10-24); main answeredStream: <arn> not found.with a period there.util::shard_in_streamreads 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, asGetShardIteratorrefuses the same pairing. The labelled-shard check runs only for a legacy id: anEXISTSonstream_shardson SQLite and PostgreSQL (byte order,COLLATE "C"on PostgreSQL), afind_oneon 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.get_stream_recordskeeps main's ownership check (the shard row's table id andshard_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. Onestream_table_row.constrainthelper beside the shard id length constants.Review changes
GetShardIteratorapplies the 65-characterShardIdmaximum only when the shard is not found, so theshardId-{table_name}-{index:016}shards of a table named with more than 40 characters stay readable.StreamSpecificationthat is not an object keepsSerializationExceptionfrom deserialisation; the null-member check applies to objects.FOR KEY SHAREinstead of all fourFOR SHARE(above).{table_id: 1, shard_id: 1}index onstream_shards: the open-shard read on every write to a streamed table, and the shard reads behindDescribeStream,GetShardIteratorandListStreams, otherwise scan the whole collection.extenddb initcreates it; an existing deployment gets it fromextenddb migrate --yes, which reports it pending while it is missing.{StreamEnabled: false}with the view type, omitted from responses) instead of "clears the specification".Tests
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 withtest_stream_shard_ownership.py,test_streams.pyandtest_streams_transactions.pygive 71 passed, 4 xfailed on each of SQLite, PostgreSQL, MongoDB and Cassandra (the fourGetRecordsterminal-page rows wait on End GetRecords iterators after closed shard exhaustion #372's rule; every other assertion in them runs). Onmainat 1d0d8f4, the first file, at 21 rows, fails 14 against a SQLite server (3 pass, 4 xfail).extenddb-storage --lib158 (stream_lineage15,shard_stream7);extenddb-storage-sqlite --lib169, 1 ignored (stream_lifecycle4,stream_tests10);extenddb-storage-postgres --test stream_disable5 (lifecycle, scope, the write race, an enable closing an earlier stream left open, a disable applying after an overlapping enable) and--test stream_disable_legacy2 (the legacy upgrade, the refused disable of a disabled stream),stream_shard_ownership6,stream_records_page_order1,stream_shard_retention1,table_snapshot81;extenddb-storage-cassandra --test direct_integrationstream_disable2,stream_endings2,stream_ownership3,streams14;extenddb-storage-mongodblive tests 9 (#[ignore]without a server).cargo fmt,clippy1.97.0 with-D warningson every target,checkon 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.rsand Cassandra'sstream_lifecycle.rswere 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.a42aeb77cafter one rerun each of the Test and Cassandra jobs. The first runs failedshape_gate_tests::serve_refuses_a_file_database_with_pending_shape_migrations(SQLite answered "database is locked" to the test'sALTER TABLE) andtests/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
mainat 1d0d8f4 after #543 (877ef39); see the section above. #372 (endGetRecordsiterators 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:DescribeStreamomitsCreationRequestDateTimeon 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 onUpdateTable(StreamViewType must be specified when StreamEnabled is truehere,If stream is being enabled then UpdateViewType is requiredon the service); the undefined-index-key sentence;AT_SEQUENCE_NUMBERpast 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 ExtendDBUpdateTableanswersTableStatus UPDATING, so the twoUpdateTableresponses sayACTIVEwhere the service saysUPDATING.A drained closed shard keeps returning
NextShardIterator(#372). Closed streams and their shard rows are never removed while the table exists, soListStreamsandDescribeStreamkeep 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 fromNEW_AND_OLD_IMAGEStoKEYS_ONLYand 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