From a6bd46b829070fca8843bc0155e5bf2b71d422dd Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 12 Jul 2019 19:54:25 +0100 Subject: [PATCH] Obtain a lock when inserting the data for a new revision This is working towards running the jobs in parallel. Each job looks at the records in the database, and adds missing ones. If other jobs, running in different transactions insert the same missing records at the same time, this could cause an error. Therefore, to just avoid this problem, lock before inserting the data. This will allow the jobs to be processed in parallel, and it shouldn't have too much of an effect on performance, as the slow bit is outside of the transaction. --- guix-data-service/jobs/load-new-guix-revision.scm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm index 401a2c7..a69b690 100644 --- a/guix-data-service/jobs/load-new-guix-revision.scm +++ b/guix-data-service/jobs/load-new-guix-revision.scm @@ -553,6 +553,11 @@ (lambda () (all-inferior-package-derivations store inf packages))))) + ;; 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* ((package-derivation-ids (packages-and-inferior-data->package-derivation-ids conn inf packages inferior-data-4-tuples))