Repository navigation
Store: nodatacow on btrfs, WAL checkpoints every 64 MB - #59
Merged
Merged
Conversation
On a StartOS server, the first full scan drove btrfs into a fault that made the data drive read-only (Start9-Community/bitcoinmonetaryview-startos#6): the scan rewrites a multi-GB SQLite database in small pieces, which fragments it on a copy-on-write file system, and each flush then logs the checksums of all its extents. - The writer marks its network directory nodatacow (chattr +C) before creating the database, so new files skip copy-on-write. Best effort: other file systems refuse the ioctl and nothing changes. Existing files keep their attribute. - WAL autocheckpoint 16384 pages (64 MB) instead of 1,000, and the WAL file is kept at most 64 MB: with synchronous=NORMAL each checkpoint flushes the database, so a fast scan now flushes about 16 times less often. - New CI job mounts a btrfs file system and checks the database files are created nodatacow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E7wzJobv8ioFW8hq9u9yGK
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.
App-side follow-up to Start9-Community/bitcoinmonetaryview-startos#6. On a StartOS server the first full scan drove btrfs into a fault that made the data drive read-only. The scan rewrites a multi-GB SQLite database in small pieces, which fragments badly on copy-on-write btrfs, and each flush then logs the checksums of all its extents.
Changes
FS_NOCOW_FL,chattr +C) before creating the database, so the database, WAL and spent-output filter skip copy-on-write. Best effort: other file systems refuse the ioctl, and nothing changes there. Only the app's own data directory is touched. Existing files keep their attribute; the StartOS package'snocow.pyrewrites them once (0.3.10:1).wal_autocheckpointis now 16384 pages (64 MB) instead of 1,000 (4 MB), andjournal_size_limitis 64 MB. Withsynchronous=NORMALeach checkpoint flushes the database, so sustained scan writes cause about 16 times fewer flushes. An app crash loses nothing. A power cut can lose progress since the last checkpoint; the database stays consistent and the scan redoes it. The saved spent-output filter is already token-checked against the database.btrfsjob mounts a loop btrfs and checks the database files are created nodatacow, and that existing files keep their attribute.Measured
strace -cof a full scan of a synthetic 6,000-block chain (9.7 MB of data): fsync+fdatasync 22 → 10. The remaining calls are fixed per scan. The difference grows with the volume written, about 1 per 64 MB instead of 1 per 4 MB.Tests
tests/test_store_fs.pycovers the PRAGMAs, the ioctl logic (mocked: sets the flag and keeps the other flags; leaves an already-set flag alone; tolerates refusal) and that only the writer marks its directory.Generated by Claude Code