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: Sat, 24 Mar 2018 19:13:57 -0400 (EDT)

branch: master
commit 326264c8e9445cb94d7fb33aab5ef93dc99ffe57
Author: Ludovic Courtès <address@hidden>
Date:   Sun Mar 25 00:02:16 2018 +0100

    database: Set a 'busy_timeout' to handle concurrent accesses.
    
    Fixes a bug whereby some fibers would get a SQLITE_BUSY exception while
    accessing the database: see
    <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30644#26>.
    
    Suggested by Danny Milosavljevic <address@hidden>.
    
    * src/cuirass/database.scm (wal-mode): Rename to...
    (set-db-options): ... this.  Add call to 'sqlite-exec' for
    'busy_timeout'.
---
 src/cuirass/database.scm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 2b1d532..d0c169b 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -136,9 +136,19 @@ question marks matches the number of arguments to bind."
               (reverse! insts)
               (loop (cons inst insts))))))))
 
-(define (wal-mode db)
-  "Turn DB in \"write-ahead log\" mode and return it."
+(define (set-db-options db)
+  "Set various options for DB and return it."
+
+  ;; Turn DB in "write-ahead log" mode and return it.
   (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.  This is useful when we have several fibers or
+  ;; threads accessing the database concurrently.
+  ;;(sqlite-busy-timeout db (* 30 1000))
+  (sqlite-exec db "PRAGMA busy_timeout = 30000;")
+
   db)
 
 (define* (db-init #:optional (db-name (%package-database))
@@ -160,9 +170,9 @@ database object."
   ;; 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))))
+  (set-db-options (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]