Skip to content

Store: nodatacow on btrfs, WAL checkpoints every 64 MB - #59

Merged
MarkSierra merged 1 commit into
mainfrom
claude/bitcoin-spam-analysis-7dojve
Nov 9, 2026
Merged

MarkSierra merged 1 commit into
mainfrom
claude/bitcoin-spam-analysis-7dojve

Conversation

@MarkSierra

Copy link
Copy Markdown
Owner

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

  • nodatacow: the writer marks its network directory nodatacow (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's nocow.py rewrites them once (0.3.10:1).
  • Fewer flushes: wal_autocheckpoint is now 16384 pages (64 MB) instead of 1,000 (4 MB), and journal_size_limit is 64 MB. With synchronous=NORMAL each 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.
  • CI: a new btrfs job mounts a loop btrfs and checks the database files are created nodatacow, and that existing files keep their attribute.

Measured

strace -c of 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

  • Full suite: 185 tests pass locally.
  • New tests/test_store_fs.py covers 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.
  • Real btrfs runs in CI.

Generated by Claude Code

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
@MarkSierra
MarkSierra marked this pull request as ready for review November 9, 2026 10:23
@MarkSierra
MarkSierra merged commit 40988af into main Nov 9, 2026
15 checks passed
@MarkSierra
MarkSierra deleted the claude/bitcoin-spam-analysis-7dojve branch November 9, 2026 10:23
@MarkSierra MarkSierra mentioned this pull request Nov 9, 2026
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