Skip to content

Close: vacuum only if the connection wrote - #25

Merged
mlin merged 3 commits into
mlin:mainfrom
Wid-L-Hacker:conrad/close-vacuum-only-if-wrote
Nov 10, 2026
Merged

mlin merged 3 commits into
mlin:mainfrom
Wid-L-Hacker:conrad/close-vacuum-only-if-wrote

Conversation

@mlin

@mlin mlin commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Every read-write close ran PRAGMA incremental_vacuum on the outer database, taking its write lock even when the connection had never written anything, so concurrent opens could fail with SQLITE_CANTOPEN while nothing ever wrote. A connection now tracks whether it entered a write path, and Close() vacuums only in that case; only a writer can have freed outer pages to reclaim. Writers behave exactly as before.

Tests: concurrent opens amid read-only-pattern closes failed 204 of 4000 times before, and pass after; a deterministic test shows a never-wrote close leaving the outer freelist untouched while a writer's close still reclaims it.

Every read-write close ran PRAGMA incremental_vacuum on the outer database, briefly taking its write lock even when the connection had only read. Under open/close churn (connection pools, parallel workers), those windows make concurrent opens fail with SQLITE_CANTOPEN, although nothing ever wrote.

Track whether the connection wrote anything -- set where the write path begins buffering changes into the outer database, which also covers page deletions and dictionary inserts -- and vacuum at close only then. A connection that never wrote freed no outer pages, so there is nothing for it to reclaim; connections that wrote close exactly as before.

Tests: a read-write connection that only reads now leaves pre-existing outer freelist pages untouched at close, while a writing connection still reclaims them; and concurrent opens survive read-write close churn (204 of 4000 churned opens failed with SQLITE_CANTOPEN before this change).
The macOS job uninstalls Homebrew's curl so the tests exercise the older system libcurl. The uninstall ran in the dependencies step, before configure -- but the runner's git loads Homebrew's libcurl, so with the keg removed, the FetchContent clones during configure die in dyld and the job fails before compiling anything. Move the uninstall into the build step, after configure and before the build: git works while it is needed, and the tests still run against the system libcurl.
@mlin
mlin merged commit 823ea49 into mlin:main Nov 10, 2026
5 checks passed
@mlin
mlin deleted the conrad/close-vacuum-only-if-wrote branch November 10, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants