Conversation
A hard shutdown on macOS can corrupt state.sqlite because checkpoint syncs use fsync(), which does not flush the drive cache. Set checkpoint_fullfsync after WAL setup and on the other state.sqlite writers. Leave fullfsync off. Fixes pingdotgg#13544
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.
What Changed
The server's SQLite connection now sets
PRAGMA checkpoint_fullfsync = ONimmediately after enabling WAL mode, so WAL checkpoints on macOS requestF_FULLFSYNC. Ordinary commits keep using plainfsync()(PRAGMA fullfsyncstays off).The same per-connection pragma is set on the
t3-sqlite-stateandmigrate-dev-dbwriter connections, which bypassSqlite.tsand can checkpointstate.sqlite.Tests read the pragmas back on the main persistence layer and the state script:
checkpoint_fullfsync = 1,fullfsync = 0.Why
Issue pingdotgg#13544 is an accepted bug. A hard shutdown on macOS can corrupt
state.sqlitebecause WAL checkpoints sync withfsync(), which does not flush the drive cache. Julius prescribed this fix in triage: after WAL, runPRAGMA checkpoint_fullfsync = ON, and leave ordinaryfullfsyncoff.This is a narrowly scoped durability fix for that hard-shutdown corruption on macOS. It is not a general product persistence default change beyond the prescribed pragma.
fullfsyncstays off, so per-commit sync behavior is unchanged. The pragma is a no-op on platforms withoutF_FULLFSYNC. It does change checkpoint durability and checkpoint cost on macOS, which is the accepted fix for pingdotgg#13544 and needs human review for that reason.Fixes pingdotgg#13544
UI Changes
None.
Checklist