From 62ad973fe48319caaadede5c36370bcd08542fbf Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Thu, 9 Sep 2021 17:42:49 +0200 Subject: [PATCH 03/10] store: Define new add-temp-root-and-valid-path? operation. This will allow speeding up 'local-file-compiler' a little, see . * nix/libstore/worker-protocols.hh (WorkerOp)[wopAddTempRootAndIsValidPath): New operation. (PROTOCOL_VERSION): Bump version. * nix/nix-daemon/nix-daemon.cc (performOp)[wopAddTempRootAndIsValidPath]: Handle new operation. * guix/store.scm (add-temp-root-and-valid-path?): New operation. (operation-id)[add-temp-root-and-valid-path?): New operation. (%protocol-version): Bump version. * tests/store.scm ("add-temp-root-valid-path? live", "add-temp-root-and-valid-path? false"): New tests. --- guix/store.scm | 11 +++++++++-- nix/libstore/worker-protocol.hh | 5 +++-- nix/nix-daemon/nix-daemon.cc | 12 ++++++++++++ tests/store.scm | 10 ++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/guix/store.scm b/guix/store.scm index 0463b0e8fa..c9f7b905b7 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -124,6 +124,7 @@ ensure-path find-roots add-temp-root + add-temp-root-and-valid-path? add-indirect-root add-permanent-root remove-permanent-root @@ -195,7 +196,7 @@ derivation-log-file log-file)) -(define %protocol-version #x163) +(define %protocol-version #x164) (define %worker-magic-1 #x6e697863) ; "nixc" (define %worker-magic-2 #x6478696f) ; "dxio" @@ -249,7 +250,8 @@ (query-valid-derivers 33) (optimize-store 34) (verify-store 35) - (built-in-builders 80)) + (built-in-builders 80) + (add-temp-root-and-valid-path? 81)) (define-enumerate-type hash-algo ;; hash.hh @@ -1455,6 +1457,11 @@ potential roots that do not point to store items." Return #t." boolean) +(define-operation (add-temp-root-and-valid-path? (store-path path)) + "Make PATH a temporary root for the duration of the current session, +and test if PATH is a valid store path (see 'valid-path?')." + boolean) + (define-operation (add-indirect-root (string file-name)) "Make the symlink FILE-NAME an indirect root for the garbage collector: whatever store item FILE-NAME points to will not be collected. Return #t on diff --git a/nix/libstore/worker-protocol.hh b/nix/libstore/worker-protocol.hh index ea67b10a5b..bb99e632cf 100644 --- a/nix/libstore/worker-protocol.hh +++ b/nix/libstore/worker-protocol.hh @@ -6,7 +6,7 @@ namespace nix { #define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_2 0x6478696f -#define PROTOCOL_VERSION 0x163 +#define PROTOCOL_VERSION 0x164 #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) @@ -44,7 +44,8 @@ typedef enum { wopQueryValidDerivers = 33, wopOptimiseStore = 34, wopVerifyStore = 35, - wopBuiltinBuilders = 80 + wopBuiltinBuilders = 80, + wopAddTempRootAndIsValidPath = 81 } WorkerOp; diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index 497de11a04..b73bb15a64 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc @@ -306,6 +306,18 @@ static void performOp(bool trusted, unsigned int clientVersion, break; } + case wopAddTempRootAndIsValidPath: { + /* This is a combination of AddTempRoot and IsValidPath, to reduce + the numer of RPC calls made by ‘local-file-compiler’ in (guix gexp). */ + Path path = readStorePath(from); + startWork(); + store->addTempRoot(path); + bool result = store->isValidPath(path); + stopWork(); + writeInt(result, to); + break; + } + case wopQueryValidPaths: { PathSet paths = readStorePaths(from); startWork(); diff --git a/tests/store.scm b/tests/store.scm index 3266fa7a82..d724ff18b2 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -138,10 +139,19 @@ (let ((p (add-text-to-store %store "hello" "hello, world"))) (valid-path? %store p))) +(test-assert "add-temp-root-valid-path? live" + (let ((p (add-text-to-store %store "hello" "hello, world"))) + (add-temp-root-and-valid-path? %store p))) + (test-assert "valid-path? false" (not (valid-path? %store (string-append (%store-prefix) "/" (make-string 32 #\e) "-foobar")))) +(test-assert "add-temp-root-and-valid-path? false" + (not (add-temp-root-and-valid-path? + %store + (string-append (%store-prefix) "/" + (make-string 32 #\e) "-foobar")))) (test-equal "with-store, multiple values" ; '(1 2 3) -- 2.33.0