forked from lix-project/hydra
Pool local store connections
This commit is contained in:
parent
1cefd6cac8
commit
88a05763cc
|
@ -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)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "lru-cache.hh"
|
||||
#include "sync.hh"
|
||||
#include "pool.hh"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
@ -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<ref<Store>()> StoreFactory;
|
||||
typedef Pool<nix::ref<nix::Store>> StorePool;
|
||||
typedef std::function<StorePool::Handle()> StoreFactory;
|
||||
|
||||
class BinaryCacheStore : public Store
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ using namespace nix;
|
|||
|
||||
|
||||
State::State()
|
||||
: localStorePool([]() { return std::make_shared<ref<Store>>(openStore()); })
|
||||
{
|
||||
hydraData = getEnv("HYDRA_DATA");
|
||||
if (hydraData == "") throw Error("$HYDRA_DATA must be set");
|
||||
|
@ -26,9 +27,10 @@ State::State()
|
|||
}
|
||||
|
||||
|
||||
ref<Store> 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<S3BinaryCacheStore>(
|
||||
[]() { 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;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
|
||||
#include "sync.hh"
|
||||
|
||||
|
@ -25,7 +26,14 @@
|
|||
template <class R>
|
||||
class Pool
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::function<std::shared_ptr<R>()> Factory;
|
||||
|
||||
private:
|
||||
|
||||
Factory factory;
|
||||
|
||||
struct State
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
@ -36,6 +44,10 @@ private:
|
|||
|
||||
public:
|
||||
|
||||
Pool(const Factory & factory = []() { return std::make_shared<R>(); })
|
||||
: 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<R>());
|
||||
return Handle(*this, factory());
|
||||
}
|
||||
|
||||
unsigned int count()
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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<time_t> lastDispatcherCheck{0};
|
||||
|
||||
/* Pool of local stores. */
|
||||
nix::StorePool localStorePool;
|
||||
|
||||
/* Destination store. */
|
||||
std::shared_ptr<nix::Store> _destStore;
|
||||
|
||||
|
@ -356,7 +361,7 @@ private:
|
|||
|
||||
/* Return a store object that can access derivations produced by
|
||||
hydra-evaluator. */
|
||||
nix::ref<nix::Store> getLocalStore();
|
||||
nix::StorePool::Handle getLocalStore();
|
||||
|
||||
/* Return a store object to store build results. */
|
||||
nix::ref<nix::Store> getDestStore();
|
||||
|
|
Loading…
Reference in a new issue