Skip to content

fix(storage-cassandra): retry a lost UpdateItem version check over the PutItem and DeleteItem window - #1531

Merged
navareamol merged 8 commits into
mainfrom
fix/878-cassandra-update-retry
Dec 3, 2026
Merged

navareamol merged 8 commits into
mainfrom
fix/878-cassandra-update-retry

Conversation

@navareamol

@navareamol navareamol commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

What

The Cassandra UpdateItem loop retries a lost version check after a random sleep. The sleep window grew from 2 ms to a cap of 16 ms. PutItem and DeleteItem retry their version check over a window that grows from 4 ms to a cap of 256 ms. UpdateItem now uses that window.

  • crates/storage-cassandra/src/data/delete_item.rs: the window math of ttl_claim_backoff moves into ttl_claim_window_ms(attempt), and the jittered sleep into a private sleep_below(window_ms). ttl_claim_backoff is sleep_below(ttl_claim_window_ms(attempt)). PutItem and DeleteItem sleep exactly as before.
  • crates/storage-cassandra/src/data/update_item.rs: OCC_BASE_DELAY_MS and OCC_EXP_CAP are gone, and UpdateItem has no window function of its own. The three sleep sites of the loop call one function, occ_backoff(account_id, attempt), which sleeps through ttl_claim_backoff, the function PutItem and DeleteItem use, and returns the window. The windows cannot drift apart. Two unit tests pin the window.
  • crates/storage-cassandra/src/test_hooks.rs: five test-only functions (compiled with test-hooks, no-ops otherwise) lose every version check or every TTL claim of one account in update_item_impl, and record the windows of its sleeps with the sleeps skipped.
  • crates/storage-cassandra/tests/direct/update_item_retry.rs: three direct tests, one per sleep site, make a call lose all 21 attempts and check the sleeps (below).
  • docs/adr/0020-cassandra-occ-update-item.md: the retry policy of update_item_impl gives the shared window (4 ms doubling to 256 ms), and the consequences line names 256 ms for both loops.
  • docs/manuals/07-upgrade-manual.md: a v1.2.0 entry says that the sleeps of one UpdateItem on a contended item can reach about 3.8 s (286 ms in all before), and that a call that still runs out took 2.87 to 4.52 s in a reviewer's runs, for clients with timeouts near 2 s.
  • UpdateItem keeps 21 attempts (OCC_MAX_RETRIES = 20). PutItem and DeleteItem keep 9 (TTL_CLAIM_MAX_RETRIES = 8). The attempt counts stay different on purpose: only the window is shared.

Paths that get the new window:

  • the UpdateItem API (crates/engine/src/update_item.rs, handle_update_item_with);
  • PartiQL UPDATE, which calls the same handler (crates/engine/src/partiql/write/update.rs:88);
  • all three retry sites of the loop: a lost version check, a row held by another owner on a TTL table, and a lost TTL claim on a TTL table.

Transactions (data/transactions.rs) do not use this loop. The five-server stress and the one-server runs used a table without TTL. The TTL sites are covered only by the direct tests below, which force the losses and check the sleeps, not the timing under load.

Why

Refs #878

tests/python/test_rfc0003_concurrency.py::TestRfc0003AtomicCounterAdd::test_all_increments_apply sends 1,000 UpdateItem ADD calls on one item from 50 threads, with SDK retries off, and asserts that no call fails. The issue records one failure of it in the cassandra-pytest job of run 42090954764 (job 127468512700): unexpected errors: ['TransactionConflictException']. The issue records no server log for that job, so I cannot say the CI failure was an exhausted loop.

On a table with no TTL, update_item_impl answers TransactionConflict("update_item: too many concurrent writers on this item") once all 21 attempts lose the version check.

Attempt counts

These runs used builds that print, for each UpdateItem call, the zero-based attempt index at which it applied and its time in the loop, or exhausted (patch below, not committed). The setup is one Cassandra 4.1 node with a 1 GB heap and five ExtendDB servers on it, each running the test 10 times at the same time (commands below).

Build Passes Runs failed Calls Calls that used all 21 attempts Highest index that applied (last allowed 20) Slowest applied call
main 5252eda 2 15 of 100 100,000 144 20 2,019 ms
this branch 2 0 of 100 100,000 0 15 2,286 ms

Each failed run on main failed with TransactionConflictException only. The exhausted calls on main took 595 ms to 1,602 ms in the loop.

On one server alone, main reached attempt index 15 of 20 in 20,000 calls and did not fail. Every exhausted call I saw was in the five-server runs. How busy the CI runner was when #878 failed is not recorded.

Pass and fail counts at similar load

Back to back on the same desktop, release builds without the print. One pass is 50 runs. The load column is the highest one-minute load average sampled every 10 s during the pass.

