Skip to content

fix(cassandra): a Scan reads on past rows without an item - #612

Open
LeeroyHannigan wants to merge 9 commits into
mainfrom
fix/cassandra-scan-emptied-partition
Open

LeeroyHannigan wants to merge 9 commits into
mainfrom
fix/cassandra-scan-emptied-partition

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

The branch is at 9da5dce. Three commits sit on 0a41409, the head of the last review:

  • ceee35c merges main at a417b2f (fix(storage-cassandra): extenddb destroy removes only a deployment's own keyspaces #1173). No file conflicted. crates/storage-cassandra/tests/direct_integration.rs keeps main's stream_at_timestamp module and this branch's two test modules.
  • a3057fe sends every read of a Scan storage call through the retry with half the rows, the first read included. This answers the finding in the review body. Before it, only the reads after the first one had the retry. So the first read of a second storage call, which main never makes, could fail with READ_TOO_MANY_TOMBSTONES. The commit adds a direct test of that shape. It adds read counts that fail when the read size does not double (thread 1). They also fail when a refused read does not lower the ceiling. It adds the tombstone check to the 101,000-partition test (thread 2). The direct tests now share one copy of their helpers in crates/storage-cassandra/tests/common/mod.rs.
  • 9da5dce pins the page counts of the wire test with Limit 1 and 7, and says which table the 59-item measurement read (thread 3).

The message of 967b171 gives the retry for the reads after the first read only. The message of a3057fe gives the rule at this head.

What

On Cassandra, a Scan now returns every item of a table that holds partitions whose items have all been deleted. Before, the Scan stopped early with no LastEvaluatedKey. CreateBackup, export, and the TTL backfill and audit stopped early the same way, because they page through the same storage function.

The change

crates/storage-cassandra/src/data/scan.rs decides "more pages" from the rows Cassandra returned, as #611 does for Query. A page that skipped rows can be short, but it carries a LastEvaluatedKey, and the caller reads on from its last item.

A full read in which no row holds an item has no item to continue from. Scan then reads on after the last row it read. A base-table read now also selects pk and the sort key column. After a row with a sort key (a claim row), the next read is pk = ? AND sk > ?. After a row without one (a static-only row, or any row of a hash-only table), the next read is token(pk) > token(?). The first read of a storage call takes LIMIT + 1 rows, as on main (1,000,001 with no Limit). Each further read takes up to twice as many rows as the one before, and at most max(1000, LIMIT + 1). No read goes back over rows already read.

Cassandra counts a tombstone for each deleted row in the partitions that a read passes. When those partitions held many deleted rows, a read of 1,000 rows can still reach tombstone_failure_threshold (100,000 by default). Cassandra then refuses the read with a read failure. The read runs again with half as many rows, down to one, and the later reads of the same storage call stay at that size. Every read of a storage call goes through this retry:

  • the first read from the start of the table or of a segment.
  • the first read after an ExclusiveStartKey.
  • each read after a full read of rows that hold no item.

After a first read with half the rows, a read that filled its LIMIT still returns a LastEvaluatedKey. CreateBackup, export and the TTL work read with a LIMIT of 1,001 rows. Such a first read fails on main with READ_TOO_MANY_TOMBSTONES, and here it runs again with half the rows.

Index tables never hold a row without item_data, so a read of an index table never reads on after its last row. Its reads get the retry too. Every read runs through PolicySession::run(Stmt::Read, ...), the path and the consistency level of main's other Scan reads (main's #945).

The row handling is in the new crates/storage-cassandra/src/data/rows.rs. That module parses the item a row holds (row_item) and finds the position of the last row. It also has the two-query read and the retry. The retry (read_halving) takes the read as a closure over its LIMIT. The two-query read that resumes after an ExclusiveStartKey moved there from scan_paginated, which this PR deletes. #611 uses row_item and read_halving for Query, and its branch sits on this one.

Why

This PR fixes no open issue. #611 fixes the same defect in Query.

What happened

scan.rs asks Cassandra for LIMIT limit + 1 rows and skips each row without item_data. Such rows are:

  • the static-only row Cassandra returns for a partition whose items have all been deleted, on a table with a sort key. DeleteItem sets the static column partition_max_delete_timestamp.
  • the row a TTL claim on an absent key writes, with only prepared_txn_id and prepared_txn_timestamp set, on any table.
  • the row a transaction prepare leaves when its UPDATE ... IF prepared_txn_id = null lands on an item deleted after the transaction read it.

Scan then decided "more pages" from the number of items it kept. A read that met such rows came back with fewer items than its LIMIT and no LastEvaluatedKey. So every caller took it as the end of the table.

What the service answers

Measured on 2026-10-26 in us-east-1, each case twice with the same answer:

  • At 15:29 UTC, the measurement wrote 30 live items and 100 partitions whose one item it put and then deleted. The table already held 29 other items. A Scan returns every live item with no Limit, with Limit 1, 7 and 50, and with two parallel segments at Limit 3. It does so with Select COUNT and with a FilterExpression too. Every case read with ConsistentRead, and the Scan with no Limit also read eventually consistent.
  • ScannedCount counts live items only. With Limit 1, a Scan of the table's 59 live items took 60 pages: 59 with one item and a last one with none.
  • At 16:39 UTC, two new tables (one with a sort key, one hash only) held 50 items, all deleted. A Scan of each with no Limit and with Limit 1 and 7 answers Count 0, ScannedCount 0 and no LastEvaluatedKey.

On 2026-11-24, demohan measured the wire file's table of 30 items on the service, in the review of this PR. The service answered 31 pages with Limit 1 and 5 pages with Limit 7.

Not changed here

The GSI backfill pages with token(pk) > token(last pk), as on main, so a partition that a page of 500 rows ends inside loses the rest of its rows. #611 changes this.

Merging

git merge-tree --write-tree of 9da5dce, on 2026-11-25:

Testing done

At 9da5dce, with toolchain 1.97.0 and cassandra:4.1 with PasswordAuthenticator, as in CI:

  • cargo test -p extenddb-storage-cassandra --test direct_integration with EXTENDDB_TEST_CASSANDRA=required: 280 of 281 passed (3,031.60 s). The one failure was keyspace_migrations::migrations_run_on_a_session_with_no_keyspace_and_leave_none_selected. In it, a schema change got no answer within 20 s, on a host with a load average near 30 on 16 cores. This PR does not change that migration file. The test passed when it ran alone (38.26 s).
  • The 11 new direct tests: 6 in direct/scan_rows_without_item.rs and 5 in direct/scan_sort_key_types.rs.
    • 30 live partitions among 300 emptied ones and 20 claim rows, on a table with a sort key and on a hash-only table. They are paged with no Limit and with Limit 1, 2, 7 and 50, and as two parallel segments.
    • a run of 40 claim rows inside one partition ahead of its item.
    • claim rows among items with number, binary and string sort keys.
    • a run of 5,000 emptied partitions between 5 items, 2,100 emptied partitions that each held 110 rows, and a table of 101,000 emptied partitions.
    • the review's shape: 5 items at the lowest tokens, then 300 emptied partitions of 400 deleted rows. It is read with Limit 128, then with Limit 1,024 from the returned key, then from the start with Limit 1,000.
  • Controls, each with the tests kept. With the production files of 0a41409, the test of the review's shape fails with READ_TOO_MANY_TOMBSTONES on the call after the fifth item. The other 10 pass. With main's scan.rs, 9 of the 11 fail, and the no-item-left and 101,000-partition tests pass.
  • Mutants, each on its own:
    • a refused read does not lower the ceiling. The test of the review's shape fails, with 5 range reads where it requires 6.
    • the read size does not double. The 5,000-partition test fails, with 2,504 range reads at Limit 1 where it allows 100.
    • the read size has no cap. The 5,000-partition test (2,299 tombstones in one read), the 101,000-partition test (42,510) and the review's shape (5 range reads) fail.
    • the first read from the start keeps its size when refused. The review's shape fails with READ_TOO_MANY_TOMBSTONES on the scan from the start.
  • tests/test_scan_emptied_partitions.py on a Cassandra-backed debug server of this head, with the runtime settings devtools/run-tests applies in CI: 16 passed.
  • cargo +1.97.0 fmt --all -- --check: clean. cargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets -- -D warnings, with --features extenddb-storage-cassandra/test-hooks and with --features extenddb-engine/backup-test-hooks: clean. The MSRV check, cargo +1.91.1 check -p extenddb-storage-cassandra --all-targets: clean.
  • cargo test -p extenddb-storage-cassandra --lib: 191 passed. --test consistency_policy: 10 passed.
  • python3 -m pytest --collect-only -q of tests/ (6,676 tests) and of tests/python (672): no error.
  • CI runs the direct tests in the cassandra-storage job with EXTENDDB_TEST_CASSANDRA=required. It runs the wire file in cassandra-pytest and in the SQLite, PostgreSQL and MongoDB jobs.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, 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

Breaking changes

On Cassandra, a Scan that main ended early, after rows without an item, now reads on. It can then reach a partition that holds 100,000 or more deleted rows. That read fails with READ_TOO_MANY_TOMBSTONES, and the Scan answers 500 InternalServerError where main answered 200. Main's page had no LastEvaluatedKey, so main's Scan ended there. Its answer held every item only when no item came after that point. On 2026-11-25, a table held 5 items, then 300 emptied partitions, then such a partition, then one more item, in token order. Main's Scan answered the 5 items with no LastEvaluatedKey and left out the last item. This branch's Scan answered 500. A smaller LIMIT does not avoid the failure. On 2026-11-25 at 11:52 UTC, one partition held a static column and 110,000 deleted rows. A read with LIMIT 1 that reached it failed with READ_TOO_MANY_TOMBSTONES, and so did a read of that partition alone with LIMIT 1. CreateBackup, export and the TTL work read with Limit 1,000. They fail the same way here. On main they fail too when main's first read of 1,001 rows reaches such a partition, as it did on that table.


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.

Scan skipped rows without item_data after Cassandra had applied the
LIMIT, and decided "more pages" from the items it kept. Such rows are the
static-only row of a partition whose items have all been deleted, on a
table with a sort key; the row a TTL claim on an absent key writes; and
the row a transaction prepare leaves on an item deleted after the
transaction read it. A read that met enough of them came back short with
no LastEvaluatedKey, so the Scan ended early, and so did CreateBackup,
export, and the TTL backfill and audit, which page through the same
function.

Scan now decides "more pages" from the rows Cassandra returned, so a
short page carries a LastEvaluatedKey. When every row of a full read
holds no item, Scan reads on after the last row it read: a base-table
read also selects pk and the sort key column, and the next read goes on
within the partition after a row with a sort key and from the next token
after a row without one. Each further read takes up to twice as many
rows and at most max(1000, LIMIT + 1), and no read goes back over rows
already read. Cassandra counts a tombstone for each deleted row in the
partitions such a read passes, so a continuation read that Cassandra
refuses with a read failure is read again with half the rows, down to
one, and later reads in the same call stay at that size.

The row handling, the continuation and the two-query read that resumes
after an ExclusiveStartKey are in the new data/scan_rows.rs; scan.rs
and scan_paginated use it.
Thirty live partitions among 300 emptied ones and 20 claim rows, on a
table with a sort key and on a hash-only table, paged with no Limit and
with Limit 1, 2, 7 and 50, and as two parallel segments; a run of claim
rows inside one partition ahead of its item; a run of 5,000 emptied
partitions between items, after which Cassandra's tombstones_per_read
histogram for the table must show no read of 1,500 tombstones or more;
a table with no item left; and a table of 101,000 emptied partitions,
more than Cassandra's tombstone failure threshold.

Claim rows among items with number, binary and string sort keys, read
back and bound again by the continuation; and 2,100 emptied partitions
that each held 110 rows, with one item after them in token order, which
a read of 1,000 rows cannot pass without a read failure.
Dual-target wire tests from the service measurements on 2026-10-26.
At 15:29 UTC: every live item is returned and only live items are
counted in ScannedCount, with no Limit, with Limit 1, 7 and 50, across
two parallel segments, with Select COUNT and with a FilterExpression,
on a table with a sort key and on a hash-only table. At 16:39 UTC: a
table whose items have all been deleted answers Count 0, ScannedCount 0
and no LastEvaluatedKey.
@LeeroyHannigan
LeeroyHannigan force-pushed the fix/cassandra-scan-emptied-partition branch from 1b1e814 to eaa2c83 Compare October 29, 2026 23:54
@navareamol navareamol added the v1 Needed for the 1.0 release label Nov 2, 2026
crates/storage-cassandra/src/data/mod.rs conflicted on the module list.
Main added the sk_range module and this branch added scan_rows. The
merged file declares both.
crates/storage-cassandra/tests/direct_integration.rs keeps the secret_rows module from main and the scan_rows_without_item and scan_sort_key_types modules from this branch.
… the consistency policy

Main runs every Cassandra statement through PolicySession::run, with a kind that sets its consistency level. The consistency_policy test refuses a driver call that goes around it. On main, scan.rs reads the rows after a position through query_rows, at Stmt::Read.

This branch moved those two reads to rows_of in scan_rows.rs, which called query_with_values at the default level of the driver. rows_of now runs each statement through PolicySession::run as Stmt::Read. It still returns the error of the driver, so the read again with half the rows still sees a read failure.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scan now returns every live item past emptied partitions on the shapes where main loses them. On Cassandra 4.1 builds of head and main 3534c9e and on the service in us-east-1, each shape repeated, head matches the service on items, Count, ScannedCount and the LastEvaluatedKey pattern and attribute set, and charges what main charges where both read the same items. The shapes covered S (multi-byte), N (38-digit, negative, exponent) and B (up to 1,024 bytes) sort keys and hash-only tables; emptied, partly deleted, moved and fully deleted partitions, 3,000-partition runs, partitions with 120 deleted rows and TTL claim rows; and no Limit, Limit 1 to 1,000, TotalSegments 2 to 4, COUNT, filters, GSI and LSI scans, ExclusiveStartKey on a deleted or never-written key, and the 1 MB page. Main returns 0 of 80 items at Limit 1 and 34 at Limit 50 on the sort key tables. With 200,000 emptied partitions and 5 items, a full Scan takes about 1.6 s. A short storage page carries a LastEvaluatedKey and the engine reads on, so the client gets no empty page with a key, each read starts after the last row read, and follow-on reads keep the segment's upper token bound.

fmt, the three CI clippy commands and the 1.91.1 MSRV check are clean, 178 lib tests and 323 of 324 direct tests pass (the other is a restore race this PR does not touch, which passes alone), the wire file passes 16 of 16 twice on Cassandra, SQLite, PostgreSQL and the service and fails 5 on main, CI is green with the direct and wire tests run, the merge with main is clean, and each part of the fix is caught by a test when broken.

I will approve once the first read of each call is retried and capped like the follow-on reads, with a test of this shape.

crates/storage-cassandra/src/data/scan.rs:204

The first read of each storage call goes out without the half-size retry or the ceiling, including the LIMIT 1025 read that resumes after the engine's cursor. Main never made that read: has_more = full || ... (:276) now returns a key after a short first read, and the engine reads its next chunk in the same request. With 5 live items at the lowest tokens followed by 300 partitions of 400 deleted rows each, Scan {ConsistentRead: true, Select: COUNT} with no Limit answers 500 InternalServerError on head, twice, with scan_next_partitions ... READ_TOO_MANY_TOMBSTONES in the log; ALL_ATTRIBUTES fails the same way. Main answers Count 5 and ScannedCount 5 with no key, as the service does. Limit 1, 5 and 100 agree on all three. With 300 live items among 3,000 partitions of 150 deleted rows, no Limit, Limit 1000, COUNT and CreateBackup answer 500 on head; main answers 200 with wrong counts. Sending the first read through read_after_position's retry and ceiling returned 300 of 300 on each, and a restored backup held 300 of 300. The body's "the first read fails where main fails" and the bound in the scan_rows.rs:11 doc follow from the same change.

body.message
);
*limit /= 2;
*ceiling = *limit;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test pins the two read-size rules: with *ceiling = *limit; removed, or the doubling at scan.rs:258 removed, all 10 new tests pass. Without the ceiling, Cassandra logged the tombstone failure 9 times in one run instead of 2.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a3057fe adds two checks that count range reads in system_views.local_scan_latency, which counts a refused read too.

