Use WAL mode for SQLite cache databases#13800
Merged
Conversation
With "truncate" mode, if we try to write to the database while another process has an active write transaction, we'll block until the other transaction finishes. This is a problem for the evaluation cache in particular, since it uses long-running transactions. WAL mode does not have this issue: it just returns "busy" right away, so Nix will print error (ignored): SQLite database '/home/eelco/.cache/nix/eval-cache-v5/...' is busy and stop trying to write to the evaluation cache. (This was the intended/original behaviour, see AttrDb::doSQLite().)
This avoids problems with older versions of Nix that don't put the caches in WAL mode. That's generally not a problem, until you do something like nix build --print-out-paths ... | cachix which deadlocks because cachix tries to switch the caches to truncate mode, which requires exclusive access. But the first process cannot make progress because the cachix process isn't reading from the pipe.
Ericson2314
approved these changes
Aug 20, 2025
Member
Ericson2314
left a comment
There was a problem hiding this comment.
I am not really the one to judge here, as I don't have much hands-on experience with the eval cache, but we use "wal" elsewhere, and the commit messages / PR description makes sense.
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
2 tasks
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.
Motivation
With "truncate" mode, if we try to write to the database while another process has an active write transaction, we'll block until the other transaction finishes. This is a problem for the evaluation cache in particular, since it uses long-running transactions. I.e. other Nix commands operating on the same flake could be blocked for an unbounded amount of time.
WAL mode does not have this issue: it just returns "busy" right away, so Nix will print
and stop trying to write to the evaluation cache. (This was the intended/original behaviour, see
AttrDb::doSQLite().)A quick benchmark (running
nix search github:NixOS/nixpkgs/bf8462aeba50cc753971480f613fbae0747cffc0?narHash=sha256-bPyv7hsbtuxyL6LLKtOYL6QsmPeFWP839BZQMd3RoUg%3D20 times) did not show a significant performance difference:This PR also updates the versions of the SQLite caches. This avoids problems with older versions of Nix that don't put the caches in WAL mode. That's generally not a problem, until you do something like
which deadlocks because cachix tries to switch the caches to truncate mode, which requires exclusive access. But the first process cannot make progress because the cachix process isn't reading from the pipe.
Based on DeterminateSystems#150, DeterminateSystems#167.
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.