Order Build Runs failed Peak load
1 main (with print) 7 of 50 11.2
2 branch (with print) 0 of 50 9.9
3 branch 0 of 50 8.6
4 main 0 of 50 7.9
5 main 4 of 50 8.9
6 branch 0 of 50 7.7
7 main (with print) 8 of 50 10.1
8 branch (with print) 0 of 50 6.6

Main failed 19 of 200 runs and the branch 0 of 200. The failure rate of main moves with load (pass 4 had none), so these counts show that the change reduces the failures. They do not show that it removes them.

Earlier passes on the first commit of this branch, at load I did not record per pass, had 1 failing run in 100 without the print. That run answered one InternalServerError and one TransactionConflictException. The InternalServerError came with occ_write lwt: IO error: failed to fill whole buffer in the server log. That build had no print, so I cannot say whether the conflict was an exhausted loop. Separately, 135 runs (135,000 calls) of the first commit with the print, in passes not counted above: 0 exhausted calls, highest index 16.

The first commit's message is out of date and should not go onto main. It says "19 of 50 before" and "0 of 50 after it", and that retries "met again". The counts are the ones in this description, and the "met again" cause was never measured. The squash message should be built from this description, not from that commit's message.

Time spent before giving up

The loop sleeps after each lost attempt except the last: 20 sleeps, each uniform below the window.

  • Before: windows 2, 4, 8, then 16 ms. The windows add up to 286 ms. A sleep is below its window, so the real most is 266 ms, about 133 ms on average.
  • After: windows 4, 8, 16, 32, 64, 128, then 256 ms. The windows add up to 3,836 ms. The real most is 3,816 ms, about 1.9 s on average.
  • PutItem and DeleteItem, unchanged: 8 sleeps, windows adding up to 764 ms.

These are sleeps only, and the 3,836 ms is a bound on sleep, not on the time of a call. It holds when the node answers each read and lightweight transaction quickly. They also apply to the TTL-claim retries at the other two sleep sites.

A reviewer measured a slower node, with Cassandra limited to 2 CPUs. There a call that ran out of attempts spent 2,775 to 7,790 ms in the loop, and the slowest call that applied took 8,900 ms. The same review measured, for calls that ran out of attempts per 50,000: 958 on main and 0 on this branch with Cassandra at 4 CPUs (38 of 50 runs failing on main, 2 of 50 here, both InternalServerError), and 1,957 and 3,099 on main against 108 and 64 here at 2 CPUs. At 2 CPUs every run here still failed, mostly with InternalServerError from occ_write lwt: IO error. This change does not touch that error. It is the lost-answer case of #1401. I did not measure the 2-CPU numbers.

Each attempt also costs a read and a lightweight transaction, which these numbers leave out. In the runs above the slowest call that applied on the branch took 2,286 ms in the loop.

I found nothing on the server that caps the time a handler runs. request_timeout_secs (crates/config/src/lib.rs:81-86, default 30) bounds the wait for request headers and the gaps in a request body (RequestBodyTimeoutLayer in crates/server/src/lib.rs:259, and the first-byte and header timeouts in crates/server/src/listener.rs). The other server layers (crates/server/src/lib.rs:244-259) set headers or refuse requests before the handler.

Count or time bound

The issue asks for a bound by time instead of by attempts. I kept the count, because the count already bounds the sleep at 3,836 ms, and the measurements give no time that a wall-clock bound should cut at. In 235,000 calls with the print on the two commits of this branch, none used all 21 attempts. In the 100,000 of them that also printed the time, the slowest call that applied took 2,286 ms. A bound below that would turn calls that apply into errors. A bound above about 4 s would not end the loop before the count does, unless reads or lightweight transactions were slow.

Testing done

Dev desktop, release builds with --no-default-features --features cassandra, Cassandra 4.1 container shared with other work.

