aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore/sqlite.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-04-22 16:07:36 +0100
committerChristopher Baines <mail@cbaines.net>2023-04-22 16:07:36 +0100
commit46df1203aa0c1ae3502e6d70cda8e826718b37b2 (patch)
tree0c2a7d4d9025603b170706a1daa43922f68dd7eb /guix-build-coordinator/datastore/sqlite.scm
parent8d524b656e9a8eff9390bb2936ad5ace84bc94b9 (diff)
downloadbuild-coordinator-46df1203aa0c1ae3502e6d70cda8e826718b37b2.tar
build-coordinator-46df1203aa0c1ae3502e6d70cda8e826718b37b2.tar.gz
Try much harder to truncate the WAL
I think when there are lots of long reads taking place, that can prevent checkpointing and truncating the WAL, so allow waiting for much longer if this seems to be the case.
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm49
1 files changed, 30 insertions, 19 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index e8d9f2a..b82cf74 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -246,6 +246,9 @@
(define wal-size-threshold
(* 5 MiB))
+ (define extreme-wal-size-threshold
+ (* 15 MiB))
+
(and
(let ((checkpoint-duration-metric-name
"datastore_wal_checkpoint_duration_seconds"))
@@ -256,25 +259,33 @@
metrics-registry
checkpoint-duration-metric-name
(lambda ()
- (let ((statement
- (sqlite-prepare
- db
- "PRAGMA wal_checkpoint(TRUNCATE);")))
- (match (sqlite-step-and-finalize statement)
- (#(blocked? modified-page-count pages-moved-to-db)
- (if (= blocked? 1)
- (begin
- (simple-format
- (current-error-port)
- "warning: wal checkpoint blocked\n")
- #f)
- (begin
- (simple-format
- (current-error-port)
- "wal checkpoint completed (~A, ~A)\n"
- modified-page-count
- pages-moved-to-db)
- #t)))))))
+ (when (> (wal-size) extreme-wal-size-threshold)
+ ;; Since the WAL is really getting too big, wait for much longer
+ (sqlite-exec db "PRAGMA busy_timeout = 120000;"))
+
+ (let* ((statement
+ (sqlite-prepare
+ db
+ "PRAGMA wal_checkpoint(TRUNCATE);"))
+ (result
+ (match (sqlite-step-and-finalize statement)
+ (#(blocked? modified-page-count pages-moved-to-db)
+ (if (= blocked? 1)
+ (begin
+ (simple-format
+ (current-error-port)
+ "warning: wal checkpoint blocked\n")
+ #f)
+ (begin
+ (simple-format
+ (current-error-port)
+ "wal checkpoint completed (~A, ~A)\n"
+ modified-page-count
+ pages-moved-to-db)
+ #t))))))
+ (sqlite-exec db "PRAGMA busy_timeout = 5000;")
+
+ result)))
#t))
(call-with-duration-metric