Skip to content
Snippets Groups Projects
Unverified Commit bdf860c2 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

database: Use "write-ahead log" mode and set a long "busy timeout".

This should avoid "database is locked" errors when there's a lot of
concurrency, for instance when offloading simultaneously a lot of
builds.

* guix/store/database.scm (call-with-database): Add two 'sqlite-exec'
calls to set 'journal_mode' and 'busy_timeout'.
parent b96e05ae
No related branches found
No related tags found
No related merge requests found
...@@ -79,6 +79,15 @@ (define (call-with-database file proc) ...@@ -79,6 +79,15 @@ (define (call-with-database file proc)
create it and initialize it as a new database." create it and initialize it as a new database."
(let ((new? (not (file-exists? file))) (let ((new? (not (file-exists? file)))
(db (sqlite-open file))) (db (sqlite-open file)))
;; Turn DB in "write-ahead log" mode, which should avoid SQLITE_LOCKED
;; errors when we have several readers: <https://www.sqlite.org/wal.html>.
(sqlite-exec db "PRAGMA journal_mode=WAL;")
;; Install a busy handler such that, when the database is locked, sqlite
;; retries until 30 seconds have passed, at which point it gives up and
;; throws SQLITE_BUSY.
(sqlite-exec db "PRAGMA busy_timeout = 30000;")
(dynamic-wind noop (dynamic-wind noop
(lambda () (lambda ()
(when new? (when new?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment