fix(db): transactions wait for the write lock instead of failing (FLAW-23)
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 58s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 58s
A load test with 16 concurrent writers lost 12 of 480 writes with SQLITE_BUSY: transactions that read before writing cannot be helped by busy_timeout once another connection writes. _txlock=immediate makes every transaction take the write lock at BEGIN, so it queues instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc44f8250c
commit
792ca946f8
3 files changed
+68
-2
No files matched your search
@@ -32,9 +32,12 @@ func NewStore(dbPath string) (*Store, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// _txlock=immediate: transactions take the write lock when they begin. A transaction that reads
|
||||
// first and writes later would otherwise fail at once with SQLITE_BUSY while another one writes
|
||||
// (busy_timeout cannot help there); now it simply waits its turn (FLAW-23).
|
||||
dsn := dbPath
|
||||
if !strings.Contains(dsn, "?") {
|
||||
dsn += "?_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)&_pragma=foreign_keys(1)"
|
||||
dsn += "?_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)&_pragma=foreign_keys(1)&_txlock=immediate"
|
||||
}
|
||||
|
||||
db, err := sql.Open("sqlite", dsn)
|
||||
|
||||
Reference in new issue
Block a user