Repository navigation
fix(sqlite): render the stream retention cutoff in the created_at column shape - #503
Conversation
…umn shape The retention sweep deletes stream_records rows with created_at < cutoff as a text comparison. The column default writes three fraction digits (2026-10-23T14:19:07.123Z); the cutoff was RFC 3339 from the time crate, which drops the fraction on a whole second (2026-10-23T14:19:07Z) and a trailing zero (07.450 renders as 07.45Z). '.' sorts before 'Z' and '0' to '9' sort before 'Z', so every row in the cutoff's own second, and every row in a tenth whose cutoff ended in a zero, compared below it and was deleted up to 999 ms early. The cutoff is now rendered with format_epoch_millis in the same 24-character shape as the column. The sweep runs through SqliteEngine::cleanup_expired_stream_records_at(now, retention_hours), which takes the engine write lock, renders the cutoff and deletes; the trait method calls it with the wall clock and the test calls it with a fixed clock, so the production path is the one under test. Unit tests: the cutoff on a whole second renders as ...07.000Z and sorts at or below same-second rows; a cutoff at .450 keeps its three digits; a sweep over rows at 06.999Z, 07.000Z and 07.123Z with the cutoff on second 07 deletes one row and keeps both same-second rows. Closes #464
crates/storage-sqlite/src/sqlite_util.rs conflicted: both sides added format_epoch_millis. Main's version is kept. It formats the same shape and stamps a value outside the time crate's range with the current time. This branch's retention cutoff calls it unchanged. Main removed crate::schema::apply from extenddb-storage-sqlite. The retention cutoff tests now create their schema with crate::migrations::apply_for_tests, as main's other unit tests do.
crates/storage-sqlite/src/stream.rs keeps from main the move of init_stream_shards and SHARDS_PER_STREAM to stream_lifecycle.rs and the table_has_labelled_shard reader. It keeps from this branch the millisecond-shape retention cutoff, the delete helper, cleanup_expired_stream_records_at and the retention_cutoff_tests module.
demohan
left a comment
There was a problem hiding this comment.
Two items before this merges.
- No test calls
StreamEngine::cleanup_expired_stream_records, which is the method the stream cleanup worker runs (workers.rs:108). The new tests callcleanup_expired_stream_records_atdirectly. Inline comment below. sqlite_util.rs:155-161(outside the diff) still calls theformat_timestampvalue "the retention cutoff" and describes the same-second edge as current behaviour. After this change the cutoff comes fromretention_cutoff. Please remove that comment and theformat_timestampassertion, or point them atretention_cutoff.
Optional: stream.rs:270 now reads the clock before cleanup_expired_stream_records_at takes the write lock, and main took the lock first. A row written while the sweep waits on the lock is kept now and was deleted before (with retention 0: 0 deleted against 1 in the old order, 3 of 3 runs). Nothing is deleted early. A sentence in the doc comment would record the order.
Measured: on SQLite servers built from this branch and from the merge-base, the hourly worker deleted the same 6 rows from a ladder at -600, -5, -1, +1, +5 and +3600 s around its cutoff. The new cutoff orders correctly against every millisecond row in a 3000 ms grid, and the old cutoff deleted 1200 of those early. Clippy 1.97.0, fmt and the 1.88 build are clean. The workspace tests pass (82 binaries, 4961 passed).
| let result = sqlx::query("DELETE FROM stream_records WHERE created_at < ?") | ||
| .bind(&cutoff) | ||
| .execute(&self.pool) | ||
| self.cleanup_expired_stream_records_at(time::OffsetDateTime::now_utc(), retention_hours) |
There was a problem hiding this comment.
No test reaches this line. The worker calls this trait method. With this body replaced by the previous inline cutoff code, by retention_hours + 1, or by a lock followed by Ok(0), the storage-sqlite lib suite passes 313 of 313 each time. A test that calls StreamEngine::cleanup_expired_stream_records(&engine, 24) on rows stamped 24.5 h and 23.5 h before now and asserts one deletion fails under the second and third changes with left: 0, right: 1.
There was a problem hiding this comment.
Added the_worker_entry_point_deletes_only_records_past_the_retention in 5197767. It stamps one record 24.5 hours and one 23.5 hours before now, sweeps through StreamEngine::cleanup_expired_stream_records(&engine, 24) and expects one deletion. Before it, the lib suite passed with the trait method at retention_hours + 1 and with a lock followed by Ok(0). With the test, both fail with left: 0, right: 1.
…ry point The retention tests called cleanup_expired_stream_records_at with a fixed clock. The one test that called StreamEngine::cleanup_expired_stream_records, which the worker runs, checked the write lock and discarded the count. So nothing checked what that method deletes. The storage-sqlite lib tests passed with it sweeping at retention_hours + 1, and with it taking the lock and returning 0. A new test stamps one record 24.5 hours before now and one 23.5 hours before now. It sweeps through the trait method with a retention of 24 hours, and expects one deletion. The epoch_millis test in sqlite_util.rs compared a row with an RFC 3339 cutoff from format_timestamp and described its same-second edge. The sweep's cutoff now comes from retention_cutoff, so that comparison and its comment are gone. The doc comment of cleanup_expired_stream_records_at says that the trait method reads the clock before the sweep takes the lock.
|
Both items are done in 5197767.
The optional item is done too: the doc comment of |
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier review are resolved at 5197767.
the_worker_entry_point_deletes_only_records_past_the_retentionsweeps throughStreamEngine::cleanup_expired_stream_records. It fails with the cutoff shifted one hour either way (left: 0 right: 1,left: 2 right: 1) and with the sweep returningOk(0)under the lock.- The
format_timestampcomment and assertion insqlite_util.rsare gone. - The clock sentence matches the code order. With the write lock held, a record stamped as the PutItem path stamps it (
data/tx_helpers.rs) and inserted while the sweep waits stays in 10 of 10 runs at retention 0. The merge-base deletes it in 10 of 10. - Release binaries built at 45d9a76 and at this head have byte-identical
.text. Stream records from PutItem, UpdateItem and DeleteItem match the service on event names, images, fields and timestamps.
| /// lock, renders the cutoff from `now`, deletes the rows before it and | ||
| /// returns the count. The trait method calls this with the wall clock; | ||
| /// tests call it with a fixed `now` so the production path is what runs. | ||
| /// The trait method reads the clock before this takes the lock, so a |
There was a problem hiding this comment.
Optional. The sentence holds for records stamped in milliseconds, as the PutItem path stamps them. A record written through write_stream_record (line 74) carries a whole-second created_at, and at retention 0 such a record written in the cutoff's own second is deleted (3 of 3 runs). The worker always passes 24 hours, and nothing in the workspace calls write_stream_record, so no request reaches this. "a record the write path stamps while the sweep waits" would scope it.
There was a problem hiding this comment.
Right. The sentence holds for records stamped in milliseconds, which is how the PutItem path stamps them. write_stream_record has no caller in the workspace, and the worker passes 24 hours, so no request reaches the whole-second case. I'll scope the sentence to records the write path stamps in a follow-up after this PR merges, so that your approval stands.
Main is at 018715e, 5 commits after the last merge (#503, #526, #690, #765 and #774). No file has a conflict. One file changed on both sides, and git merged it with no overlap: docs/differences-from-dynamodb.md. #526 adds a Transactions section to it, and this branch changes the index key validation row. #526 puts the Return fields in the token fingerprint and gives IdempotentParameterMismatchException the service's message. #774 picks the message key per error. The commits after this merge bring the branch in line with both.
Merges main at 018715e, five commits past 6aef346: - #503: the stream retention cutoff shape on SQLite - #526: the Return fields on a TransactWriteItems token replay - #690: catalog-check matches data relations by catalog id - #765: the FilterExpression suffix in the values message - #774: the Message key on two errors No conflicts. None of the five changes a file of this branch. #774 changes crates/server/src/response.rs, which renders the errors this branch's tests assert. The key on SerializationException stays message.
Merges b9baaf5 of fix/request-nesting-depth. That commit merges main at 018715e into the other branch, five commits past 6aef346: - #503: the stream retention cutoff shape on SQLite - #526: the Return fields on a TransactWriteItems token replay - #690: catalog-check matches data relations by catalog id - #765: the FilterExpression suffix in the values message - #774: the Message key on two errors No conflicts. None of the five changes a file of this branch. #774 changes crates/server/src/response.rs, which renders the refusals that this branch's tests assert. SerializationException keeps the message key, and a refusal with an empty message still has no message key.
Merges 0986467 of fix/1195-syntax-fault-message, its merge of fix/request-nesting-depth at b9baaf5. That commit merges main at 018715e, five commits past 6aef346: - #503: the stream retention cutoff shape on SQLite - #526: the Return fields on a TransactWriteItems token replay - #690: catalog-check matches data relations by catalog id - #765: the FilterExpression suffix in the values message - #774: the Message key on two errors No conflicts. None of the five changes a file of this branch. #774 changes crates/server/src/response.rs, which renders the refusals that this branch's tests assert. SerializationException keeps the message key, and a refusal with an empty message still has no message key.
Merges 0986467 of fix/1195-syntax-fault-message, its merge of fix/request-nesting-depth at b9baaf5. That commit merges main at 018715e, five commits past 6aef346: - #503: the stream retention cutoff shape on SQLite - #526: the Return fields on a TransactWriteItems token replay - #690: catalog-check matches data relations by catalog id - #765: the FilterExpression suffix in the values message - #774: the Message key on two errors No conflicts. None of the five changes a file of this branch. #774 changes crates/server/src/response.rs, which renders the refusals and the authentication errors that this branch's tests assert. The two errors that get the Message key are not among them. A refusal with an empty message still has no message key.
Merges 54ed1f2 of fix/1257-leading-zero-numbers, its merge of fix/1195-syntax-fault-message at 0986467. That brings in fix/request-nesting-depth at b9baaf5, which merges main at 018715e, five commits past 6aef346: - #503: the stream retention cutoff shape on SQLite - #526: the Return fields on a TransactWriteItems token replay - #690: catalog-check matches data relations by catalog id - #765: the FilterExpression suffix in the values message - #774: the Message key on two errors No conflicts. None of the five changes a file of this branch. #774 changes crates/server/src/response.rs, which renders the refusals that this branch's tests assert. SerializationException keeps the message key, and a refusal with an empty message still has no message key.
Main is at 018715e, seven commits after the last merge (#432, #468, #503, #526, #690, #765 and #774). One file conflicted: crates/storage-postgres/src/data/mod.rs. #690 adds STORAGE_RELATION_PREFIX where this branch imports from_catalog_json and to_catalog_json. The merge keeps both. Main changed seven other files this branch changes, and git merged them with no overlap. The PostgreSQL query and query_scan modules keep this branch's import of parse_sk and pk_to_text from data::key_text. So the LSI index walk of #432 refuses a key that holds U+0000 as the other reads do. The AT_TIMESTAMP seek of #468 reads sequence numbers only, so the record escape does not apply to it. Main adds no catalog migration, so migration 13 keeps its number.
Resolve the Cargo.lock merge conflict with main and adapt the Cloud Bigtable storage backend to upstream changes: - Implement StreamEngine::first_sequence_number_at_or_after for AT_TIMESTAMP shard iterators (ExtendDB#468): capture (epoch_secs, epoch_millis) from a single UTC clock read (current_stream_clock / build_record_with_timestamp), persist created_at_ms on TxnStreamRecord and stream_record:* rows (falling back to ApproximateCreationDateTime * 1_000 for legacy rows and direct writes via decode_stored_record), align stream retention cleanup cutoffs to milliseconds (ExtendDB#503), and fence first_sequence_number_at_or_after, latest_sequence_for_shard, and ensure_shard_past_record against advancing or exposing records past ShardMeta.ending_sequence_number. - Add unit and live cbtemulator integration tests covering AT_TIMESTAMP millisecond boundaries, cross-shard isolation, backward clock steps, legacy row fallback, multi-page seeks, closed-shard fencing, millisecond retention pruning, and begins_with / BETWEEN near U+10FFFF and binary 0xFF across base tables, GSIs, and LSIs (ExtendDB#588). - Update docs/differences-from-dynamodb.md AT_TIMESTAMP row for all five backends.
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that carries it: the root Cargo.toml version and its 13 exact pins, the 15 workspace entries in Cargo.lock (no third-party entry changes), packaging/npm/package.json (the version and the five platform pins), the four license-notice files (regenerated with cargo-about 0.9.0), and the sample `extenddb version` and `serve` output in docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md. This is a minor release. Since v1.0.0, main has two features (#468, #1009) and changes that make ExtendDB answer as DynamoDB does, which docs/versioning.md ships in a minor release. It adds no catalog migration (RELEASED_THROUGH stays 12, the last id), no configuration key and no backup format version. Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468 (AT_TIMESTAMP, and the GetShardIterator answers it changes), #503, #544, #567, #765 and #774, #588, #596, #690, #1144, #1173 and #1194, next to the existing entries for #398 and #526. The #526 entry now gives the old TransactWriteItems mismatch message, and the entries are in PR order. Current Status, the General Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no migrate step, and a rollback runs the 1.0.0 binary on the same catalog, with the two limits the manual names (#526 tokens, and 1.0.0's catalog-check --fix). The rollback note of the KEK-file switch says that 1.0.0 serves a switched catalog. docs/manuals/11-deployment-guide.md: a sentence about the release before the one that carries #398 is gone. Signed-off-by: Scott Robinson <robinnsc@amazon.com>
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that carries it: the root Cargo.toml version and its 13 exact pins, the 15 workspace entries in Cargo.lock (no third-party entry changes), packaging/npm/package.json (the version and the five platform pins), the four license-notice files (regenerated with cargo-about 0.9.0), and the sample `extenddb version` and `serve` output in docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md. This is a minor release. Since v1.0.0, main has two features (#468, #1009) and changes that make ExtendDB answer as DynamoDB does, which docs/versioning.md ships in a minor release. It adds no catalog migration (RELEASED_THROUGH stays 12, the last id), no configuration key and no backup format version. Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468 (AT_TIMESTAMP, and the GetShardIterator answers it changes), #486, #503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173, #1194 and #1375, next to the existing entries for #398, #526 and #1166. The #526 entry now gives the old TransactWriteItems mismatch message, and the entries are in PR order. Current Status, the General Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no migrate step, the #1166 checks before a PostgreSQL upgrade, and a rollback runs the 1.0.0 binary on the same catalog, with the two limits the manual names (#526 tokens, and 1.0.0's catalog-check --fix). The rollback note of the KEK-file switch says that 1.0.0 serves a switched catalog. docs/manuals/11-deployment-guide.md: a sentence about the release before the one that carries #398 is gone.
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that carries it: the root Cargo.toml version and its 13 exact pins, the 15 workspace entries in Cargo.lock (no third-party entry changes), packaging/npm/package.json (the version and the five platform pins), the four license-notice files (regenerated with cargo-about 0.9.0), and the sample `extenddb version` and `serve` output in docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md. This is a minor release. Since v1.0.0, main has three features (#468, #1009, #1449) and changes that make ExtendDB answer as DynamoDB does, which docs/versioning.md ships in a minor release. It adds no catalog migration (RELEASED_THROUGH stays 12, the last id), no configuration key and no backup format version. Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468 (AT_TIMESTAMP, and the GetShardIterator answers it changes), #486, #503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173, #1194, #1375 and #1522, next to the existing entries for #398, #526, #1166, #1449 and #1523. The #526 entry now gives the old TransactWriteItems mismatch message, the #1523 heading takes the v1.1.0: prefix, and the entries are in PR order. Current Status, the General Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no migrate step, the #1166 checks before a PostgreSQL upgrade, and a rollback runs the 1.0.0 binary on the same catalog, with the two limits the manual names (#526 tokens, and 1.0.0's catalog-check --fix). The rollback note of the KEK-file switch says that 1.0.0 serves a switched catalog. docs/manuals/11-deployment-guide.md: a sentence about the release before the one that carries #398 is gone.
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that carries it: the root Cargo.toml version and its 13 exact pins, the 15 workspace entries in Cargo.lock (no third-party entry changes), packaging/npm/package.json (the version and the five platform pins), the four license-notice files (regenerated with cargo-about 0.9.0), and the sample `extenddb version` and `serve` output in docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md. This is a minor release. Since v1.0.0, main has three features (#468, #1009, #1449) and changes that make ExtendDB answer as DynamoDB does, which docs/versioning.md ships in a minor release. It adds no catalog migration (RELEASED_THROUGH stays 12, the last id), no configuration key and no backup format version. Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468 (AT_TIMESTAMP, and the GetShardIterator answers it changes), #486, #503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173, #1194, #1375 and #1522, next to the existing entries for #398, #526, #1166, #1449 and #1523. The #526 entry now gives the old TransactWriteItems mismatch message, the #1523 heading takes the v1.1.0: prefix, and the entries are in PR order. Current Status, the General Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no migrate step, the #1166 checks before a PostgreSQL upgrade, and a rollback runs the 1.0.0 binary on the same catalog, with the two limits the manual names (#526 tokens, and 1.0.0's catalog-check --fix). The rollback note of the KEK-file switch says that 1.0.0 serves a switched catalog. docs/manuals/11-deployment-guide.md: a sentence about the release before the one that carries #398 is gone. docs/troubleshooting.md: the bus error entry names 1.0.0 as the release that has the bug, so its line carries a version-literal-ok marker.
* chore(release): bump version to 1.1.0 Moves the workspace version from 1.0.0 to 1.1.0 on every surface that carries it: the root Cargo.toml version and its 13 exact pins, the 15 workspace entries in Cargo.lock (no third-party entry changes), packaging/npm/package.json (the version and the five platform pins), the four license-notice files (regenerated with cargo-about 0.9.0), and the sample `extenddb version` and `serve` output in docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md. This is a minor release. Since v1.0.0, main has three features (#468, #1009, #1449) and changes that make ExtendDB answer as DynamoDB does, which docs/versioning.md ships in a minor release. It adds no catalog migration (RELEASED_THROUGH stays 12, the last id), no configuration key and no backup format version. Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468 (AT_TIMESTAMP, and the GetShardIterator answers it changes), #486, #503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173, #1194, #1375 and #1522, next to the existing entries for #398, #526, #1166, #1449 and #1523. The #526 entry now gives the old TransactWriteItems mismatch message, the #1523 heading takes the v1.1.0: prefix, and the entries are in PR order. Current Status, the General Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no migrate step, the #1166 checks before a PostgreSQL upgrade, and a rollback runs the 1.0.0 binary on the same catalog, with the two limits the manual names (#526 tokens, and 1.0.0's catalog-check --fix). The rollback note of the KEK-file switch says that 1.0.0 serves a switched catalog. docs/manuals/11-deployment-guide.md: a sentence about the release before the one that carries #398 is gone. docs/troubleshooting.md: the bus error entry names 1.0.0 as the release that has the bug, so its line carries a version-literal-ok marker. * docs(upgrade): add the v1.1.0 entry of #1290, put #1349's in order #1290 merged after this branch was rebased. It changes the answer to a request with no Authorization header, so it gets a v1.1.0 entry. The merge of main put the #1349 entry after the #1523 entry. It moves to the place of its number, beside the new #1290 entry. --------- Co-authored-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
What
format_epoch_millisnow renders the cutoff in the column's 24-character shape. The sweep runs throughSqliteEngine::cleanup_expired_stream_records_at(now, retention_hours). The trait method calls it with the wall clock, and the test calls it with a fixed clock. So the path that runs in production is the one under test.Scope
SQLite only. PostgreSQL and MongoDB compare native timestamps. Cassandra writes stream rows with
USING TTL, and its sweep is a no-op by design. No migration: the column shape does not change, and rows written by older releases carry the same three digits from the column default.Why
The SQLite retention sweep (
cleanup_expired_stream_recordsincrates/storage-sqlite/src/stream.rs) deletesstream_recordsrows withcreated_at < cutoffas a text comparison. The column default writes three fraction digits (2026-10-23T14:19:07.123Z). The cutoff was RFC 3339 from thetimecrate, which drops the fraction on a whole second (...07Z) and drops a trailing zero (07.450renders as07.45Z). Since.and the digits sort beforeZ, every row in the cutoff's own second compared below the cutoff. Every row in a tenth whose cutoff ended in a zero also compared below the cutoff. The sweep deleted these rows up to 999 ms early.Closes #464
Testing done
cutoff_on_a_whole_second_keeps_the_column_shape,cutoff_with_a_fraction_keeps_the_column_shape(including the.450case), andsweep_on_a_whole_second_keeps_same_second_rows. In the sweep test the rows are at06.999Z,07.000Zand07.123Z, and the cutoff is on second07. The sweep deletes one row and keeps both same-second rows.the_worker_entry_point_deletes_only_records_past_the_retentionsweeps throughStreamEngine::cleanup_expired_stream_records, the method the retention worker runs, with a retention of 24 hours. Of a record stamped 24.5 hours before now and one stamped 23.5 hours before now, it deletes only the first. The test fails with the trait method sweeping atretention_hours + 1, and with it taking the lock and returning 0.backup_catalog::write_lock_tests, fail on the host where these ran, and they fail at the previous head 45d9a76 too.tests/test_streams.py16 passed, 1 xfail.tests/python/test_streams.py15 passed.cargo fmt,clippy1.97.0 with-D warnings, build on 1.88.0: clean.format_epoch_millis, and the merge of main in 45d9a76 keeps one definition.git merge-treeof this branch with main and with feat(streams): AT_TIMESTAMP shard iterator on all four backends #468 is clean.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.