diff options
author | Christopher Baines <mail@cbaines.net> | 2023-04-20 23:38:10 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-04-20 23:38:10 +0100 |
commit | 2a39a4e5ecb5143c4fcedd7f804da88162cebeb9 (patch) | |
tree | 29541269def80d9bd38310d5156a3d50000f6e24 /guix-build-coordinator | |
parent | a627595b15e8fbe62178ec3fbed904f9c6a04533 (diff) | |
download | build-coordinator-2a39a4e5ecb5143c4fcedd7f804da88162cebeb9.tar build-coordinator-2a39a4e5ecb5143c4fcedd7f804da88162cebeb9.tar.gz |
Improve datastore-call-with-transaction
Include exception in log message, and separate out exception handling for the
transaction start and body.
Diffstat (limited to 'guix-build-coordinator')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index fa871be..6408059 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -422,20 +422,23 @@ PRAGMA optimize;"))))) (immediate? (not readonly?)) duration-metric-name) (define (run-proc-within-transaction db) - (with-exception-handler - (lambda (exn) - (match (exception-args exn) - (('sqlite-exec 5 msg) - (simple-format (current-error-port) "warning: sqlite error: ~A\n" msg) - (run-proc-within-transaction db)) - (_ - (simple-format (current-error-port) - "exception starting transaction\n") - (raise-exception exn)))) - (lambda () - (sqlite-exec db (if immediate? - "BEGIN IMMEDIATE TRANSACTION;" - "BEGIN TRANSACTION;")) + (if (with-exception-handler + (lambda (exn) + (match (exception-args exn) + (('sqlite-exec 5 msg) + (simple-format (current-error-port) "warning: sqlite error: ~A\n" msg) + #f) + (_ + (simple-format (current-error-port) + "exception starting transaction\n") + (raise-exception exn)))) + (lambda () + (sqlite-exec db (if immediate? + "BEGIN IMMEDIATE TRANSACTION;" + "BEGIN TRANSACTION;")) + #t) + #:unwind? #t) + (with-exception-handler (lambda (exn) (if (transaction-rollback-exception? exn) @@ -444,7 +447,8 @@ PRAGMA optimize;"))))) (transaction-rollback-exception-return-value exn)) (begin (simple-format (current-error-port) - "error: sqlite rolling back transaction\n") + "error: sqlite rolling back transaction (~A)\n" + exn) (sqlite-exec db "ROLLBACK TRANSACTION;") (raise-exception exn)))) (lambda () @@ -455,8 +459,10 @@ PRAGMA optimize;"))))) (lambda vals (sqlite-exec db "COMMIT TRANSACTION;") (apply values vals)))) - #:unwind? #t)) - #:unwind? #t)) + #:unwind? #t) + + ;; Database is busy, so retry + (run-proc-within-transaction db))) (define (proc-with-duration-timing db) (let ((start-time (get-internal-real-time))) |