Repository navigation
Add Db::promote to move the anonymous database into a shared WAL temp file - #1761
Merged
Merged
Conversation
…ons share Db::new creates dirsql-<pid>-<n>.db in SQLite's temp directory and deletes it with its journal, -wal and -shm files once the last connection closes. Db::reader opens another connection to the same file, switching it to WAL so reads neither wait for nor see a write in progress, and carries over path-table settings, extensions and declared functions.
…reader opens A rollback journal file created and deleted per commit made a watched write about 1.5x slower to reach an /events consumer than inotifywait; an in-memory journal under an exclusive lock brings a small commit within about 3 microseconds of the anonymous temp database.
…tions share it Db::new goes back to the anonymous temp database; Db::promote is a stub, so every test that promotes and then opens a reader fails.
thekevinbot
marked this pull request as ready for review
November 19, 2026 03:50
8 tasks done
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.
Part of #1754 (PR 1 of 3; the last PR carries
Fixes #1754).Db::newstays the anonymous temp database, so watch latency is unchanged. This PR adds the pieces the query path will use in PR 2:Db::promote()copies an anonymous database (SQLite backup API) into a file of its own in SQLite's temp directory (SQLITE_TMPDIR->TMPDIR->/var/tmp->/usr/tmp->/tmp;std::env::temp_dir()on Windows), nameddirsql-<pid>-<n>.db, owner-only, switches it to WAL, and makes it theDb's connection with the same path-table settings, extensions and declared functions. The file and its-journal/-wal/-shmfiles are deleted when the last connection drops. ADbthat already has a file (promoted, orDb::open) is left alone.Db::reader()opens another connection to a promoted or opened database, set up the same way (function workers shared, so an embedding model is not loaded per reader). On an anonymous database it returnsDbError::Anonymous.Nothing calls
promote()yet. PR 2 adds the trigger (the first read that has to overlap another statement waits once, then the database is promoted before the next statement), the reader pool and the Rust repro.Measurements
Promotion: about 0.7 ms per MiB of database (1M rows of 40-byte blobs: 36 ms; 63 MiB: 45 ms); the WAL switch is about 0.2 ms.
Promoted, 1.5M-row table, 1 s slow scan:
Manual exercise
A scratch crate against this branch:
reader()beforepromote()returnsAnonymous;promote()moved 1M rows in 36 ms into/var/tmp/dirsql-<pid>-0.dbin WAL mode; the writer inserted and counted while a reader's 3M-row join ran, and the join returned a consistent 3,000,000; the file was gone after the last connection dropped.Red: job 135280534246 (commit 54d1e3b,
promote()a stub):db::tests::promote_moves_the_database_into_a_wal_temp_filefailed its WAL assertion atdb.rs:3915, and every reader test failed withcalled Result::unwrap() on an Err value: Anonymous.tests/concurrent_reads.rsasserts "Db::promote must move the database to a named file other connections can share" (fails the same way locally).E2E Verification
watch_speed_test)cargo test --workspace --features cli --no-fail-fastpass, exceptnon_utf8_names/non_utf8_names_e2e, which fail identically on main on this host (ZFSutf8onlyrejects non-UTF-8 names, os error 84)packages/python/e2e-attestations/<branch>.jsonreceipt written (just e2e-attest-python)packages/ts/e2e-attestations/<branch>.jsonreceipt written (just e2e-attest-ts)just e2e-attest-ts,just e2e-attest-python,cargo test --workspace --features cli --no-fail-fast, all at d314bf2 (final code)Changelog / Migrations
packages/rust/changelog.d/packages/rust/migrations.d/