diff options
author | Christopher Baines <mail@cbaines.net> | 2021-02-05 11:07:07 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-02-05 11:07:07 +0000 |
commit | 07f903abaf7efb87e9984ce64dce6f26776c415d (patch) | |
tree | 2d708eefc08dae24016b2a9dcbd57466cb604aa8 | |
parent | 02b75d857aadda35cb7c6afb416c248ada435df2 (diff) | |
download | data-service-07f903abaf7efb87e9984ce64dce6f26776c415d.tar data-service-07f903abaf7efb87e9984ce64dce6f26776c415d.tar.gz |
Fix dropping the job lock
-rw-r--r-- | guix-data-service/jobs/load-new-guix-revision.scm | 144 |
1 files changed, 78 insertions, 66 deletions
diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm index 317c647..50eef74 100644 --- a/guix-data-service/jobs/load-new-guix-revision.scm +++ b/guix-data-service/jobs/load-new-guix-revision.scm @@ -1302,6 +1302,50 @@ WHERE job_id = $1") (prevent-inlining-for-tests extract-information-from) +(define (load-channel-instances git-repository-id commit + channel-derivations-by-system) + ;; Load the channel instances in a different transaction, so that this can + ;; commit prior to the outer transaction + (with-postgresql-connection + "load-new-guix-revision insert channel instances" + (lambda (channel-instances-conn) + (with-postgresql-transaction + channel-instances-conn + (lambda (channel-instances-conn) + + (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 channel-instances-conn + 'load-new-guix-revision-inserts)) + + (let* ((existing-guix-revision-id + (git-repository-id-and-commit->revision-id channel-instances-conn + git-repository-id + commit)) + (guix-revision-id + (or existing-guix-revision-id + (insert-guix-revision channel-instances-conn + git-repository-id commit)))) + (unless existing-guix-revision-id + (insert-channel-instances 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: saved the channel instance derivations to the database\n")) + + guix-revision-id)))))) + (define (load-new-guix-revision conn store git-repository-id commit) (let* ((git-repository-fields (select-git-repository conn git-repository-id)) @@ -1317,72 +1361,40 @@ WHERE job_id = $1") (channel->derivations-by-system conn store channel-for-commit - fetch-with-authentication?))) - - (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") - - ;; COMMIT so that the channel instances are saved to the database, then - ;; start a new transaction for the rest of the processing. - (exec-query conn "COMMIT") - (exec-query conn "BEGIN") - - (let ((store-item - (channel-derivations-by-system->guix-store-item - store - channel-derivations-by-system))) - (if store-item - (begin - (extract-information-from conn store - guix-revision-id - commit store-item) - - (if (defined? 'channel-news-for-commit - (resolve-module '(guix channels))) - (with-time-logging "inserting channel news entries" - (insert-channel-news-entries-for-guix-revision - conn - guix-revision-id - (channel-news-for-commit channel-for-commit commit))) - (begin - (simple-format - #t "debug: importing channel news not supported\n") - #t)) - - (update-package-derivations-table conn - git-repository-id - guix-revision-id - commit)) - (begin - (simple-format #t "Failed to generate store item for ~A\n" - commit) - #f)))))) + fetch-with-authentication?)) + (guix-revision-id + (load-channel-instances git-repository-id commit + channel-derivations-by-system))) + (let ((store-item + (channel-derivations-by-system->guix-store-item + store + channel-derivations-by-system))) + (if store-item + (begin + (extract-information-from conn store + guix-revision-id + commit store-item) + + (if (defined? 'channel-news-for-commit + (resolve-module '(guix channels))) + (with-time-logging "inserting channel news entries" + (insert-channel-news-entries-for-guix-revision + conn + guix-revision-id + (channel-news-for-commit channel-for-commit commit))) + (begin + (simple-format + #t "debug: importing channel news not supported\n") + #t)) + + (update-package-derivations-table conn + git-repository-id + guix-revision-id + commit)) + (begin + (simple-format #t "Failed to generate store item for ~A\n" + commit) + #f))))) (define (enqueue-load-new-guix-revision-job conn git-repository-id commit source) (define query |