diff --git a/src/hydra-queue-runner/binary-cache-store.cc b/src/hydra-queue-runner/binary-cache-store.cc index 873b83b4..f4e9b652 100644 --- a/src/hydra-queue-runner/binary-cache-store.cc +++ b/src/hydra-queue-runner/binary-cache-store.cc @@ -234,11 +234,11 @@ void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths, auto localStore = storeFactory(); for (auto & storePath : paths) { - if (!localStore->isValidPath(storePath)) { + if (!(*localStore)->isValidPath(storePath)) { left.insert(storePath); continue; } - ValidPathInfo info = localStore->queryPathInfo(storePath); + ValidPathInfo info = (*localStore)->queryPathInfo(storePath); SubstitutablePathInfo sub; sub.references = info.references; sub.downloadSize = 0; @@ -246,7 +246,7 @@ void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths, infos.emplace(storePath, sub); } - localStore->querySubstitutablePathInfos(left, infos); + //(*localStore)->querySubstitutablePathInfos(left, infos); } void BinaryCacheStore::buildPaths(const PathSet & paths, BuildMode buildMode) @@ -258,12 +258,12 @@ void BinaryCacheStore::buildPaths(const PathSet & paths, BuildMode buildMode) if (isValidPath(storePath)) continue; - localStore->addTempRoot(storePath); + (*localStore)->addTempRoot(storePath); - if (!localStore->isValidPath(storePath)) - localStore->ensurePath(storePath); + if (!(*localStore)->isValidPath(storePath)) + (*localStore)->ensurePath(storePath); - ValidPathInfo info = localStore->queryPathInfo(storePath); + ValidPathInfo info = (*localStore)->queryPathInfo(storePath); for (auto & ref : info.references) if (ref != storePath) diff --git a/src/hydra-queue-runner/binary-cache-store.hh b/src/hydra-queue-runner/binary-cache-store.hh index 8b2d4a81..4d02b3b2 100644 --- a/src/hydra-queue-runner/binary-cache-store.hh +++ b/src/hydra-queue-runner/binary-cache-store.hh @@ -5,6 +5,7 @@ #include "lru-cache.hh" #include "sync.hh" +#include "pool.hh" #include @@ -15,7 +16,8 @@ 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; +typedef Pool> StorePool; +typedef std::function StoreFactory; class BinaryCacheStore : public Store { diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 8080af7a..6fd6e2f8 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -18,6 +18,7 @@ using namespace nix; State::State() + : localStorePool([]() { return std::make_shared>(openStore()); }) { hydraData = getEnv("HYDRA_DATA"); if (hydraData == "") throw Error("$HYDRA_DATA must be set"); @@ -26,9 +27,10 @@ State::State() } -ref State::getLocalStore() +StorePool::Handle State::getLocalStore() { - return openStore(); // FIXME: pool + auto conn(localStorePool.get()); + return conn; } @@ -733,10 +735,10 @@ void State::run(BuildID buildOne) #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");; + [this]() { return this->getLocalStore(); }, + "/home/eelco/hydra/secret", + "/home/eelco/hydra/public", + "nix-test-cache"); store->init(); _destStore = store; diff --git a/src/hydra-queue-runner/pool.hh b/src/hydra-queue-runner/pool.hh index a1cd3977..83d947e3 100644 --- a/src/hydra-queue-runner/pool.hh +++ b/src/hydra-queue-runner/pool.hh @@ -2,6 +2,7 @@ #include #include +#include #include "sync.hh" @@ -25,7 +26,14 @@ template class Pool { +public: + + typedef std::function()> Factory; + private: + + Factory factory; + struct State { unsigned int count = 0; @@ -36,6 +44,10 @@ private: public: + Pool(const Factory & factory = []() { return std::make_shared(); }) + : factory(factory) + { } + class Handle { private: @@ -74,7 +86,7 @@ public: } /* Note: we don't hold the lock while creating a new instance, because creation might take a long time. */ - return Handle(*this, std::make_shared()); + return Handle(*this, factory()); } unsigned int count() diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index f7e40827..f3970407 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -36,7 +36,7 @@ void State::queueMonitorLoop() unsigned int lastBuildId = 0; while (true) { - bool done = getQueuedBuilds(*conn, localStore, destStore, lastBuildId); + bool done = getQueuedBuilds(*conn, *localStore, destStore, lastBuildId); /* Sleep until we get notification from the database about an event. */ diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index eb9d6457..a524670d 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -16,6 +16,8 @@ #include "store-api.hh" #include "derivations.hh" +#include "binary-cache-store.hh" // FIXME + typedef unsigned int BuildID; @@ -346,6 +348,9 @@ private: std::atomic lastDispatcherCheck{0}; + /* Pool of local stores. */ + nix::StorePool localStorePool; + /* Destination store. */ std::shared_ptr _destStore; @@ -356,7 +361,7 @@ private: /* Return a store object that can access derivations produced by hydra-evaluator. */ - nix::ref getLocalStore(); + nix::StorePool::Handle getLocalStore(); /* Return a store object to store build results. */ nix::ref getDestStore();