aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2022-01-19 13:17:13 +0000
committerChristopher Baines <mail@cbaines.net>2022-01-19 13:22:19 +0000
commita0abeeb621557bd1a8172d28e0e912f99021c7c3 (patch)
treec315eed6c6e58ae34ec9597a9cd553f52035f30d /guix-build-coordinator/datastore
parentb37dce9c3ffb794d76f867500bafe4c34c6bc8eb (diff)
downloadbuild-coordinator-a0abeeb621557bd1a8172d28e0e912f99021c7c3.tar
build-coordinator-a0abeeb621557bd1a8172d28e0e912f99021c7c3.tar.gz
Switch around some SQLite stuff
Use SQLITE_OPEN_SHAREDCACHE for all connections, and create the writer thread first to allow this. I think this addresses some weridness I was seeing locally, where hooks would get processed multiple times.
Diffstat (limited to 'guix-build-coordinator/datastore')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm82
1 files changed, 41 insertions, 41 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 74d75f7..9d9f272 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -124,33 +124,31 @@
(slot-set!
datastore
- 'worker-reader-thread-channel
+ 'worker-writer-thread-channel
(make-worker-thread-channel
(lambda ()
(let ((db
- (db-open database-file #:write? #f)))
- (sqlite-exec db "PRAGMA temp_store = MEMORY;")
+ (db-open database-file)))
(sqlite-exec db "PRAGMA busy_timeout = 5000;")
- (sqlite-exec db "PRAGMA cache_size = -16000;")
+ (sqlite-exec db "PRAGMA synchronous = NORMAL;")
+ (sqlite-exec db "PRAGMA temp_store = MEMORY;")
+ (sqlite-exec db "PRAGMA foreign_keys = ON;")
(list db)))
#:destructor
- (let ((reader-thread-destructor-counter
- (make-gauge-metric metrics-registry
- "datastore_reader_thread_close_total")))
- (lambda (db)
- (metric-increment reader-thread-destructor-counter)
- (sqlite-close db)))
- #:lifetime 50000
+ (lambda (db)
+ (db-optimize db
+ database-file
+ metrics-registry)
- ;; Use a minimum of 2 and a maximum of 8 threads
- #:parallelism
- (min (max (current-processor-count)
- 2)
- 8)
+ (sqlite-close db))
+ #:lifetime 500
+
+ ;; SQLite doesn't support parallel writes
+ #:parallelism 1
#:delay-logger (let ((delay-metric
(make-histogram-metric
metrics-registry
- "datastore_read_delay_seconds")))
+ "datastore_write_delay_seconds")))
(lambda (seconds-delayed)
(metric-observe delay-metric
;; TODO exact->inexact to work around
@@ -158,40 +156,42 @@
;; the metric sum will output in the
;; exact form including the /q
(exact->inexact seconds-delayed))
- (log-delay "datastore read" seconds-delayed)
+ (log-delay "datastore write" seconds-delayed)
(when (> seconds-delayed 1)
(format
(current-error-port)
- "warning: database read delayed by ~1,2f seconds~%"
+ "warning: database write delayed by ~1,2f seconds~%"
seconds-delayed))))))
(slot-set!
datastore
- 'worker-writer-thread-channel
+ 'worker-reader-thread-channel
(make-worker-thread-channel
(lambda ()
(let ((db
- (db-open database-file)))
- (sqlite-exec db "PRAGMA busy_timeout = 5000;")
- (sqlite-exec db "PRAGMA synchronous = NORMAL;")
+ (db-open database-file #:write? #f)))
(sqlite-exec db "PRAGMA temp_store = MEMORY;")
- (sqlite-exec db "PRAGMA foreign_keys = ON;")
+ (sqlite-exec db "PRAGMA busy_timeout = 5000;")
+ (sqlite-exec db "PRAGMA cache_size = -16000;")
(list db)))
#:destructor
- (lambda (db)
- (db-optimize db
- database-file
- metrics-registry)
-
- (sqlite-close db))
- #:lifetime 500
+ (let ((reader-thread-destructor-counter
+ (make-gauge-metric metrics-registry
+ "datastore_reader_thread_close_total")))
+ (lambda (db)
+ (metric-increment reader-thread-destructor-counter)
+ (sqlite-close db)))
+ #:lifetime 50000
- ;; SQLite doesn't support parallel writes
- #:parallelism 1
+ ;; Use a minimum of 2 and a maximum of 8 threads
+ #:parallelism
+ (min (max (current-processor-count)
+ 2)
+ 8)
#:delay-logger (let ((delay-metric
(make-histogram-metric
metrics-registry
- "datastore_write_delay_seconds")))
+ "datastore_read_delay_seconds")))
(lambda (seconds-delayed)
(metric-observe delay-metric
;; TODO exact->inexact to work around
@@ -199,11 +199,11 @@
;; the metric sum will output in the
;; exact form including the /q
(exact->inexact seconds-delayed))
- (log-delay "datastore write" seconds-delayed)
+ (log-delay "datastore read" seconds-delayed)
(when (> seconds-delayed 1)
(format
(current-error-port)
- "warning: database write delayed by ~1,2f seconds~%"
+ "warning: database read delayed by ~1,2f seconds~%"
seconds-delayed))))))
datastore))
@@ -2918,12 +2918,12 @@ WHERE build_results.build_id = :build_id"
(define* (db-open database
#:key (write? #t))
(define flags
- (append
+ (cons
(if write?
- (list SQLITE_OPEN_READWRITE)
- (list SQLITE_OPEN_READONLY
- SQLITE_OPEN_SHAREDCACHE))
- (list SQLITE_OPEN_NOMUTEX)))
+ SQLITE_OPEN_READWRITE
+ SQLITE_OPEN_READONLY)
+ (list SQLITE_OPEN_NOMUTEX
+ SQLITE_OPEN_SHAREDCACHE)))
(unless (file-exists? database)
(run-sqitch database))