[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#70494] [PATCH 01/23] store: database: Register derivation outputs.
From: |
Christopher Baines |
Subject: |
[bug#70494] [PATCH 01/23] store: database: Register derivation outputs. |
Date: |
Sun, 21 Apr 2024 10:42:19 +0100 |
From: Caleb Ristvedt <caleb.ristvedt@cune.org>
* guix/store/database.scm (register-derivation-outputs,
registered-derivation-outputs): New procedures
(register-valid-path): Call register-derivation-outputs for derivations.
Co-authored-by: Christopher Baines <mail@cbaines.net>
Change-Id: Id958709f36f24ee1c9c375807e8146a9d1cc4259
---
guix/store/database.scm | 49 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/guix/store/database.scm b/guix/store/database.scm
index a847f9d2f0..6a9acc2aef 100644
--- a/guix/store/database.scm
+++ b/guix/store/database.scm
@@ -22,6 +22,9 @@
(define-module (guix store database)
#:use-module (sqlite3)
#:use-module (guix config)
+ #:use-module (guix serialization)
+ #:use-module (guix store)
+ #:use-module (guix derivations)
#:use-module (guix store deduplication)
#:use-module (guix base16)
#:use-module (guix progress)
@@ -44,7 +47,9 @@ (define-module (guix store database)
valid-path-id
register-valid-path
+ register-derivation-outputs
register-items
+ registered-derivation-outputs
%epoch
reset-timestamps
vacuum-database))
@@ -206,6 +211,26 @@ (define-inlinable (assert-integer proc in-range? key
number)
"Integer ~A out of range: ~S" (list key number)
(list number))))
+(define (register-derivation-outputs db drv)
+ "Register all output paths of DRV as being produced by it (note that
+this doesn't mean 'already produced by it', but rather just 'associated with
+it')."
+ (let ((stmt (sqlite-prepare
+ db
+ "
+INSERT OR REPLACE INTO DerivationOutputs (drv, id, path)
+SELECT id, :outid, :outpath FROM ValidPaths WHERE path = :drvpath;"
+ #:cache? #t)))
+ (for-each (match-lambda
+ ((outid . ($ <derivation-output> path))
+ (sqlite-bind-arguments stmt
+ #:drvpath (derivation-file-name
+ drv)
+ #:outid outid
+ #:outpath path)
+ (sqlite-step-and-reset stmt)))
+ (derivation-outputs drv))))
+
(define (add-references db referrer references)
"REFERRER is the id of the referring store item, REFERENCES is a list
ids of items referred to."
@@ -284,6 +309,11 @@ (define* (register-valid-path db #:key path (references
'())
(sqlite-step-and-reset stmt)
(last-insert-row-id db)))))
+ (when (derivation-path? path)
+ (register-derivation-outputs db
+ (read-derivation-from-file
+ path)))
+
;; Call 'path-id' on each of REFERENCES. This ensures we get a
;; "non-NULL constraint" failure if one of REFERENCES is unregistered.
(add-references db id
@@ -331,6 +361,25 @@ (define %epoch
;; When it all began.
(make-time time-utc 0 1))
+(define (registered-derivation-outputs db drv)
+ "Get the list of (id, output-path) pairs registered for DRV."
+ (let ((stmt (sqlite-prepare
+ db
+ "
+SELECT id, path
+FROM DerivationOutputs
+WHERE drv in (SELECT id from ValidPaths where path = :drv)"
+ #:cache? #t)))
+ (sqlite-bind-arguments stmt #:drv drv)
+ (let ((result (sqlite-fold (lambda (current prev)
+ (match current
+ (#(id path)
+ (cons (cons id path)
+ prev))))
+ '() stmt)))
+ (sqlite-reset stmt)
+ result)))
+
(define* (register-items db items
#:key prefix
(registration-time (timestamp))
base-commit: 92af4ea17f70207fbbf2513f677f3171d4eafd41
--
2.41.0
- [bug#70494] [PATCH 03/23] syscalls: Add missing pieces for derivation build environment., (continued)
- [bug#70494] [PATCH 03/23] syscalls: Add missing pieces for derivation build environment., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 02/23] gnu: linux-container: Make it more suitable for derivation-building., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 07/23] serialization: Export read-byte-string., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 05/23] store: build-derivations: New module., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 16/23] store: database: Log when aborting transactions., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 17/23] store: database: Export transaction helpers., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 04/23] guix: store: environment: New module., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 18/23] guix: http-client: Add network-error?., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 19/23] http-client: Include EPIPE in network-error?., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 20/23] scripts: substitute: Simplify with-timeout usage., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 01/23] store: database: Register derivation outputs.,
Christopher Baines <=
- [bug#70494] [PATCH 21/23] scripts: substitute: Don't enforce cached connections in download-nar., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 08/23] store: Add text-output-path and text-output-path-from-hash., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 09/23] store: Add validate-store-name., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 13/23] syscalls: Add unshare., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 11/23] scripts: substitute: Untangle selecting fast vs small compressions., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 10/23] store: database: Add procedures for querying valid paths., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 12/23] scripts: substitute: Extract script specific output from download-nar., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 23/23] substitutes: Add #:keep-alive? keyword argument to download-nar., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 15/23] store: Export operation-id., Christopher Baines, 2024/04/21
- [bug#70494] [PATCH 06/23] store: Export protocol related constants., Christopher Baines, 2024/04/21