Check Result
cargo fmt --check clean
cargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets -- -D warnings clean
cargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets --features test-hooks -- -D warnings clean
cargo +1.97.0 test -p extenddb-storage-cassandra --lib, with and without --features test-hooks 194 passed each (one test binary), including the 2 unit tests (195 before the drift test went)
Unit tests, with the old window constants (control 1) 2 failed
--features test-hooks --test direct_integration update_item_retry, 20 runs 20 of 20 passed, 3 tests each, 47 to 52 s a run; my keyspaces dropped every 4 runs, no out-of-heap in the node's log
Direct tests with the sleep sites and hooks mutated (controls below) A, B1 to B3, C1 to C3, D1, D3 fail as expected; D2 and E pass, as explained
Target test, one server, release build of the head, 20 runs 20 passed, each 3.3 s to 5.0 s
Whole module test_rfc0003_concurrency.py, release build of the head 4 passed in 11.70 s (main: 4 passed in 11.86 s, measured on the first commit's base)
Five-server stress, back to back tables above, measured on the first two commits; the later commits change no window
After the rebase on main 1be1012: fmt, clippy (with and without test-hooks), --lib tests clean, clean, 194 passed

Main also passes the one-server 20-run row and the module row, so those rows show no regression, not the fix. The fix shows only in the five-server tables.

Not run: an MSRV 1.88 build, the Windows target check, the other three backends (the change is in the Cassandra crate only), and any TTL table. The TTL-claim retries in UpdateItem now sleep up to 16 times longer, and no run measured them under load.

The new unit tests:

  • window_starts_at_4_ms_and_stops_at_256_ms: ttl_claim_window_ms at attempt 0, 6 and 20.
  • retry_windows_add_up_to_3836_ms: the 20 windows add up to exactly 3,836 ms.

They pin the window, not the outcome under contention. They do not show that the loop sleeps in it.

The three direct tests in update_item_retry.rs do. Each makes one call lose every attempt and compares the windows of its 20 sleeps with 4, 8, 16, 32, 64, 128 and then 256 ms 14 times (3,836 ms in all), and checks that the call answers TransactionConflict. The hook records the windows and skips the sleeps, so a test takes the time of 21 reads, not 3.8 s.

Test What loses every attempt Sleep site
lost_version_checks_sleep_in_the_shared_window hook: the write reports a lost version check, table without TTL after the lost write, update_item.rs:280
lost_ttl_claims_sleep_in_the_shared_window hook: the TTL claim reports a held claim, TTL table after the lost claim, update_item.rs:225
a_held_ttl_claim_sleeps_in_the_shared_window no hook: the test holds a real TTL claim on the item, TTL table after the read that finds the claim, update_item.rs:126

All three sites are reached. The first two need a hook, because a lost version check or a lost claim cannot be made certain on a live node without one.

The tests check the window each site records and that each site calls occ_backoff. The sleep itself is ttl_claim_backoff, the function PutItem and DeleteItem use. A change inside occ_backoff that sleeps in another window but records the shared one passes (control E).

Negative controls, each run on the committed tree and reverted with git checkout -- afterwards (git status --short empty after each). A control counts when the tests fail on an assertion about the sleeps or the call's answer.

Control Mutation Direct tests Result
A all three occ_backoff calls removed 3 failed, left: [] fails as expected
B1 read site sleeps in the old 2 ms to 16 ms window only a_held_ttl_claim_sleeps_in_the_shared_window failed, left: [] fails as expected
B2 claim site, old window only lost_ttl_claims_sleep_in_the_shared_window failed, left: [] fails as expected
B3 write site, old window only lost_version_checks_sleep_in_the_shared_window failed, left: [] fails as expected
C1, C2, C3 read, claim or write site calls ttl_claim_backoff directly, skipping occ_backoff only the test of that site failed, left: [] fails as expected
D1 the hook that loses a write or a claim reports nothing lost the two hook tests failed: a call that loses every attempt must give up with TransactionConflict, got Ok((None, None)) the hook matters
D2 the sleep hook records the window but does not skip the sleep 3 passed, each run 52 s passes: the windows are still recorded, and the sleeps then run for real. The test is only slower. Pair with D3
D3 the sleep hook does not record 3 failed, left: [] the record matters
E occ_backoff sleeps in the old window but records ttl_claim_window_ms 3 passed passes: not caught by design, see above

Control 1, the old window constants in delete_item.rs (unit tests: left: 286, right: 3836 and left: 2, right: 4). It also changes the window of PutItem and DeleteItem, so it pins the constants for all three:

--- a/crates/storage-cassandra/src/data/delete_item.rs
+++ b/crates/storage-cassandra/src/data/delete_item.rs
-const TTL_CLAIM_BASE_DELAY_MS: u64 = 4;
-const TTL_CLAIM_EXP_CAP: u32 = 6;
+const TTL_CLAIM_BASE_DELAY_MS: u64 = 2;
+const TTL_CLAIM_EXP_CAP: u32 = 3;

Controls B1 to B3 replace occ_backoff(&key_info.account_id, attempt).await; at one site with tokio::time::sleep(std::time::Duration::from_millis(rand::random::<u64>() % (2 * (1u64 << attempt.min(3))))).await;. A removes the three calls. C1 to C3 replace one with ttl_claim_backoff(attempt).await;. D1 makes take_loss return false where it returns true. D2 makes update_item_sleep_skipped return false after windows.push(window_ms);. D3 replaces windows.push(window_ms); with let _ = windows;. E replaces ttl_claim_backoff(attempt).await; inside occ_backoff with the old-window sleep. The failing text of A, B, C and D3:

assertion `left == right` failed: the sleeps of a call that loses every attempt
  left: []
 right: [4, 8, 16, 32, 64, 128, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256]

The print, applied to main and to this branch for the attempt table (measurement only; abridged, apply it by hand):

--- a/crates/storage-cassandra/src/data/update_item.rs
+++ b/crates/storage-cassandra/src/data/update_item.rs
+        let occ_t0 = std::time::Instant::now();
         for attempt in 0..=OCC_MAX_RETRIES {
             // --- READ ---
@@
             if applied {
+                eprintln!("OCCATT {attempt} {}", occ_t0.elapsed().as_millis());
                 return Ok((old_item, new_item));
@@
+        eprintln!("OCCATT exhausted {}", occ_t0.elapsed().as_millis());
         Err(StorageError::TransactionConflict(
             "update_item: too many concurrent writers on this item".to_owned(),

Rerunning the five-server stress

Five servers share one Cassandra node. Each server has its own catalog keyspace prefix and port and runs the test 10 times, and the five run at the same time.

Setup, once:

docker run -d --name cass -e MAX_HEAP_SIZE=1024M -e HEAP_NEWSIZE=128M \
  -p 127.0.0.1:9042:9042 cassandra:4.1
# then turn on PasswordAuthenticator as in .github/workflows/integration-cassandra.yml
cargo build --release -p extenddb --no-default-features --features cassandra
BIN=$PWD/target/release/extenddb

For each server n in 1 to 5 ($TREE a checkout of the branch), in its own shell:

D=$HOME/stress-$n; mkdir -p $D
$BIN init --config $D/extenddb.toml --cassandra-contact-points 127.0.0.1:9042 \
  --cassandra-user cassandra --cassandra-pass cassandra --keyspace-prefix stress$n
# set [server] port = 1890$n in $D/extenddb.toml
$BIN serve --config $D/extenddb.toml --foreground > $D/serve.log 2>&1 &
cd $TREE
export EXTENDDB_TEST_ENDPOINT=https://127.0.0.1:1890$n EXTENDDB_ADMIN_USER=admin \
  EXTENDDB_ADMIN_PASSWORD=<password printed by init>
eval "$(python3 devtools/provision-test-credentials)"
export DYNAMODB_ENDPOINT=$EXTENDDB_TEST_ENDPOINT
for i in $(seq 1 10); do
  python -m pytest -q tests/python/test_rfc0003_concurrency.py::TestRfc0003AtomicCounterAdd
done

Start the five loops together (for example each in ( ... ) &, then wait). Each run is the test's own 50 threads of 20 calls. A run counts as failed when pytest reports a failure. The attempt table counts OCCATT lines in each serve.log. Load is the 1-minute load average from uptime, sampled during each pass; the peak is reported. Each server keeps its keyspaces between passes, and each pass uses one build (main or branch), alternating.

Open question

  1. The worst case for one UpdateItem call is now about 3.8 s of sleep plus 21 reads and lightweight transactions. What read timeout do the SDKs use by default, and does a 4 s tail on a contended item matter for it?
  2. fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401 edits the end of the same function and answers an exhausted loop with a 503 instead of TransactionConflictException. Its read-back after a lost answer can sleep up to 1,550 ms per lost attempt (50 << probe over 6 probes). With fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401 merged too, the sleeps alone can reach about 36.4 s (21 attempts of up to 1,550 ms of read-back probes, plus at most 3,816 ms of backoff), but only if every attempt loses its answer, which is a fault case. Under contention alone the sleeps stay under 3.8 s. Does fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401 need its own bound? The two branches conflict in one hunk, the constants block at the top of update_item.rs. Keep occ_window_ms from this branch and COMMIT_CHECK_PROBES from fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401, and drop fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401's OCC_BASE_DELAY_MS and OCC_EXP_CAP, which nothing uses after the merge (clippy with -D warnings refuses them).
  3. The 3.8 s bounds the sleeps only. What limits one read or lightweight transaction on the server's Cassandra connection?
  4. The occ_write lwt: IO error: failed to fill whole buffer 500 seen in the earlier passes is the lost-answer case fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401 handles. Does it explain the 500 in Flaky on Cassandra: an UpdateItem under write contention answered 500 InternalServerError in test_update_item_contention_is_never_a_transaction_conflict #1204?

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed at 9c13569. 1 finding: 1 Docs.

The change gives the Cassandra UpdateItem retry loop the 4 ms to 256 ms jittered window that PutItem and DeleteItem use, through ttl_claim_window_ms and sleep_below. Confirmed: on a table without TTL, 50 threads x 20 ADD calls on one item with SDK retries off answered no error and the counter ended at 1000 in 3 of 3 trials on one server and 3 of 3 on two servers; with the base's two files put back the same run answered 1, 2, 3 and 1, 6, 1 TransactionConflictException. Two trials through PartiQL UPDATE also ended at 1000 with no error. DynamoDB answered no error and ended at 1000 in all 3 trials, TTL on or off. With the base window put back in occ_window_ms, all 3 new tests fail (left: 286 right: 3836). The tree merged with #1401, its conflict resolved as the description says, builds without warnings and passes the 195 storage-cassandra lib tests. Those 195 tests also pass at the head.

  • Docs docs/adr/0020-cassandra-occ-update-item.md:36 — ADR-0020 still gives UpdateItem a 2 ms base and a 16 ms window cap, which this change replaces with 4 ms to 256 ms.

Docs — outside the diff

docs/adr/0020-cassandra-occ-update-item.md:36
Docs
ADR-0020's retry policy for update_item_impl still reads **Base delay:** 2 ms (line 36) and capped at a 16 ms window (line 37), and line 53 still says the bounded backoff windows (16 ms and 256 ms). At this head occ_window_ms (update_item.rs:36-38) returns ttl_claim_window_ms, which is 4 ms doubling to 256 ms. Fix: state the shared window at lines 36-37 and say 256 ms for both loops at line 53.

Evidence: the three new tests assert occ_window_ms(0) == 4 and occ_window_ms(20) == 256. With the ADR's formula put back (2 * (1u64 << attempt.min(3))) they fail with left: 2 right: 4 and left: 286 right: 3836.

@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 wider window cuts the calls that run out of attempts at 9c13569. In the body's five-server setup on one Cassandra node, exhausted UpdateItem calls per 50,000 were 958 on main and 0 here with Cassandra at 4 CPUs (38 of 50 runs failing on main, 2 of 50 here, both InternalServerError), 1,957 and 3,099 against 108 and 64 at 2 CPUs, and 0 on both uncapped; at 2 CPUs every run here still fails, mostly on InternalServerError (occ_write lwt: IO error), which this does not touch. Uncontended UpdateItem is unchanged (p50 1.7 to 1.9 ms); contended on a healthy node the two builds overlap (p99 387 to 423 ms); on a slow node this moves time from the median to the tail (p50 7 to 17 ms against 106 to 198 ms, p99 2.40 to 3.13 s against 2.29 to 2.78 s, max up to 5.6 s against 4.35 s). A call that still runs out answers 400 TransactionConflictException after 2.87 to 4.52 s, which botocore does not retry. On a table without TTL the counter equals the acknowledged count in every run on both builds, PartiQL UPDATE goes through the same loop and is right, and PutItem and DeleteItem behave as before. fmt, clippy, the 195 lib tests and the 1.94.0 check are clean, CI is green, and it is on current main; it conflicts with #1401 in one hunk, as the body says.

I will approve once a test holds that the loop sleeps in the new window.

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

Thanks. I read the change against main 92155f3. On a single-node Cassandra 4.1, the crate's 195 lib tests passed at this head, and the three new tests passed 3 of 3 runs. I did not repeat the five-server load runs, which LJMart11 and demohan measured. The window sums in the description match the constants: 286 ms before, 3,836 ms of windows now, and 764 ms for PutItem and DeleteItem. No client answer changes.

One change before I approve: lines 36-37 and 53 of docs/adr/0020-cassandra-occ-update-item.md still give UpdateItem a 2 ms base and a 16 ms cap. LJMart11 and demohan asked for this, and I agree.

demohan also asks for a test that the three sites sleep in the new window. My inline comment at line 36 suggests a smaller change that keeps the three sites on the PutItem and DeleteItem window. A test that the loop sleeps at all still needs a hook, as demohan says. I do not make that test a condition of my approval.

On your open question 2: with #1401 merged too, the sleeps alone can reach about 36.4 s in total. Each of the 21 attempts can sleep 1,550 ms in the read-back probes, and the backoff adds 3,816 ms at most. That needs every attempt to lose its answer, so it is a fault case. Under contention alone the sleeps stay under 3.8 s.

Two more points:

  • A short entry under a ### v1.2.0: heading in docs/manuals/07-upgrade-manual.md would help operators. On a contended item, the sleeps of one UpdateItem can now reach 3.8 s, where the sleeps on main stop at 286 ms in total. A call that still runs out took 2.87 to 4.52 s in demohan's runs. An operator with a client timeout near 2 s would want to know.
  • The message of the first commit, 3a73a94, still says "19 of 50" and "met again". The description asks to drop those lines. The repository builds the squash message from the commit messages, so the merger has to edit it.

#1401 (eliseong) changes the end of the same loop for #893. The two PRs conflict in one hunk, and your description gives the resolution. They fix different defects, so neither duplicates the other. I found no other open or recent PR that changes these windows.

Amol Navare added 5 commits December 2, 2026 10:59
…e window PutItem and DeleteItem use

Concurrent UpdateItem calls on one item must all succeed. The Cassandra
UpdateItem loop reads the item and writes it with a version check, and a
writer that loses the check sleeps a random time and tries again. The
window grew from 2 ms to 16 ms at most, and a writer gave up after 21
attempts with TransactionConflictException. With 50 writers on one item
their retries fell into the same 16 ms and met again, and when the
Cassandra node was busy a writer used all 21 attempts.

PutItem and DeleteItem retry the same check over a window that grows from
4 ms to 256 ms. UpdateItem now uses the same base and cap. The number of
attempts is unchanged.

Verified on a single Cassandra node: five servers on one node, each
running the 50 writer counter test ten times, answered
TransactionConflictException in 19 of 50 runs before the change and in 0
of 50 after it.
…utItem and DeleteItem, and pin it in tests

The previous commit gave the UpdateItem version check the window that
PutItem and DeleteItem use, with copied constants. UpdateItem now reads
that window from one function, `ttl_claim_window_ms` in delete_item.rs,
so the two cannot drift. The three sleep sites of the UpdateItem loop
call one helper. UpdateItem keeps its 21 attempts; PutItem and
DeleteItem keep 9.

The new unit tests check the window at the first and last attempt, that
it equals the PutItem and DeleteItem window, and that the sleeps before
the loop gives up add up to at most 3,836 ms. With the old window (2 ms
doubling to 16 ms) that sum is 286 ms and the test fails.

The previous commit message reports 0 failures in 50 five-server runs
after the change. A first pass of 50 had 1 failure, so the change
reduced the failures and did not remove them.
The test asserts the windows add up to exactly 3,836 ms, so drop the
check that could never fail and the 'at most' in its name. Say the
exhausted attempts were seen with five servers on one node, which is
what was measured.
… through the retry sites

Nothing in the tests failed when an UpdateItem retry slept in another
window, did not sleep, or slept at only two of its three retry sites.
The three sites (a row held by another owner, a lost TTL claim, a lost
version check) now sleep through one function, `occ_backoff`, which
sleeps below `occ_window_ms(attempt)` and returns that window.

Three test-hooks functions let a test lose every version check or every
TTL claim of one account, and record the windows of the sleeps with the
sleeps skipped. The new direct tests make a call lose all 21 attempts at
each site and check that it sleeps 20 times, in the windows 4, 8, 16,
32, 64 and 128 ms and then 256 ms 14 times, and answers
TransactionConflict. The held-claim test holds a real TTL claim. A
production build carries no hook.

ADR-0020 gives UpdateItem the window it now uses, 4 ms doubling to
256 ms, and names 256 ms for both loops.
…im_backoff

The three retry sites of UpdateItem sleep through `occ_backoff`, which
now calls `ttl_claim_backoff`, the function PutItem and DeleteItem use
for their version check. UpdateItem has no window function of its own,
so the two windows cannot drift apart. `occ_window_ms` and the test that
compared it with the PutItem and DeleteItem window are gone, and the unit
tests read `ttl_claim_window_ms`. PutItem and DeleteItem sleep as
before; `sleep_below` is private again.

The doc comment of `occ_backoff` says that some of 50 concurrent ADD
calls used every attempt, not all of them. The upgrade manual lists the
longer sleeps under v1.2.0, and ADR-0020 names the shared function.
@navareamol
navareamol force-pushed the fix/878-cassandra-update-retry branch from 9c13569 to 3f3d42d Compare December 2, 2026 20:42
@navareamol

Copy link
Copy Markdown
Collaborator Author

ADR-0020 now gives UpdateItem the shared window. Lines 35 to 37 read: 20 retries (21 attempts), base 4 ms, and the window of ttl_claim_window_ms, 4 ms doubling to 256 ms, with the 20 sleeps adding up to at most 3,836 ms, slept through ttl_claim_backoff at all three retry sites (lines 35-37). Line 53 says "the bounded backoff window (256 ms for both loops)" (line 53). I searched docs/ and the crate for other mentions of a 2 ms base or a 16 ms window for UpdateItem. The only other hits are the MongoDB backend's own backoff and a comment that describes the old window.

@navareamol

Copy link
Copy Markdown
Collaborator Author

Your request is met at 3f3d42d: a test holds that the loop sleeps in the shared window at each of its three sites, with the hooks and the controls described in my reply on the inline thread. The test passes 20 of 20 runs. The mutations you listed fail it, and two do not (a sleep inside occ_backoff in another window with the shared window recorded, and a recording hook that does not skip the sleep); the PR body lists both.

The body now says the 3.8 s bounds the sleep only and holds on a healthy node, and quotes your 2-CPU numbers: 2,775 to 7,790 ms in the loop for a call that ran out, 8,900 ms for the slowest that applied, and 2.87 to 4.52 s before a call that still runs out answers TransactionConflictException. The 2-CPU failures that are occ_write lwt: IO error stay out of this PR, as #1401 covers them. The upgrade manual has a v1.2.0 entry with the longer sleeps (07-upgrade-manual.md:395). The branch is rebased on main 1be10124b.

@navareamol

Copy link
Copy Markdown
Collaborator Author

At 3f3d42d:

  • ADR-0020 lines 35 to 37 and 53 give UpdateItem the shared window, as LJMart11 and demohan asked.
  • The three sites go through occ_backoff, which calls ttl_claim_backoff, the function PutItem and DeleteItem use. occ_window_ms and the drift test are gone, the unit tests read ttl_claim_window_ms, and sleep_below is private. demohan's recording test stays on top of it. Details are in the replies on the two inline threads.
  • The doc comment says that some of 50 concurrent ADD calls used every attempt, 144 of 100,000 in the runs.
  • The upgrade manual has a ### v1.2.0: entry (line 395): the sleeps of one UpdateItem on a contended item can reach about 3.8 s where they stopped at 286 ms in total, and a call that still runs out took 2.87 to 4.52 s in demohan's runs, for clients with timeouts near 2 s.
  • The first commit's message is stale. The PR author merges and builds the squash message from the description, not from that commit's message. The body says so.
  • The body's open question 2 now has your 36.4 s figure for fix(cassandra): do not report a committed PutItem or UpdateItem as failed #1401 merged too, and says it needs every attempt to lose its answer.

LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
The base brings main at b6c8595 through #1260 and #1313, with #1446,
#1531 and #1466. It also brings the 15 new rows of #1260 in
tests/test_binary_base64.py.

One file conflicted: docs/manuals/07-upgrade-manual.md. #1446 and #1531
add two v1.2.0 entries at the top of "Behavior Changes by Release",
where this branch adds its entry. The merge keeps the two entries of
main first, then the entry of this branch, then the entry of #1355.
No other file has changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
…-time

The merge takes b8f73c4 of #1093, which merges main at db8a90d.
The last merge took c8cd082, with main at c057660. Between the
two, #1531 merged into main. #1531 changed seven files, and the commits
of #1207 change none of them, so git merged without a conflict. In
docs/manuals/07-upgrade-manual.md, the v1.2.0 entry of #1531 now
follows the entry of #1093.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 5826e1b. This branch last had main at c8e66fb. Since
then, four PRs merged into main: #1446, #1531, #1466 and #1087.

One file conflicted. In docs/manuals/07-upgrade-manual.md, #1087 added
its v1.2.0 entry after the other v1.2.0 entries of main, where this
branch has its entry. The merge keeps the entries of main first, then
the entry of this branch.

Git merged crates/wasm-adapter/parity/corpus.json with no conflict:
#1087 adds a Scan case, and the 15 checks that this branch changes are
in other cases. The diff of this branch against main does not change in
that file.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 5826e1b. This branch last had main at c8e66fb. Since
then, four PRs merged into main: #1446, #1531, #1466 and #1087.

One file conflicted. In docs/manuals/07-upgrade-manual.md, #1087 added
its v1.2.0 entry after the other v1.2.0 entries of main, where this
branch has its entry. The merge keeps the entries of main first, then
the entry of this branch.

Main changed no other file that this branch changes.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 5826e1b, three commits past c057660: #1531, #1466 and
#1087. In docs/manuals/07-upgrade-manual.md, #1531 adds a v1.2.0 entry
at the top of "Behavior Changes by Release", and git merged it with no
conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of
main, where this branch has its entry. That is the one conflict. The
merge keeps both entries without change: the entry of #1087 first, then
the entry of this branch, before the v1.1.0 entries. No other file has
changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 5826e1b, three commits past c057660: #1531, #1466 and
#1087. In docs/manuals/07-upgrade-manual.md, #1531 adds a v1.2.0 entry
at the top of "Behavior Changes by Release", and git merged it with no
conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of
main, where this branch has its entry. That is the one conflict. The
merge keeps both entries without change: the entry of #1087 first, then
the entry of this branch, before the v1.1.0 entries.

Git merged three other files with no conflict:

- crates/storage-sqlite/src/data/data_engine.rs: #1087 changes
  scan_key_in_segment to compute the segment from the key, with no read
  of the data table. This branch maps the error of a dropped data table
  to StorageError::TableNotFound in the other data-plane calls, and it
  does not change scan_key_in_segment.
- crates/storage-sqlite/src/lib.rs: #1087 declares the
  scan_segment_tests module, and this branch declares
  deleting_window_data_tests.
- crates/storage-cassandra/tests/direct_integration.rs: #1531 declares
  the update_item_retry module, and this branch declares
  deleting_window.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 5826e1b, three commits past c057660: #1531, #1466 and
#1087. In docs/manuals/07-upgrade-manual.md, #1531 adds a v1.2.0 entry
at the top of "Behavior Changes by Release", and git merged it with no
conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of
main, where this branch has its entry. That is the one conflict. The
merge keeps both entries without change: the entry of #1087 first, then
the entry of this branch, before the v1.1.0 entries.

No other file has changes on both sides. #1087 changes how SQLite puts
items in parallel Scan segments. This branch changes the Scan request
checks in crates/engine, and #1087 changes no file in that crate.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 5826e1b, three commits past c057660: #1531, #1466 and
#1087. In docs/manuals/07-upgrade-manual.md, #1531 adds a v1.2.0 entry
at the top of "Behavior Changes by Release", and git merged it with no
conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of
main, where this branch has its entry. That is the one conflict. The
merge keeps both entries without change: the entry of #1087 first, then
the entry of this branch, before the v1.1.0 entries. No other file has
changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 44a7b79, five commits past c057660: #1531, #1466, #1087,
#768 and #1296. In docs/manuals/07-upgrade-manual.md, #1531 adds a
v1.2.0 entry at the top of "Behavior Changes by Release", and git
merged it with no conflict. #1087 adds its v1.2.0 entry after the other
v1.2.0 entries of main, where this branch has its entry. That is the one
conflict. The merge keeps both entries without change: the entry of
#1087 first, then the entry of this branch, before the v1.1.0 entries.

Git merged crates/storage-sqlite/src/data/query_scan.rs with no
conflict. #1087 replaces the rowid rule of the parallel Scan with the
SQL function extenddb_scan_segment. It computes the segment of a start
key from the key alone. This branch sets creation_date_time in
the TableKeyInfo of the test helper key_info. The tests that #1087 adds
in crates/storage-sqlite/src/scan_segment_tests.rs build each
TableKeyInfo from a clone, so they need no change for the new field.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466,
#1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and
#1531 add v1.2.0 entries at the top of "Behavior Changes by Release",
and git merged them with no conflict. #1087 adds its v1.2.0 entry after
the other v1.2.0 entries of main, where this branch has its entry. That
is the one conflict. The merge keeps both entries without change: the
entry of #1087 first, then the entry of this branch, before the v1.1.0
entries.

Git merged five other files with no conflict:

- crates/storage-cassandra/tests/direct_integration.rs: #1531 declares
  the update_item_retry module, and this branch declares
  gsi_backfilling.
- crates/storage-mongodb/src/table_engine.rs: #1446 changes DeleteTable.
  It marks the table DELETING by table_id, and it removes the tags and
  the table document in one transaction. This branch changes
  create_table_impl_inner, index_info_by_table_id_impl and
  doc_to_table_description_in.
- crates/storage-sqlite/src/lib.rs: #1087 declares the
  scan_segment_tests module, and this branch declares
  gsi_backfilling_tests.
- crates/storage-sqlite/src/store.rs: #1087 registers
  extenddb_scan_segment on each connection of the pool. This branch
  adds the gsi_backfills field and gsi_creating_phase_delay.
- crates/storage/src/lib.rs: #1087 rewrites the doc comment of
  scan_key_in_segment, and this branch declares the gsi_backfill
  module.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 44a7b79, five commits past c057660: #1531, #1466, #1087,
#768 and #1296. In docs/manuals/07-upgrade-manual.md, #1531 adds a
v1.2.0 entry at the top of "Behavior Changes by Release", and git
merged it with no conflict. #1087 adds its v1.2.0 entry after the other
v1.2.0 entries of main, where this branch has its entry. That is the one
conflict. The merge keeps both entries without change: the entry of
#1087 first, then the entry of this branch, before the v1.1.0 entries.

Git merged two other files with no conflict:

- crates/storage-mongodb/src/data_engine.rs: #1087 computes the
  parallel Scan segment with scan_segment in scan_key_in_segment and in
  scan_impl. This branch changes the write functions and their retries
  at other lines.
- crates/storage/src/lib.rs: #1087 rewrites the doc comment of
  scan_key_in_segment, and this branch declares the request_clock
  module.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466,
#1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and
#1531 add v1.2.0 entries at the top of "Behavior Changes by Release",
and git merged them with no conflict. #1087 adds its v1.2.0 entry after
the other v1.2.0 entries of main, where this branch has its entry. That
is the one conflict. The merge keeps both entries without change: the
entry of #1087 first, then the entry of this branch, before the v1.1.0
entries.

Git merged four other files with no conflict:

- Cargo.lock: #1087 adds crc32fast to the dependencies of
  extenddb-storage, and this branch adds form_urlencoded and tempfile to
  the dependencies of extenddb-storage-sqlite.
- crates/storage-sqlite/Cargo.toml: #1087 rewrites the comments of
  libsqlite3-sys and sqlite-wasm-rs. This branch adds form_urlencoded
  and the tempfile dev-dependency.
- crates/storage-sqlite/src/lib.rs: #1087 declares the
  scan_segment_tests module, and this branch declares file_mode and
  sqlite_uri.
- crates/storage-sqlite/src/store.rs: #1087 registers
  extenddb_scan_segment on each connection of the pool, in
  after_connect. This branch calls file_mode::prepare before the pool
  connects, and it removes the mode change after the connect. The pool
  keeps the after_connect of main.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466,
#1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and
#1531 add v1.2.0 entries at the top of "Behavior Changes by Release",
and git merged them with no conflict. #1087 adds its v1.2.0 entry after
the other v1.2.0 entries of main, where this branch has its entry. That
is the one conflict. The merge keeps both entries without change: the
entry of #1087 first, then the entry of this branch, before the v1.1.0
entries. No other file has changes on both sides.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants