Crudely make worker only provide a Store, not LocalStore

We downcast in a few places, this will be refactored to be better later.
This commit is contained in:
John Ericson 2020-12-20 17:36:52 +00:00
parent 12f7a1f65b
commit 450c3500f1
3 changed files with 54 additions and 27 deletions

View file

@ -848,14 +848,16 @@ void DerivationGoal::buildDone()
So instead, check if the disk is (nearly) full now. If So instead, check if the disk is (nearly) full now. If
so, we don't mark this build as a permanent failure. */ so, we don't mark this build as a permanent failure. */
#if HAVE_STATVFS #if HAVE_STATVFS
uint64_t required = 8ULL * 1024 * 1024; // FIXME: make configurable if (auto localStore = dynamic_cast<LocalStore *>(&worker.store)) {
struct statvfs st; uint64_t required = 8ULL * 1024 * 1024; // FIXME: make configurable
if (statvfs(worker.store.realStoreDir.c_str(), &st) == 0 && struct statvfs st;
(uint64_t) st.f_bavail * st.f_bsize < required) if (statvfs(localStore->realStoreDir.c_str(), &st) == 0 &&
diskFull = true; (uint64_t) st.f_bavail * st.f_bsize < required)
if (statvfs(tmpDir.c_str(), &st) == 0 && diskFull = true;
(uint64_t) st.f_bavail * st.f_bsize < required) if (statvfs(tmpDir.c_str(), &st) == 0 &&
diskFull = true; (uint64_t) st.f_bavail * st.f_bsize < required)
diskFull = true;
}
#endif #endif
deleteTmpDir(false); deleteTmpDir(false);
@ -1215,12 +1217,15 @@ void DerivationGoal::startBuilder()
useChroot = !(derivationIsImpure(derivationType)) && !noChroot; useChroot = !(derivationIsImpure(derivationType)) && !noChroot;
} }
if (worker.store.storeDir != worker.store.realStoreDir) { if (auto localStoreP = dynamic_cast<LocalStore *>(&worker.store)) {
#if __linux__ auto & localStore = *localStoreP;
useChroot = true; if (localStore.storeDir != localStore.realStoreDir) {
#else #if __linux__
throw Error("building using a diverted store is not supported on this platform"); useChroot = true;
#endif #else
throw Error("building using a diverted store is not supported on this platform");
#endif
}
} }
/* Create a temporary directory where the build will take /* Create a temporary directory where the build will take
@ -2182,7 +2187,8 @@ void DerivationGoal::startDaemon()
Store::Params params; Store::Params params;
params["path-info-cache-size"] = "0"; params["path-info-cache-size"] = "0";
params["store"] = worker.store.storeDir; params["store"] = worker.store.storeDir;
params["root"] = worker.store.rootDir; if (auto localStore = dynamic_cast<LocalStore *>(&worker.store))
params["root"] = localStore->rootDir;
params["state"] = "/no-such-path"; params["state"] = "/no-such-path";
params["log"] = "/no-such-path"; params["log"] = "/no-such-path";
auto store = make_ref<RestrictedStore>(params, auto store = make_ref<RestrictedStore>(params,
@ -3246,7 +3252,13 @@ void DerivationGoal::registerOutputs()
} }
} }
auto localStoreP = dynamic_cast<LocalStore *>(&worker.store);
if (!localStoreP)
Unsupported("Can only register outputs with local store");
auto & localStore = *localStoreP;
if (buildMode == bmCheck) { if (buildMode == bmCheck) {
if (!worker.store.isValidPath(newInfo.path)) continue; if (!worker.store.isValidPath(newInfo.path)) continue;
ValidPathInfo oldInfo(*worker.store.queryPathInfo(newInfo.path)); ValidPathInfo oldInfo(*worker.store.queryPathInfo(newInfo.path));
if (newInfo.narHash != oldInfo.narHash) { if (newInfo.narHash != oldInfo.narHash) {
@ -3271,8 +3283,8 @@ void DerivationGoal::registerOutputs()
/* Since we verified the build, it's now ultimately trusted. */ /* Since we verified the build, it's now ultimately trusted. */
if (!oldInfo.ultimate) { if (!oldInfo.ultimate) {
oldInfo.ultimate = true; oldInfo.ultimate = true;
worker.store.signPathInfo(oldInfo); localStore.signPathInfo(oldInfo);
worker.store.registerValidPaths({{oldInfo.path, oldInfo}}); localStore.registerValidPaths({{oldInfo.path, oldInfo}});
} }
continue; continue;
@ -3288,13 +3300,13 @@ void DerivationGoal::registerOutputs()
} }
if (curRound == nrRounds) { if (curRound == nrRounds) {
worker.store.optimisePath(actualPath); // FIXME: combine with scanForReferences() localStore.optimisePath(actualPath); // FIXME: combine with scanForReferences()
worker.markContentsGood(newInfo.path); worker.markContentsGood(newInfo.path);
} }
newInfo.deriver = drvPath; newInfo.deriver = drvPath;
newInfo.ultimate = true; newInfo.ultimate = true;
worker.store.signPathInfo(newInfo); localStore.signPathInfo(newInfo);
finish(newInfo.path); finish(newInfo.path);
@ -3302,7 +3314,7 @@ void DerivationGoal::registerOutputs()
isn't statically known so that we can safely unlock the path before isn't statically known so that we can safely unlock the path before
the next iteration */ the next iteration */
if (newInfo.ca) if (newInfo.ca)
worker.store.registerValidPaths({{newInfo.path, newInfo}}); localStore.registerValidPaths({{newInfo.path, newInfo}});
infos.emplace(outputName, std::move(newInfo)); infos.emplace(outputName, std::move(newInfo));
} }
@ -3375,11 +3387,16 @@ void DerivationGoal::registerOutputs()
paths referenced by each of them. If there are cycles in the paths referenced by each of them. If there are cycles in the
outputs, this will fail. */ outputs, this will fail. */
{ {
auto localStoreP = dynamic_cast<LocalStore *>(&worker.store);
if (!localStoreP)
Unsupported("Can only register outputs with local store");
auto & localStore = *localStoreP;
ValidPathInfos infos2; ValidPathInfos infos2;
for (auto & [outputName, newInfo] : infos) { for (auto & [outputName, newInfo] : infos) {
infos2.insert_or_assign(newInfo.path, newInfo); infos2.insert_or_assign(newInfo.path, newInfo);
} }
worker.store.registerValidPaths(infos2); localStore.registerValidPaths(infos2);
} }
/* In case of a fixed-output derivation hash mismatch, throw an /* In case of a fixed-output derivation hash mismatch, throw an
@ -3577,7 +3594,12 @@ Path DerivationGoal::openLogFile()
auto baseName = std::string(baseNameOf(worker.store.printStorePath(drvPath))); auto baseName = std::string(baseNameOf(worker.store.printStorePath(drvPath)));
/* Create a log file. */ /* Create a log file. */
Path dir = fmt("%s/%s/%s/", worker.store.logDir, worker.store.drvsLogDir, string(baseName, 0, 2)); Path logDir;
if (auto localStore = dynamic_cast<LocalStore *>(&worker.store))
logDir = localStore->logDir;
else
logDir = settings.nixLogDir;
Path dir = fmt("%s/%s/%s/", logDir, LocalFSStore::drvsLogDir, string(baseName, 0, 2));
createDirs(dir); createDirs(dir);
Path logFileName = fmt("%s/%s%s", dir, string(baseName, 2), Path logFileName = fmt("%s/%s%s", dir, string(baseName, 2),

View file

@ -8,7 +8,7 @@
namespace nix { namespace nix {
Worker::Worker(LocalStore & store) Worker::Worker(Store & store)
: act(*logger, actRealise) : act(*logger, actRealise)
, actDerivations(*logger, actBuilds) , actDerivations(*logger, actBuilds)
, actSubstitutions(*logger, actCopyPaths) , actSubstitutions(*logger, actCopyPaths)
@ -229,7 +229,9 @@ void Worker::run(const Goals & _topGoals)
checkInterrupt(); checkInterrupt();
store.autoGC(false); // TODO GC interface?
if (auto localStore = dynamic_cast<LocalStore *>(&store))
localStore->autoGC(false);
/* Call every wake goal (in the ordering established by /* Call every wake goal (in the ordering established by
CompareGoalPtrs). */ CompareGoalPtrs). */

View file

@ -2,9 +2,12 @@
#include "types.hh" #include "types.hh"
#include "lock.hh" #include "lock.hh"
#include "local-store.hh" #include "store-api.hh"
#include "goal.hh" #include "goal.hh"
#include <future>
#include <thread>
namespace nix { namespace nix {
/* Forward definition. */ /* Forward definition. */
@ -102,7 +105,7 @@ public:
/* Set if at least one derivation is not deterministic in check mode. */ /* Set if at least one derivation is not deterministic in check mode. */
bool checkMismatch; bool checkMismatch;
LocalStore & store; Store & store;
std::unique_ptr<HookInstance> hook; std::unique_ptr<HookInstance> hook;
@ -124,7 +127,7 @@ public:
it answers with "decline-permanently", we don't try again. */ it answers with "decline-permanently", we don't try again. */
bool tryBuildHook = true; bool tryBuildHook = true;
Worker(LocalStore & store); Worker(Store & store);
~Worker(); ~Worker();
/* Make a goal (with caching). */ /* Make a goal (with caching). */