summaryrefslogtreecommitdiff
path: root/src/cuirass/database.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-01-26 18:20:30 +0100
committerLudovic Courtès <ludo@gnu.org>2018-01-26 18:21:56 +0100
commitf3335e880c26897daced684710de7d79f5a83252 (patch)
treef4d560bd60c4fdc6b68141c895cccd12e3415b46 /src/cuirass/database.scm
parente11bcf926d70e73eec6ad782f0a3445547f502a1 (diff)
downloadcuirass-f3335e880c26897daced684710de7d79f5a83252.tar
cuirass-f3335e880c26897daced684710de7d79f5a83252.tar.gz
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.
Diffstat (limited to 'src/cuirass/database.scm')
-rw-r--r--src/cuirass/database.scm14
1 files 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."