aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-data-service/jobs/load-new-guix-revision.scm88
-rw-r--r--guix-data-service/model/guix-revision.scm14
2 files changed, 63 insertions, 39 deletions
diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm
index 423043b..0e051f4 100644
--- a/guix-data-service/jobs/load-new-guix-revision.scm
+++ b/guix-data-service/jobs/load-new-guix-revision.scm
@@ -1316,20 +1316,32 @@ WHERE job_id = $1"
store
channel-for-commit
fetch-with-authentication?)))
- (let ((guix-revision-id
- (insert-guix-revision conn git-repository-id commit)))
- (insert-channel-instances conn
- guix-revision-id
- (filter-map
- (match-lambda
- ((system . derivations)
- (and=>
- (assoc-ref derivations
- 'manifest-entry-item)
- (lambda (drv)
- (cons system drv)))))
- channel-derivations-by-system))
+ (with-time-logging
+ "acquiring advisory transaction lock: load-new-guix-revision-inserts"
+ ;; Wait until this is the only transaction inserting data, to avoid any
+ ;; concurrency issues
+ (obtain-advisory-transaction-lock conn
+ 'load-new-guix-revision-inserts))
+ (let* ((existing-guix-revision-id
+ (git-repository-id-and-commit->revision-id conn
+ git-repository-id
+ commit))
+ (guix-revision-id
+ (or existing-guix-revision-id
+ (insert-guix-revision conn git-repository-id commit))))
+ (unless existing-guix-revision-id
+ (insert-channel-instances conn
+ guix-revision-id
+ (filter-map
+ (match-lambda
+ ((system . derivations)
+ (and=>
+ (assoc-ref derivations
+ 'manifest-entry-item)
+ (lambda (drv)
+ (cons system drv)))))
+ channel-derivations-by-system)))
(simple-format
(current-error-port)
"guix-data-service: saving the channel instance derivations to the database\n")
@@ -1777,32 +1789,30 @@ SKIP LOCKED")
(simple-format #t "Processing job ~A (commit: ~A, source: ~A)\n\n"
id commit source)
- (if (or
- (guix-revision-exists? conn git-repository-id commit)
- (eq?
- (with-time-logging (string-append "loading revision " commit)
- (setup-logging
- id
- (lambda ()
- (with-exception-handler
- (const #f)
- (lambda ()
- (with-exception-handler
- (lambda (exn)
- (simple-format (current-error-port)
- "error: load-new-guix-revision: ~A\n"
- exn)
- (backtrace)
- #f)
- (lambda ()
- (with-store-connection
- (lambda (store)
- (load-new-guix-revision conn
- store
- git-repository-id
- commit))))))
- #:unwind? #t))))
- #t))
+ (if (eq?
+ (with-time-logging (string-append "loading revision " commit)
+ (setup-logging
+ id
+ (lambda ()
+ (with-exception-handler
+ (const #f)
+ (lambda ()
+ (with-exception-handler
+ (lambda (exn)
+ (simple-format (current-error-port)
+ "error: load-new-guix-revision: ~A\n"
+ exn)
+ (backtrace)
+ #f)
+ (lambda ()
+ (with-store-connection
+ (lambda (store)
+ (load-new-guix-revision conn
+ store
+ git-repository-id
+ commit))))))
+ #:unwind? #t))))
+ #t)
(begin
(record-job-succeeded conn id)
(record-job-event conn id "success")
diff --git a/guix-data-service/model/guix-revision.scm b/guix-data-service/model/guix-revision.scm
index 4f5ed6d..f7dc26a 100644
--- a/guix-data-service/model/guix-revision.scm
+++ b/guix-data-service/model/guix-revision.scm
@@ -23,6 +23,7 @@
#:export (count-guix-revisions
most-recent-n-guix-revisions
commit->revision-id
+ git-repository-id-and-commit->revision-id
insert-guix-revision
guix-commit-exists?
guix-revision-exists?
@@ -46,6 +47,19 @@
id)
(() #f)))
+(define (git-repository-id-and-commit->revision-id conn git-repository-id commit)
+ (match (exec-query
+ conn
+ "
+SELECT id
+FROM guix_revisions
+WHERE commit = $1
+ AND git_repository_id = $2"
+ (list commit git-repository-id))
+ (((id))
+ id)
+ (() #f)))
+
(define (insert-guix-revision conn git-repository-id commit)
(define insert
"