guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: guix-commits
Subject: 05/05: database: Use "write-ahead log" mode and set a long "busy timeout".
Date: Fri, 21 Dec 2018 17:50:21 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit bdf860c2e99077d431da0cc1db4fc14db2a35d31
Author: Ludovic Courtès <address@hidden>
Date:   Fri Dec 21 23:35:20 2018 +0100

    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'.
---
 guix/store/database.scm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/guix/store/database.scm b/guix/store/database.scm
index e6bfbe7..4791f49 100644
--- a/guix/store/database.scm
+++ b/guix/store/database.scm
@@ -79,6 +79,15 @@ as specified by SQL-SCHEMA."
 create it and initialize it as a new database."
   (let ((new? (not (file-exists? 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
                   (lambda ()
                     (when new?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]