From 63745b8e257d68687f563937400e5884f10c8b2c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 7 Jul 2015 10:25:33 +0200 Subject: [PATCH] Move buildRemote() into State --- src/hydra-queue-runner/Makefile.am | 2 +- src/hydra-queue-runner/build-remote.cc | 46 +++++++++----------- src/hydra-queue-runner/build-remote.hh | 28 ------------ src/hydra-queue-runner/hydra-queue-runner.cc | 6 +-- src/hydra-queue-runner/state.hh | 19 ++++++++ 5 files changed, 42 insertions(+), 59 deletions(-) delete mode 100644 src/hydra-queue-runner/build-remote.hh diff --git a/src/hydra-queue-runner/Makefile.am b/src/hydra-queue-runner/Makefile.am index 5acc7729..f947ddc4 100644 --- a/src/hydra-queue-runner/Makefile.am +++ b/src/hydra-queue-runner/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = hydra-queue-runner hydra_queue_runner_SOURCES = hydra-queue-runner.cc build-result.cc build-remote.cc \ - build-remote.hh build-result.hh counter.hh pool.hh sync.hh token-server.hh state.hh db.hh + build-result.hh counter.hh pool.hh sync.hh token-server.hh state.hh db.hh hydra_queue_runner_LDADD = $(NIX_LIBS) -lpqxx AM_CXXFLAGS = $(NIX_CFLAGS) -Wall diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc index f9a0483a..c87d040b 100644 --- a/src/hydra-queue-runner/build-remote.cc +++ b/src/hydra-queue-runner/build-remote.cc @@ -4,11 +4,10 @@ #include #include -#include "build-remote.hh" - -#include "util.hh" #include "misc.hh" #include "serve-protocol.hh" +#include "state.hh" +#include "util.hh" #include "worker-protocol.hh" using namespace nix; @@ -141,15 +140,12 @@ static void copyClosureFrom(std::shared_ptr store, } -void buildRemote(std::shared_ptr store, - const string & sshName, const string & sshKey, - const Path & drvPath, const Derivation & drv, - const nix::Path & logDir, unsigned int maxSilentTime, unsigned int buildTimeout, - TokenServer & copyClosureTokenServer, RemoteResult & result, - counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom, - counter & bytesSent, counter & bytesReceived) +void State::buildRemote(std::shared_ptr store, + Machine::ptr machine, Step::ptr step, + unsigned int maxSilentTime, unsigned int buildTimeout, + RemoteResult & result) { - string base = baseNameOf(drvPath); + string base = baseNameOf(step->drvPath); result.logFile = logDir + "/" + string(base, 0, 2) + "/" + string(base, 2); AutoDelete autoDelete(result.logFile, false); @@ -159,7 +155,7 @@ void buildRemote(std::shared_ptr store, if (logFD == -1) throw SysError(format("creating log file ‘%1%’") % result.logFile); Child child; - openConnection(sshName, sshKey, logFD, child); + openConnection(machine->sshName, machine->sshKey, logFD, child); logFD.close(); @@ -174,19 +170,19 @@ void buildRemote(std::shared_ptr store, unsigned int magic = readInt(from); if (magic != SERVE_MAGIC_2) - throw Error(format("protocol mismatch with ‘nix-store --serve’ on ‘%1%’") % sshName); + throw Error(format("protocol mismatch with ‘nix-store --serve’ on ‘%1%’") % machine->sshName); unsigned int version = readInt(from); if (GET_PROTOCOL_MAJOR(version) != 0x200) - throw Error(format("unsupported ‘nix-store --serve’ protocol version on ‘%1%’") % sshName); + throw Error(format("unsupported ‘nix-store --serve’ protocol version on ‘%1%’") % machine->sshName); } catch (EndOfFile & e) { child.pid.wait(true); string s = chomp(readFile(result.logFile)); - throw Error(format("cannot connect to ‘%1%’: %2%") % sshName % s); + throw Error(format("cannot connect to ‘%1%’: %2%") % machine->sshName % s); } /* Gather the inputs. */ - PathSet inputs({drvPath}); - for (auto & input : drv.inputDrvs) { + PathSet inputs({step->drvPath}); + for (auto & input : step->drv.inputDrvs) { Derivation drv2 = readDerivation(input.first); for (auto & name : input.second) { auto i = drv2.outputs.find(name); @@ -195,8 +191,8 @@ void buildRemote(std::shared_ptr store, } /* Copy the input closure. */ - if (sshName != "localhost") { - printMsg(lvlDebug, format("sending closure of ‘%1%’ to ‘%2%’") % drvPath % sshName); + if (machine->sshName != "localhost") { + printMsg(lvlDebug, format("sending closure of ‘%1%’ to ‘%2%’") % step->drvPath % machine->sshName); MaintainCount mc(nrStepsCopyingTo); copyClosureTo(store, from, to, inputs, copyClosureTokenServer, bytesSent); } @@ -204,9 +200,9 @@ void buildRemote(std::shared_ptr store, autoDelete.cancel(); /* Do the build. */ - printMsg(lvlDebug, format("building ‘%1%’ on ‘%2%’") % drvPath % sshName); + printMsg(lvlDebug, format("building ‘%1%’ on ‘%2%’") % step->drvPath % machine->sshName); writeInt(cmdBuildPaths, to); - writeStrings(PathSet({drvPath}), to); + writeStrings(PathSet({step->drvPath}), to); writeInt(maxSilentTime, to); writeInt(buildTimeout, to); // FIXME: send maxLogSize. @@ -219,7 +215,7 @@ void buildRemote(std::shared_ptr store, } result.stopTime = time(0); if (res) { - result.errorMsg = (format("%1% on ‘%2%’") % readString(from) % sshName).str(); + result.errorMsg = (format("%1% on ‘%2%’") % readString(from) % machine->sshName).str(); if (res == 100) result.status = RemoteResult::rrPermanentFailure; else if (res == 101) result.status = RemoteResult::rrTimedOut; else result.status = RemoteResult::rrMiscFailure; @@ -227,10 +223,10 @@ void buildRemote(std::shared_ptr store, } /* Copy the output paths. */ - if (sshName != "localhost") { - printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % drvPath % sshName); + if (machine->sshName != "localhost") { + printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % step->drvPath % machine->sshName); PathSet outputs; - for (auto & output : drv.outputs) + for (auto & output : step->drv.outputs) outputs.insert(output.second.path); MaintainCount mc(nrStepsCopyingFrom); copyClosureFrom(store, from, to, outputs, bytesReceived); diff --git a/src/hydra-queue-runner/build-remote.hh b/src/hydra-queue-runner/build-remote.hh deleted file mode 100644 index 3aa2d919..00000000 --- a/src/hydra-queue-runner/build-remote.hh +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "store-api.hh" -#include "derivations.hh" - -#include "counter.hh" -#include "token-server.hh" - -struct RemoteResult -{ - enum { - rrSuccess = 0, - rrPermanentFailure = 1, - rrTimedOut = 2, - rrMiscFailure = 3 - } status = rrMiscFailure; - std::string errorMsg; - time_t startTime = 0, stopTime = 0; - nix::Path logFile; -}; - -void buildRemote(std::shared_ptr store, - const std::string & sshName, const std::string & sshKey, - const nix::Path & drvPath, const nix::Derivation & drv, - const nix::Path & logDir, unsigned int maxSilentTime, unsigned int buildTimeout, - TokenServer & copyClosureTokenServer, RemoteResult & result, - counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom, - counter & bytesSent, counter & bytesReceived); diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index b1f95b6e..27e18212 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -8,7 +8,6 @@ #include #include "build-result.hh" -#include "build-remote.hh" #include "state.hh" #include "shared.hh" @@ -848,10 +847,7 @@ bool State::doBuildStep(std::shared_ptr store, Step::ptr step, /* Do the build. */ try { /* FIXME: referring builds may have conflicting timeouts. */ - buildRemote(store, machine->sshName, machine->sshKey, step->drvPath, step->drv, - logDir, build->maxSilentTime, build->buildTimeout, copyClosureTokenServer, - result, nrStepsBuilding, nrStepsCopyingTo, nrStepsCopyingFrom, - bytesSent, bytesReceived); + buildRemote(store, machine, step, build->maxSilentTime, build->buildTimeout, result); } catch (Error & e) { result.status = RemoteResult::rrMiscFailure; result.errorMsg = e.msg(); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index ede7ecc6..877870af 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -46,6 +46,20 @@ typedef enum { } BuildStepStatus; +struct RemoteResult +{ + enum { + rrSuccess = 0, + rrPermanentFailure = 1, + rrTimedOut = 2, + rrMiscFailure = 3 + } status = rrMiscFailure; + std::string errorMsg; + time_t startTime = 0, stopTime = 0; + nix::Path logFile; +}; + + struct Step; struct BuildResult; @@ -265,6 +279,11 @@ private: bool doBuildStep(std::shared_ptr store, Step::ptr step, Machine::ptr machine); + void buildRemote(std::shared_ptr store, + Machine::ptr machine, Step::ptr step, + unsigned int maxSilentTime, unsigned int buildTimeout, + RemoteResult & result); + void markSucceededBuild(pqxx::work & txn, Build::ptr build, const BuildResult & res, bool isCachedBuild, time_t startTime, time_t stopTime);