sqlutil: enable WAL, larger cache, and NORMAL sync for the modernc SQLite driver#3693
Open
Deln0r wants to merge 1 commit into
Open
sqlutil: enable WAL, larger cache, and NORMAL sync for the modernc SQLite driver#3693Deln0r wants to merge 1 commit into
Deln0r wants to merge 1 commit into
Conversation
…Lite driver
Augment the !cgo SQLite DSN with three further pragmas alongside the
existing busy_timeout setting:
journal_mode=WAL - readers no longer block on the writer, which
Dendrite's storage layer always has multiple of.
cache_size=-32000 - 32 MiB page cache, up from the modernc default
of 2 MiB. Federation and sync workloads touch
many rooms per request and benefit from the
larger working set.
synchronous=NORMAL - fsync only at WAL checkpoints. Safe under WAL
for application durability; a power loss may
roll back to the last checkpoint, which Matrix
recovers from by resyncing peers.
Adds a regression test that opens a fresh database with the assembled
DSN and asserts each pragma round-trips to the expected value. The
test inherits the !cgo build tag so it runs together with the code
it exercises.
Only the !cgo build path is touched. The CGO build path (sqlite_cgo.go,
mattn/go-sqlite3) is unchanged.
Signed-off-by: Ian Chechin <ian00chechin@gmail.com>
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.
Summary
The
!cgoSQLite path (modernc.org/sqlite driver) currently only setsbusy_timeout=10000on the connection DSN. This PR adds three further pragmas with documented rationale and a regression test:journal_mode=WAL- readers proceed while a writer is active. Dendrite's storage layer always has concurrent readers and writers, so WAL is the SQLite-recommended setting.cache_size=-32000- 32 MiB page cache, up from the modernc default of 2 MiB. Federation and sync workloads touch many rooms per request and benefit from a larger working set.synchronous=NORMAL- fsync only at WAL checkpoints. Safe under WAL for application-level durability that survives process crashes; a power loss may roll back the most recent commit to the last checkpoint, which Matrix recovers from by resyncing peers.The CGO build path (
sqlite_cgo.go,mattn/go-sqlite3) is untouched.Test plan
A new
TestSQLiteNativeDSNExtensionininternal/sqlutil/sqlite_native_test.goopens a fresh file-backed database with the assembled DSN and asserts each of the four pragmas round-trips to the expected value (busy_timeout,journal_mode,cache_size,synchronous). It carries the!cgobuild tag so it runs in lock-step with the code under test.Notes
%3dform (=) of the DSN syntax is kept to match the existingbusy_timeoutline; switching to the parenthesis form (_pragma=cache_size(-32000)) would be a separate cosmetic refactor.synchronous=FULLat the OS layer.