diff --git a/src/hydra-queue-runner/binary-cache-store.cc b/src/hydra-queue-runner/binary-cache-store.cc index d9cd0a4e..bf9215d5 100644 --- a/src/hydra-queue-runner/binary-cache-store.cc +++ b/src/hydra-queue-runner/binary-cache-store.cc @@ -11,9 +11,9 @@ namespace nix { -BinaryCacheStore::BinaryCacheStore(ref localStore, +BinaryCacheStore::BinaryCacheStore(const StoreFactory & storeFactory, const Path & secretKeyFile, const Path & publicKeyFile) - : localStore(localStore) + : storeFactory(storeFactory) { if (secretKeyFile != "") secretKey = std::unique_ptr(new SecretKey(readFile(secretKeyFile))); @@ -192,6 +192,8 @@ void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths, { PathSet left; + auto localStore = storeFactory(); + for (auto & storePath : paths) { if (!localStore->isValidPath(storePath)) { left.insert(storePath); @@ -210,6 +212,8 @@ void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths, void BinaryCacheStore::buildPaths(const PathSet & paths, BuildMode buildMode) { + auto localStore = storeFactory(); + for (auto & storePath : paths) { assert(!isDerivation(storePath)); diff --git a/src/hydra-queue-runner/binary-cache-store.hh b/src/hydra-queue-runner/binary-cache-store.hh index 0db7ddc4..8883075b 100644 --- a/src/hydra-queue-runner/binary-cache-store.hh +++ b/src/hydra-queue-runner/binary-cache-store.hh @@ -7,18 +7,23 @@ namespace nix { struct NarInfo; +/* While BinaryCacheStore is thread-safe, LocalStore and RemoteStore + aren't. Until they are, use a factory to produce a thread-local + local store. */ +typedef std::function()> StoreFactory; + class BinaryCacheStore : public Store { private: - ref localStore; - std::unique_ptr secretKey; std::unique_ptr publicKeys; + StoreFactory storeFactory; + protected: - BinaryCacheStore(ref localStore, + BinaryCacheStore(const StoreFactory & storeFactory, const Path & secretKeyFile, const Path & publicKeyFile); virtual bool fileExists(const std::string & path) = 0; diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index d64ffd0c..afa4a565 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -23,6 +23,21 @@ State::State() if (hydraData == "") throw Error("$HYDRA_DATA must be set"); logDir = canonPath(hydraData + "/build-logs"); + +#if 0 + auto store = make_ref(getLocalStore(), + "/home/eelco/Misc/Keys/test.nixos.org/secret", + "/home/eelco/Misc/Keys/test.nixos.org/public", + "/tmp/binary-cache"); +#endif + + auto store = std::make_shared( + []() { return openStore(); }, + "/home/eelco/Misc/Keys/test.nixos.org/secret", + "/home/eelco/Misc/Keys/test.nixos.org/public", + "nix-test-cache-3");; + store->init(); + _destStore = store; } @@ -34,18 +49,7 @@ ref State::getLocalStore() ref State::getDestStore() { -#if 0 - auto store = make_ref(getLocalStore(), - "/home/eelco/Misc/Keys/test.nixos.org/secret", - "/home/eelco/Misc/Keys/test.nixos.org/public", - "/tmp/binary-cache"); -#endif - auto store = make_ref(getLocalStore(), - "/home/eelco/Misc/Keys/test.nixos.org/secret", - "/home/eelco/Misc/Keys/test.nixos.org/public", - "nix-test-cache-3"); - store->init(); - return store; + return ref(_destStore); } diff --git a/src/hydra-queue-runner/local-binary-cache-store.cc b/src/hydra-queue-runner/local-binary-cache-store.cc index 250eb3c1..a82e6597 100644 --- a/src/hydra-queue-runner/local-binary-cache-store.cc +++ b/src/hydra-queue-runner/local-binary-cache-store.cc @@ -2,10 +2,10 @@ namespace nix { -LocalBinaryCacheStore::LocalBinaryCacheStore(ref localStore, +LocalBinaryCacheStore::LocalBinaryCacheStore(const StoreFactory & storeFactory, const Path & secretKeyFile, const Path & publicKeyFile, const Path & binaryCacheDir) - : BinaryCacheStore(localStore, secretKeyFile, publicKeyFile) + : BinaryCacheStore(storeFactory, secretKeyFile, publicKeyFile) , binaryCacheDir(binaryCacheDir) { } diff --git a/src/hydra-queue-runner/local-binary-cache-store.hh b/src/hydra-queue-runner/local-binary-cache-store.hh index 26bac146..e29d0ca2 100644 --- a/src/hydra-queue-runner/local-binary-cache-store.hh +++ b/src/hydra-queue-runner/local-binary-cache-store.hh @@ -12,7 +12,7 @@ private: public: - LocalBinaryCacheStore(ref localStore, + LocalBinaryCacheStore(const StoreFactory & storeFactory, const Path & secretKeyFile, const Path & publicKeyFile, const Path & binaryCacheDir); diff --git a/src/hydra-queue-runner/s3-binary-cache-store.cc b/src/hydra-queue-runner/s3-binary-cache-store.cc index 0fa33b25..9d545d29 100644 --- a/src/hydra-queue-runner/s3-binary-cache-store.cc +++ b/src/hydra-queue-runner/s3-binary-cache-store.cc @@ -20,10 +20,10 @@ R && checkAws(Aws::Utils::Outcome && outcome) return outcome.GetResultWithOwnership(); } -S3BinaryCacheStore::S3BinaryCacheStore(ref localStore, +S3BinaryCacheStore::S3BinaryCacheStore(const StoreFactory & storeFactory, const Path & secretKeyFile, const Path & publicKeyFile, const std::string & bucketName) - : BinaryCacheStore(localStore, secretKeyFile, publicKeyFile) + : BinaryCacheStore(storeFactory, secretKeyFile, publicKeyFile) , bucketName(bucketName) , config(makeConfig()) , client(make_ref(*config)) diff --git a/src/hydra-queue-runner/s3-binary-cache-store.hh b/src/hydra-queue-runner/s3-binary-cache-store.hh index 2c11a164..a39a498b 100644 --- a/src/hydra-queue-runner/s3-binary-cache-store.hh +++ b/src/hydra-queue-runner/s3-binary-cache-store.hh @@ -18,7 +18,7 @@ private: public: - S3BinaryCacheStore(ref localStore, + S3BinaryCacheStore(const StoreFactory & storeFactory, const Path & secretKeyFile, const Path & publicKeyFile, const std::string & bucketName); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index aa9c1f38..eb9d6457 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -346,6 +346,9 @@ private: std::atomic lastDispatcherCheck{0}; + /* Destination store. */ + std::shared_ptr _destStore; + public: State();