Repository navigation
fix(storage-cassandra): retry a lost UpdateItem version check over the PutItem and DeleteItem window - #1531
Conversation
LJMart11
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 indocs/manuals/07-upgrade-manual.mdwould 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.
…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.
9c13569 to
3f3d42d
Compare
|
ADR-0020 now gives UpdateItem the shared window. Lines 35 to 37 read: 20 retries (21 attempts), base 4 ms, and the window of |
|
Your request is met at 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 |
|
At
|
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.
…-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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 ofttl_claim_backoffmoves intottl_claim_window_ms(attempt), and the jittered sleep into a privatesleep_below(window_ms).ttl_claim_backoffissleep_below(ttl_claim_window_ms(attempt)). PutItem and DeleteItem sleep exactly as before.crates/storage-cassandra/src/data/update_item.rs:OCC_BASE_DELAY_MSandOCC_EXP_CAPare 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 throughttl_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 withtest-hooks, no-ops otherwise) lose every version check or every TTL claim of one account inupdate_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 ofupdate_item_implgives 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: av1.2.0entry 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.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:
crates/engine/src/update_item.rs,handle_update_item_with);UPDATE, which calls the same handler (crates/engine/src/partiql/write/update.rs:88);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_applysends 1,000UpdateItem ADDcalls on one item from 50 threads, with SDK retries off, and asserts that no call fails. The issue records one failure of it in thecassandra-pytestjob 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_implanswersTransactionConflict("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).Each failed run on main failed with
TransactionConflictExceptiononly. 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.
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
InternalServerErrorand oneTransactionConflictException. TheInternalServerErrorcame withocc_write lwt: IO error: failed to fill whole bufferin 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.
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 withInternalServerErrorfromocc_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 (RequestBodyTimeoutLayerincrates/server/src/lib.rs:259, and the first-byte and header timeouts incrates/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.cargo fmt --checkcargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets -- -D warningscargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets --features test-hooks -- -D warningscargo +1.97.0 test -p extenddb-storage-cassandra --lib, with and without--features test-hooks--features test-hooks --test direct_integration update_item_retry, 20 runstest_rfc0003_concurrency.py, release build of the headtest-hooks),--libtestsMain 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_msat 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.rsdo. 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 answersTransactionConflict. The hook records the windows and skips the sleeps, so a test takes the time of 21 reads, not 3.8 s.lost_version_checks_sleep_in_the_shared_windowupdate_item.rs:280lost_ttl_claims_sleep_in_the_shared_windowupdate_item.rs:225a_held_ttl_claim_sleeps_in_the_shared_windowupdate_item.rs:126All 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 isttl_claim_backoff, the function PutItem and DeleteItem use. A change insideocc_backoffthat 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 --shortempty after each). A control counts when the tests fail on an assertion about the sleeps or the call's answer.occ_backoffcalls removedleft: []a_held_ttl_claim_sleeps_in_the_shared_windowfailed,left: []lost_ttl_claims_sleep_in_the_shared_windowfailed,left: []lost_version_checks_sleep_in_the_shared_windowfailed,left: []ttl_claim_backoffdirectly, skippingocc_backoffleft: []a call that loses every attempt must give up with TransactionConflict, got Ok((None, None))left: []occ_backoffsleeps in the old window but recordsttl_claim_window_msControl 1, the old window constants in
delete_item.rs(unit tests:left: 286,right: 3836andleft: 2,right: 4). It also changes the window of PutItem and DeleteItem, so it pins the constants for all three:Controls B1 to B3 replace
occ_backoff(&key_info.account_id, attempt).await;at one site withtokio::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 withttl_claim_backoff(attempt).await;. D1 makestake_lossreturnfalsewhere it returnstrue. D2 makesupdate_item_sleep_skippedreturnfalseafterwindows.push(window_ms);. D3 replaceswindows.push(window_ms);withlet _ = windows;. E replacesttl_claim_backoff(attempt).await;insideocc_backoffwith the old-window sleep. The failing text of A, B, C and D3:The print, applied to main and to this branch for the attempt table (measurement only; abridged, apply it by hand):
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:
For each server
nin 1 to 5 ($TREEa checkout of the branch), in its own shell:Start the five loops together (for example each in
( ... ) &, thenwait). 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 countsOCCATTlines in eachserve.log. Load is the 1-minute load average fromuptime, 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
TransactionConflictException. Its read-back after a lost answer can sleep up to 1,550 ms per lost attempt (50 << probeover 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 ofupdate_item.rs. Keepocc_window_msfrom this branch andCOMMIT_CHECK_PROBESfrom 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'sOCC_BASE_DELAY_MSandOCC_EXP_CAP, which nothing uses after the merge (clippy with-D warningsrefuses them).occ_write lwt: IO error: failed to fill whole buffer500 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?