fix(microvm-run): avoid db.sqlite backup restart loop under concurrent writes#11
Conversation
…t writes The nix store DB snapshot taken before VM boot used a plain `.backup` command, which the SQLite docs specify will restart from page 1 whenever the source database is modified by another connection mid-copy. On an actively used host, nix-daemon writes to db.sqlite frequently enough (builds, substitutions, GC, etc.) that the backup could be restarted continuously, observed as the sqlite3 process pegging a CPU core indefinitely — the bottleneck was repeated re-copying, not disk throughput. Fix by opening an explicit read transaction on the same connection before running .backup. This pins a consistent snapshot up front, so external commits during the backup no longer invalidate already- copied pages and trigger a restart. Also add a 30s busy-timeout as a defensive measure in case another process holds a competing lock at the moment the transaction starts. Ref: https://sqlite.org/forum/info/cca839708d74a20014f7188b86a19b267602d497bfa90ec1d1e79111a5b24adb Co-Authored-By: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughModifies flake.nix's VM runner script to wrap the SQLite Nix store database backup in an explicit read transaction with a timeout and consistency check, replacing the previous single-step ChangesSQLite Backup Mitigation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
systemstart
left a comment
There was a problem hiding this comment.
LGTM, thanks for contributing.
|
Added in v0.10.0 |
The nix store DB snapshot taken before VM boot used a plain
.backupcommand, which the SQLite docs specify will restart from page 1 whenever the source database is modified by another connection mid-copy. On an actively used host, nix-daemon writes to db.sqlite frequently enough (builds, substitutions, GC, etc.) that the backup could be restarted continuously, observed as the sqlite3 process pegging a CPU core indefinitely — the bottleneck was repeated re-copying, not disk throughput.Fix by opening an explicit read transaction on the same connection before running .backup. This pins a consistent snapshot up front, so external commits during the backup no longer invalidate already- copied pages and trigger a restart. Also add a 30s busy-timeout as a defensive measure in case another process holds a competing lock at the moment the transaction starts.
Ref: https://sqlite.org/forum/info/cca839708d74a20014f7188b86a19b267602d497bfa90ec1d1e79111a5b24adb
Summary by CodeRabbit