test_scan_past_a_long_run_of_emptied_partitions now requires each pass over the 5,000 emptied partitions to take at most 100 range reads (53 with Limit 1). With the doubling removed, the Limit 1 pass takes 2,504 and the test fails.

test_scan_after_items_past_partitions_with_many_deleted_rows requires 6 range reads for the call after the fifth item: 1,025, 512 and 256 rows refused, then 128, 128 and 44. With *ceiling = *limit; removed, the read after the first 128 rows takes up to 256 rows, the call makes 5 reads, and the test fails.

/// `tombstone_failure_threshold` (100,000 by default). Each read of the run
/// stays below it, so the scan answers no item and no key.
#[tokio::test]
async fn test_scan_of_a_table_emptied_past_the_tombstone_threshold() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 101,000-partition test passes on main, with the cap removed and with the retry disabled, so "each read of the run stays below it" is not checked. Asserting the read sizes, or a shape that fails without the cap, would hold it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a3057fe adds the tombstones_per_read check to the 101,000-partition test, after its two scans: no read may count 1,500 tombstones or more. With no cap on the read size (.min(ceiling) removed), the histogram's largest read is 42,510 tombstones and the test fails. The test still passes on main, which makes one read of 1,001 rows here.

assert len(pages) == 1
assert (pages[0]["Count"], pages[0]["ScannedCount"]) == (30, 30)
assert sorted(pks) == LIVE

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test checks the first page only. On this file's table of 30 items the service answers 31 pages at Limit 1 and 5 at Limit 7, and head gives the same pages, so the page count can be pinned. The docstring's "59 items took 60 pages" describes a table the file does not build.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9da5dce pins the page counts from your measurement on the service: 31 pages with Limit 1 and 5 with Limit 7. The test's docstring cites your review. Limit 50 has no measurement of its page count, so the test does not pin one. The module docstring now says which table the 59-item measurement read. The measurement wrote 30 live items and 100 emptied partitions into a table that already held 29 other items.

