guix-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Ludovic Courtès
Date: Fri, 26 Jan 2018 12:29:53 -0500 (EST)

branch: master
commit f3335e880c26897daced684710de7d79f5a83252
Author: Ludovic Courtès <address@hidden>
Date:   Fri Jan 26 18:20:30 2018 +0100

    database: Open the database in "write-ahead log" mode.
    
    Suggested by Ricardo Wurmus.
    
    * src/cuirass/database.scm (wal-mode): New procedure.
    (db-open): Use it.
---
 src/cuirass/database.scm | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index f1d0118..5ca3ad3 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -99,6 +99,11 @@ SQL statement to DB.  FMT and ARGS are passed to 'format'."
               (reverse! insts)
               (loop (cons inst insts))))))))
 
+(define (wal-mode db)
+  "Turn DB in \"write-ahead log\" mode and return it."
+  (sqlite-exec db "PRAGMA journal_mode=WAL;")
+  db)
+
 (define* (db-init #:optional (db-name (%package-database))
                   #:key (schema (%package-schema-file)))
   "Open the database to store and read jobs and builds informations.  Return a
@@ -115,9 +120,12 @@ database object."
 (define* (db-open #:optional (db (%package-database)))
   "Open database to store or read jobs and builds informations.  Return a
 database object."
-  (if (file-exists? db)
-      (sqlite-open db SQLITE_OPEN_READWRITE)
-      (db-init db)))
+  ;; Use "write-ahead log" mode because it improves concurrency and should
+  ;; avoid SQLITE_LOCKED errors when we have several readers:
+  ;; <https://www.sqlite.org/wal.html>.
+  (wal-mode (if (file-exists? db)
+                (sqlite-open db SQLITE_OPEN_READWRITE)
+                (db-init db))))
 
 (define (db-close db)
   "Close database object DB."



reply via email to

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