Repository navigation
fix(storage): apply SQLite pragmas to every connection and bound the busy retry - #2289
Conversation
|
Hey @mbrandenburger 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! PR Checks✅ DCO Sign-off -- All commits have valid sign-offs. Nice work! ❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:
You'll need to sign your commits with GPG (e.g. ✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing! ✅ Issue Link -- Linked to #2285 (assigned to you). ⏳ All checks must pass before this PR can be reviewed. You've got this! |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
…busy retry openDB applied the default pragmas with one db.Exec, which database/sql runs on a single pooled connection. journal_mode is stored in the file, but busy_timeout, synchronous, temp_store and foreign_keys are per connection, so every other read connection ran with busy_timeout=0 and failed with SQLITE_BUSY at once instead of waiting. The same Exec also overrode a busy_timeout set in the data source on that one connection. openDB now adds the defaults to the data source as _pragma parameters, which modernc runs on every new connection. A pragma the data source already sets, as _pragma=name(...) or as a driver shorthand such as _busy_timeout, is not added, so the user's value applies. The cache_size=1000000000 default is dropped: as a per-connection setting it would let page-cache memory grow with every read connection, and the read pool is unbounded by default. retryWriteDB retried SQLITE_BUSY by calling itself with no limit, so a lock held for good hung the caller. It now retries up to 3 times without a sleep, since each attempt already waits up to busy_timeout inside SQLite, and returns the last error. The KVS write DB is wrapped in it like every other SQLite store. The tests hold four read connections and check the pragmas on each, including a data source that sets busy_timeout itself. The retry and KVS tests hold BEGIN EXCLUSIVE from another connection and use an error mapper that releases the lock on the first SQLITE_BUSY, so they do not depend on timing. docs/configuration.md documents the per-connection defaults, DSN precedence, that pool settings apply to the read pool only, directory creation and the busy retry. Fixes hyperledger-labs#2285 Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
…nd the busy retry Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
edda6a8 to
b40c71e
Compare
Fixes #2285
openDBapplied the default pragmas with onedb.Exec, whichdatabase/sqlruns on a single pooled connection. Every other read connection ran withbusy_timeout=0andforeign_keys=0, so a read there failed withSQLITE_BUSYat once. A test that holds four read connections showed the defaults on the first one only. The sameExecalso overrode abusy_timeoutset in the data source on that connection.Changes
openDBadds the defaults to the data source as_pragmaparameters, and modernc runs them on every new connection. A pragma the data source already sets, as_pragma=name(...)or as a driver shorthand such as_busy_timeout, is not added.cache_size=1000000000default is dropped. Applied per connection, it would let page-cache memory grow with every read connection, and the read pool is unbounded by default. A user who wants it sets_pragma=cache_size(...).retryWriteDBretriesSQLITE_BUSYup to 3 times instead of recursing with no limit. It does not sleep, since each attempt already waits up tobusy_timeoutinside SQLite.NewRetryWriteDBlike every other SQLite store.docs/configuration.mddocuments the per-connection defaults, DSN precedence, that the pool settings apply to the read pool only, directory creation and the busy retry. It also fixes the example data source (&_txlockto?_txlock).Tests
TestOpenAppliesPragmasToEveryConnectionchecks the pragmas on four read connections for a plain path, afile:URI, a_pragmain the DSN and a shorthand in the DSN.TestWithDefaultPragmascovers the DSN rewriting.TestRetryWriteDBBusyandTestKVSRetriesBusyWriteholdBEGIN EXCLUSIVEfrom another connection. An error mapper releases the lock on the firstSQLITE_BUSY, so the tests count retries without depending on timing.main. The old retry loops until the test times out.Compatibility
No exported API changes. Panurus uses
DbProvider,Opts,Config,ErrorMapperandNewConfigProvider, which are unchanged, and wraps its own stores in a boundedBusyRetryWriteDB. Its read connections now getforeign_keys=ON, which was the intended default.