The merge brings main to a417b2f (#1173). Git merged it with no
conflict. crates/storage-cassandra/tests/direct_integration.rs keeps the
stream_at_timestamp module from main and the scan_rows_without_item and
scan_sort_key_types modules from this branch.
…rows

This branch returns a LastEvaluatedKey after a page that rows without an
item left short, when the read filled its LIMIT. The engine then reads its
next chunk in the same request, with a second storage call from the last
item. The first read of each storage call went out once, with no retry at
half the rows and no lowered ceiling. So the second call's first read could
pass more deleted rows than Cassandra allows in one read. One table held 5
items at the lowest tokens, then 300 emptied partitions of 400 deleted rows
each. There, the call after the fifth item failed with
READ_TOO_MANY_TOMBSTONES, and the engine answers that as 500. On main, the
first call returns no key after that short page. So a Scan with no Limit
answers Count 5 and makes no second call.

Every read of a Scan storage call now goes through the same retry. That
includes the first read from the start of the table or segment and the
first read after an ExclusiveStartKey. It also includes each read after a
full read of rows that hold no item. Cassandra can refuse a read with a
read failure. The read then runs again with half the rows, down to one, and
the later reads of the call stay at that size. The rule in 967b171 retried
only the reads after the first one. After a first read at half the rows, a
read that filled its halved LIMIT still returns a LastEvaluatedKey.

The retry (rows::read_halving) takes the read as a closure over its LIMIT.
data/scan_rows.rs is now data/rows.rs, with the parse of the item a row
holds (row_item), which Query can use too. scan_paginated and
rows_no_values are gone. Their reads go through rows::scan_rows.

Tests:

- The shape above as a direct test. It fails with READ_TOO_MANY_TOMBSTONES
  on 0a41409. It also checks that the call after the fifth item makes 6
  range reads (3 refused, then 128, 128 and 44 rows). When a read failure
  does not lower the ceiling, the read after the first 128 rows takes up to
  256 rows. It reads the last 172 partitions at once, the call makes 5
  reads, and the test fails. Last, the test scans from the start with Limit
  1,000, the Limit of CreateBackup. Cassandra refuses the reads of 1,001
  and 500 rows, and the read of 250 rows returns the 5 items with a key.
  With no retry of that first read, the call fails with
  READ_TOO_MANY_TOMBSTONES.
- The run of 5,000 emptied partitions counts the range reads of each pass:
  at most 100 (53 with Limit 1). With reads that do not double, the Limit 1
  pass takes 2,504.
- The 101,000-partition test checks the tombstones_per_read histogram. With
  no cap on the read size, the histogram's largest read is 42,510
  tombstones and the test fails.
- The direct tests share one copy of their helpers in tests/common/mod.rs.
On the file's table of 30 items, the service answers 31 pages with Limit 1
and 5 pages with Limit 7. The review of #612 measured this on 2026-11-24.
The test now checks both counts. Limit 50 has no such measurement, so the
test does not check its page count.

The module docstring now says which table the 59-item measurement read.
The measurement wrote 30 live items and 100 emptied partitions into a table
that already held 29 other items.
LeeroyHannigan added a commit that referenced this pull request Nov 25, 2026
…query-emptied-partition

The merge brings #612's branch at 9da5dce, which merges main at
a417b2f (#1173). Git merged it with no conflict. In
crates/storage-cassandra/src/data/query.rs, this branch's skip of rows
without item_data and its "more pages" rule sit next to main's sort key
range (sk_range.rs). In data/ddl.rs, the backfill's skip of such rows sits
next to main's batch builder and version stamps.
crates/storage-cassandra/tests/direct_integration.rs keeps the modules of
both branches and of main.
LeeroyHannigan added a commit that referenced this pull request Nov 25, 2026
…an item

In 9c1e6af, Query read the partition again from the same start when no
row of a full read held an item. The new read had twice the LIMIT, and
Query did so again while every row held no item. Each wider read went back
over the rows of the read before it, and the last one returned every row
up to its LIMIT. One partition held 1,030 rows without an item ahead of 300
items. There, a Query with Limit 128 made a read of LIMIT 2,049, which
returned all 1,330 rows of the partition.

Query now reads on after the last row's sort key, through the retry of
data/rows.rs that #612 adds for Scan. A base-table read also selects the
sort key column. The next read is `sk > ?` forward and `sk < ?` backward,
and it keeps the key condition's bound on the far side. Each further read
takes up to twice as many rows as the read before, and at most
max(1000, LIMIT + 1). Cassandra can refuse a read with a read failure. The
read then runs again with half the rows, down to one, and the later reads
of the call stay at that size. No row is read twice. Index tables never
hold a row without item_data, and their reads are unchanged.

The message of 1df5da3 says that a TTL claim or a transaction prepare on
an absent key writes a row with only prepared_txn_id set. A prepare on an
absent key writes item_data with the JSON of the key (prepare_item in
transactions.rs). The rows without item_data are these:

- the static-only row of a partition whose items have all been deleted,
  on a table with a sort key.
- the row a TTL claim on an absent key writes, with only prepared_txn_id
  and prepared_txn_timestamp set.
- the row a transaction prepare leaves when its
  `UPDATE ... IF prepared_txn_id = null` lands on an item deleted after
  the transaction read it.

The comment in query.rs and the doc of the direct test module now name
these rows. Query parses a row with row_item from data/rows.rs, and the
direct tests use the helpers in tests/common/mod.rs.

Tests:

- Limit 1 over 3,000 rows without an item: 11 reads of the data table
  (13 with 9c1e6af's read again from the start).
- 1,030 and 3,500 such rows ahead of 300 items, Limit 128: the
  rows_per_read histogram shows no read of more than 1,000 rows. With
  9c1e6af, one read returned 1,330 rows. With no cap on the read size,
  the fifth read in the second shape returns 1,865 rows.
- 2,100 such rows, each followed by 110 deleted rows, read with Limit 1.
  Cassandra refuses the read of 1,000 rows. The read of 500 rows passes,
  and the Query answers the first item. With 9c1e6af, the Query fails
  with READ_TOO_MANY_TOMBSTONES.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

a3057fe sends every read of a Scan storage call through the retry with half the rows. That covers the first read from the start of the table or segment and the first read after an ExclusiveStartKey. It also covers each read after a full read of rows that hold no item. When Cassandra refuses a read with a read failure, such as READ_TOO_MANY_TOMBSTONES, the read runs again with half the rows. The later reads of the call stay at that size. After a first read with half the rows, a read that filled its LIMIT still returns a key.

The direct test test_scan_after_items_past_partitions_with_many_deleted_rows builds your shape: 5 items at the lowest tokens, then 300 partitions of 400 deleted rows. Limit 128 returns the 5 items with a key, and Limit 1,024 from that key returns no item and no key. At 0a41409 the second call fails with READ_TOO_MANY_TOMBSTONES. The test also scans from the start with Limit 1,000, the Limit of CreateBackup, and gets the 5 items after two refused reads.

The body no longer says that the first read fails where main fails. The module doc of data/rows.rs (formerly scan_rows.rs) states the new rule.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first read of each call is retried and capped like the follow-on reads at 9da5dce, and a test of the review's shape holds it.

  • On a Cassandra 4.1 node with CI settings, 5 items at the lowest tokens followed by 300 partitions of 400 deleted rows, this head answers 15 of 15 Scan shapes as the service does in us-east-1, twice, and 15 of 15 again with one more item after the deleted rows; ConsistentRead with Select: COUNT answers Count 6 here and on the service, where 0a41409 answers 500 and main Count 5. 300 items among 3,000 partitions of 150 deleted rows answer 7 of 7 shapes, 300 of 300 items, and CreateBackup and restore keep every item. The log shows the first read from the start refused at 1,001 and 500 rows and the read after an ExclusiveStartKey at 1,025, 512 and 256, each read again with the same statement kind, error class and segment bounds.
  • test_scan_after_items_past_partitions_with_many_deleted_rows fails with the reviewed files, and when either kind of first read skips the retry; removing *ceiling = *limit;, the doubling or the cap fails the read-size and 101,000-partition tests. The wire file's 31 pages at Limit 1 and 5 at Limit 7 are the service's, measured again twice, and an engine that carries a key only when storage reports more fails it. The wire file passes 16 of 16 on the service, on Cassandra and on SQLite.
  • Round 1's 97 shapes over S, N and B sort keys, GSI, LSI and emptied tables answer as before. fmt, the three clippy commands, the 1.91.1 check, 191 lib and 10 consistency tests are clean, and CI is green apart from wasm, which fails building main's crates/core changes from #398.

def test_scan_pages_through_every_item(dynamodb_client, table, limit):
"""On this file's table of 30 items, the service answers 31 pages with
Limit 1 (30 with one item and a last one with none) and 5 pages with
Limit 7, measured in the review of #612 on 2026-11-24

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional. The docstring can state the measurement without the review link, and Limit 50 measures 1 page on the service, twice, so it can be pinned too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the approval. Both stay as they are in this PR. The docstring and a Limit 50 row are test text, and neither changes what a Scan answers. A push for them would reset your approval and change no answer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants