Repository navigation
Read helper: retry a WAL cohort that closes during the open - #317
Merged
Merged
Conversation
Each store call closes its connection, and the last close deletes the -wal/-shm pair. When that close falls between the helper's first stamps and its lock, the helper reports "source changed" with launch_topology_change: the main file is unchanged, only the sidecars are gone. Only attach reads retried it. Ordinary and reuse reads raised it at once, which made test_stop_receipt flake on macOS CI. Ordinary and reuse reads now retry it in their own window, like "live sidecars". After a write race or a turnover the retry waits 10 ms, not 50 ms, so a slow first answer does not use the 100 ms reuse window. Stress (store.job_ref against a thread that opens and closes store connections): source changed 18 in 9,000 reads before, 0 after (2 ms writer gap); 4 in 30,000 before, 0 after (10 ms gap).
Owner
Author
|
First CI run: test (macos-latest, 3.12) failed one test, test_codex_host.HostTurnTests.test_cut_interrupts_only_its_turn ('timeout' != 'cancelled'). That test uses only a fake socket host and a threading.Event. It does not use the store or the read helper. All other legs passed. The failed job is rerun. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS CI,
tests/test_stop_receipt.py::StopReceiptTests::test_a_cut_running_worker_records_a_stop_receipt_and_settlesfailed now and then withReadUnavailable: unable to open database: source changed(run 44764591763, job 136385806279, PR #314; one earlier time near v1.51.4). The call path isstore.cut_task->store.job_ref->readonly.connect(reuse=True)->ReadConnection.__init__. A second run of the same tree passed.Root cause
Each store call opens and closes its own SQLite connection. In WAL mode the last close checkpoints and deletes the
-wal/-shmpair.The read helper (
readonly_worker.main) takes its first stamps, opens the file, checks for a lock, takes the lock, and stamps again. When a writer in the test process closes its last connection inside that window, the first stamps include the WAL pair and the second stamps do not. The main file keeps its inode, size, mtime and ctime. The helper then reportssource changedwithlaunch_topology_change=Trueandsame_store_write=False.ReadConnectionretried that proof only forattach_bindingreads. Ordinary andreusereads raised it at once, although the same reads retrylive sidecarsandactive reader, which are the same writer cohort seen at a different time.Probed, with a temporary tag on each helper emit site: all 25
source changederrors in the before runs below came from the post-lock compare (readonly_worker.py,after != beforeafterlockf). In each one, the main stamp was equal and only the sidecars were gone.Fix
readonly._sidecar_contention(exc):live sidecars,active reader, orsource changedwithlaunch_topology_change. Ordinary and reuse reads retry it in their own window (100 ms for reuse, 1 s for ordinary). Both retry sites use it.A real source swap still raises. A new inode or changed main metadata does not set
launch_topology_change(the helper sets it only when the full main stamp is equal). The retry evaluates the source again from the start through the same fences.Before and after
Stress script: one thread calls
store.get_jobin a loop (each call opens and closes a WAL connection), the main thread callsstore.job_ref300 times per process. macOS, this Mac. Counts ofsource changedthat reached the caller:The original test in a loop with 18 CPU burners gave 0 failures in 200 runs before the fix, so CPU load alone does not reproduce it. The stress script does.
Not changed: under the same stress,
active readeranddatabase is lockedstill reach the caller when the 100 ms reuse window ends (for example 116 and 7 in 30,000 reads at 10 ms, before and after alike). That is the designed short window of ordinary reads, not this fault.Tests
tests/test_readonly_cohort_turnover.py:test_closing_writer_between_stamps_and_lock_is_a_topology_change: forces the race with real files. A read-only WAL writer is open at the first stamps and closed before the lock. The helper emitssource changedwithlaunch_topology_change=True,same_store_write=False, and the main stamp is unchanged. The next open reads the source.test_ordinary_and_reuse_reads_retry_a_cohort_turnover: fails before the fix in both modes, passes after, with one helper process.test_slow_turnover_answer_still_retries_in_the_reuse_window: first answer at 60 ms. Fails with the old 50 ms sleep.test_source_change_without_proof_still_raises:source changedwithout a proof still raises.Local (macOS, this Mac): related readonly, store and launch tests pass (232 passed). Full
python -m unittest discover -s tests: 4521 tests, 2 failures and 3 errors, all timeouts intest_job_scope_launch,test_state_dir_bindingandtest_daemon_worker_mode_uses_warm_worker. The same 5 fail with theorigin/devreadonly.pyin place (5 failed, 7 passed both ways), so they are not from this change. CI is the gate.Changelog text for the next release
test_stop_receipt.