Repository navigation
0.3.10:1: store result databases nodatacow - #6
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
helix-white
left a comment
There was a problem hiding this comment.
Two failure paths need fixing before this migration ships:
-
P2 — Restore the live directory before treating a failed swap as non-fatal (
nocow.py, the two renames). Ifos.rename(path, old)succeeds andos.rename(tmp, path)raises (for example, a filesystem metadata-allocation error),main()catches the error and completes the migration successfully with/data/<network>missing. The scanner then creates a fresh database there (upstream/bitcoinmonetaryview/store.py), abandoning the existing scan in.<network>.old. The migration does not run again on ordinary starts. Roll back the first rename before continuing; if rollback fails, fail the migration rather than start with missing data. The same rule must cover failure to restore an interrupted swap at the beginning ofrewrite(). The proposal records that startup-safety contract at the recovery helper; the PR's unconditional “never fails a start” statement should be qualified accordingly. -
P2 — Clean up an incomplete staging copy on conversion failure (
nocow.py, the copy loop). A write/fsync failure leaves.<network>.nocowbehind while the migration reports success. This can retain almost another database's worth of disk space indefinitely, and these hidden directories are not excluded bystartos/backups.ts, so subsequent backups can include the supposedly excluded scan results. The proposal removes the staging directory on handled conversion failures while preserving recovery artifacts if restoring the live directory fails.
Proposed changes: 4861637...proposal/6
The head merges cleanly into main; existing CI passed discovery and x86/arm/riscv builds. Review and proposal are code-only, not executed. Please verify adopted changes with injected copy, promotion-rename, and recovery-rename failures.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
helix-white
left a comment
There was a problem hiding this comment.
Both earlier findings are resolved at b7c39dd. Failed promotion restores the original live directory before continuing; failed rollback or interrupted-swap recovery propagates a fatal error and preserves recovery artifacts. Handled conversion failures remove the staging copy. The startup-safety contract is recorded at the recovery helper, and the PR description now reflects it.
The adopted code matches the proposal. The head merges cleanly into main; discovery and all x86/arm/riscv build checks passed (the separate Retarget Build job was skipped). Reviewed code only, without executing the package; the author reports the requested fault-injection cases passed. No remaining blockers.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
|
@MarkSierra, could you look this over before we merge? It touches your users' scan data, so we'd like your eyes on it first. Some context: a StartOS user's data drive went read-only overnight while Monetary View's first full scan was running, and every service on the server went down with it. The kernel trace points at the app's This PR stores the result databases without copy-on-write ( Things worth your judgement:
|
|
One migration detail for the upstream option: setting |
|
Thanks Matt, and sorry this took a server down. I've looked through the change and I'm happy with it: it only touches Monetary View's own data, the swap and rollback are careful, and losing btrfs checksums is fine since the results are rebuildable and not in backups. Please merge it as is. I'd keep the migration in the package, since only it can rewrite existing databases. For the next app release I'll also set nodatacow on the data directory from the app itself, so other btrfs hosts are covered, and reduce how often the full scan forces writes to disk (fewer commits and larger WAL checkpoints), which should take a lot of pressure off btrfs. I have a finished mainnet scan on my StartOS box, so I'll time the update once it's on Community Beta and post the result here. |
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
|
Timing from my StartOS server (x86_64, kernel from StartOS 0.4.1.2), updating from 0.3.10:0 with a finished mainnet scan of 3.67 GB: the migration including the nocow rewrite took 19 seconds ("Migrating 0.3.10:0 -> 0.3.10:1 -> ..." at 17:12:12, "Initialization complete" at 17:12:31). The app reopened its database and resumed without rescanning. Thanks again! |
A StartOS 0.4.1.2 server running Monetary View's first full scan had its package-data btrfs volume forced read-only, which took every service down. Kernel 7.2.11, with 522 GiB unallocated and no I/O or checksum errors. The abort came from the app's
scannerthread fsyncing (btrfs_sync_file → btrfs_log_inode → log_csums → btrfs_del_csums,Transaction aborted (error -28)), with metadata space reservations at 7.9 GB against a 7.5 GB metadata allocation, almost all of it the delayed-refs reserve.The scan writes a multi-GB SQLite WAL database in small random chunks every 2 s. On copy-on-write btrfs that fragments the file into a vast number of extents, and every fsync then logs their checksums. The btrfs failure to grow metadata into free space is a kernel problem that this doesn't fix, but this workload is what drove it.
nocow.py(copied into the image) setsFS_NOCOW_FLon/data, so the result databases the app creates inherit it. Given network directories, it byte-copies any copy-on-write files into a nodatacow directory and swaps it in. It checks free space first and recovers an interrupted swap. A failed copy or swap removes the staging copy, puts the original directory back, logs, and lets the service start on its data unchanged. Only when the original directory cannot be put back does it fail the migration, keeping both directories for recovery, rather than start with no data./data(init/noCowData.ts). The0.3.10:1migration sets it and rewrites the existing/data/<network>/directories once.Verified on a StartOS 0.4.1.2 box (kernel 7.2.11): the script on a btrfs scratch directory (attribute set, content byte-identical, second run a no-op, new files inherit it), then 0.3.10:0 installed from community-beta and scanned, and updated to this build. Every file under
/dataended upC, set from inside the subcontainer through the idmapped mount, and the app reopened its database and resumed scanning. Injected failures (copy, promotion rename, rollback rename, and recovery of an interrupted swap, with and without a failing rename) each end in the outcome above. Not exercised: a rewrite of a database large enough to take minutes, and aarch64/riscv64.🤖 Generated with Claude Code