Make explicit non-passive Sqlite WAL checkpoints#85
Merged
OpsBotPrime merged 3 commits intomasterfrom Mar 26, 2026
Merged
Conversation
The default way SQLite in WAL mode performs checkpoints, is by waiting for quiet time where there are no readers nor writers. Any read-connection can block this passive WAL checkpointing from making progress. We have observed that in production when having large workloads with consumers working on hundreds of chunks concurrently. Whereas the WAL is not expected to grow much beyond 4MiB (that's when the passive autocheckpointing kicks in), we saw WALs of > 850MiB. At that point, reads slow down significantly and that can cause a failure for the system as a whole. To mitigate this, as per the SQLite docs, this PR: - Disables the passive autocheckpointing (leaving it enabled conflicts with manual checkpointing which can then result in a SQLITE_BUSY) - Runs active checkpointing _every second_. It is very fast when there is little-to-no work to do, but under load it is expected that we'll hit the '1000 page mutations' (AKA the 4MiB default WAL size) within a second. - We use the 'RESTART' strategy, together with a `journal_file_limit` that ensures that the WAL will be trimmed down to the max of 4MiB. That means we don't always fully truncate, nor do we keep it at 'whatever the max happened to be'. Doing this checkpointing does mean that every second there is a tiny timeframe in which both write-tasks and also all read-tasks will have to wait. This is unlikely to cause any problems. We now explicitly configure the busy timeout to be 5 seconds, which was the prior implicit default of SQLx/Rusqlite for good measure.
Contributor
Author
|
SHOW @ReinierMaas |
7894cc2 to
1f005b9
Compare
Contributor
Author
|
@OpsBotPrime merge and tag |
Contributor
|
Rebased as 9b4d5e2, waiting for CI … |
OpsBotPrime
added a commit
that referenced
this pull request
Mar 26, 2026
Approved-by: Qqwy Priority: Normal Auto-deploy: false
Contributor
|
CI job 🟡 started. |
Contributor
|
The build failed ❌. If this is the result of a flaky test, then tag me again with the |
Contributor
Author
|
@OpsBotPrime retry |
Approved-by: Qqwy Priority: Normal Auto-deploy: false
Contributor
|
Rebased as 5c25128, waiting for CI … |
Contributor
|
CI job 🟡 started. |
ReinierMaas
reviewed
Mar 26, 2026
Contributor
ReinierMaas
left a comment
There was a problem hiding this comment.
LGTM! Only a single comment thanks for looking into this!
Comment on lines
+246
to
+247
| /// We use the 'TRUNCATE' strategy, which will do the most work but will briefly block the writer *and* all readers | ||
| /// |
Contributor
There was a problem hiding this comment.
You use the RESTART strategy.
Contributor
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.
The default way SQLite in WAL mode performs checkpoints, is by waiting for quiet time where there are no readers nor writers.
Any read-connection can block this passive WAL checkpointing from making progress. We have observed that in production when having large workloads with consumers working on hundreds of chunks concurrently.
Whereas the WAL is not expected to grow much beyond 4MiB (that's when the passive autocheckpointing kicks in), we saw WALs of > 850MiB. At that point, reads slow down significantly and that can cause a failure for the system as a whole.
To mitigate this, as per the SQLite docs, this PR:
journal_file_limitthat ensures that the WAL will be trimmed down to the max of 4MiB. That means we don't always fully truncate, nor do we keep it at 'whatever the max happened to be'.Doing this checkpointing does mean that every second there is a tiny timeframe in which both write-tasks and also all read-tasks will have to wait. This is unlikely to cause any problems. We now explicitly configure the busy timeout to be 5 seconds, which was the prior implicit default of SQLx/Rusqlite for good measure.