diff options
author | Christopher Baines <mail@cbaines.net> | 2019-12-26 08:53:51 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-12-26 08:53:51 +0000 |
commit | dd94f59acfa4512247f47ae9a1a01077cabaeb6d (patch) | |
tree | 69d6f76ddfbc4c3f0bc949fbfb7ad6832860fb8b /guix-data-service | |
parent | 4eb5a3417c13f74745ec7ca3d92a95096c176da1 (diff) | |
download | data-service-dd94f59acfa4512247f47ae9a1a01077cabaeb6d.tar data-service-dd94f59acfa4512247f47ae9a1a01077cabaeb6d.tar.gz |
Fix the representation of the fixed output derivation hashes
Previously, they were nix-base32-string encoded, but the representation in the
derivations is base16, so it doesn't make sense to use a different
representation in the database.
Therefore, add some code that runs before the start of each job to convert the
data in the database. It was easier to do this in Guile with the existing
support for working with these bytevector representations. After some
migration period, the code for converting the old hashes can be removed.
Diffstat (limited to 'guix-data-service')
-rw-r--r-- | guix-data-service/jobs/load-new-guix-revision.scm | 5 | ||||
-rw-r--r-- | guix-data-service/model/derivation.scm | 48 |
2 files changed, 52 insertions, 1 deletions
diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm index 1c58f21..753bfbd 100644 --- a/guix-data-service/jobs/load-new-guix-revision.scm +++ b/guix-data-service/jobs/load-new-guix-revision.scm @@ -1236,6 +1236,11 @@ SKIP LOCKED") (with-postgresql-connection (simple-format #f "load-new-guix-revision ~A" id) (lambda (conn) + ;; Fix the hash encoding of derivation_output_details. This'll only run + ;; once on any given database, but is kept here just to make sure any + ;; instances have the data updated. + (fix-derivation-output-details-hash-encoding conn) + (exec-query conn "BEGIN") (match (select-job-for-update conn id) diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm index 49973be..a585028 100644 --- a/guix-data-service/model/derivation.scm +++ b/guix-data-service/model/derivation.scm @@ -4,6 +4,7 @@ #:use-module (ice-9 match) #:use-module (squee) #:use-module (json) + #:use-module (guix base16) #:use-module (guix base32) #:use-module (guix inferior) #:use-module (guix memoization) @@ -20,6 +21,7 @@ select-derivations-using-output select-derivations-in-revision select-derivation-outputs-in-revision + fix-derivation-output-details-hash-encoding select-derivations-by-revision-name-and-version select-derivation-inputs-by-derivation-id select-existing-derivations @@ -400,6 +402,50 @@ ORDER BY derivation_output_details.path (list target) '()))))) +(define (fix-derivation-output-details-hash-encoding conn) + (define (find-old-derivations-and-hashes conn) + (exec-query + conn + " +SELECT id, hash +FROM derivation_output_details +WHERE hash_algorithm = 'sha256' AND char_length(hash) = 52 LIMIT 100")) + + (define (fix-batch data) + (for-each + (match-lambda + ((id base32-hash) + (exec-query + conn + " +UPDATE derivation_output_details +SET hash = $2 +WHERE id = $1" + (list id + (bytevector->base16-string + (nix-base32-string->bytevector base32-hash)))))) + data)) + + (unless (null? (find-old-derivations-and-hashes conn)) + (with-postgresql-transaction + conn + (lambda (conn) + (exec-query + conn + " +LOCK TABLE ONLY derivation_output_details + IN SHARE ROW EXCLUSIVE MODE") + + (let loop ((data (find-old-derivations-and-hashes conn))) + (unless (null? data) + (fix-batch data) + + (simple-format #t "updated ~A old hashes\n" + (length data)) + + ;; Recurse in case there are more to fix + (loop (find-old-derivations-and-hashes conn)))))))) + (define (insert-derivation-outputs conn derivation-id names-and-derivation-outputs) @@ -418,7 +464,7 @@ ORDER BY derivation_output_details.path (value->quoted-string-or-null (and=> hash-algo symbol->string)) (value->quoted-string-or-null - (and=> hash bytevector->nix-base32-string)) + (and=> hash bytevector->base16-string)) (if recursive? "TRUE" "FALSE")) ",") ")"))) |