forked from lix-project/hydra
Move buildRemote() into State
This commit is contained in:
parent
df29527531
commit
63745b8e25
5 changed files with 42 additions and 59 deletions
|
@ -1,7 +1,7 @@
|
||||||
bin_PROGRAMS = hydra-queue-runner
|
bin_PROGRAMS = hydra-queue-runner
|
||||||
|
|
||||||
hydra_queue_runner_SOURCES = hydra-queue-runner.cc build-result.cc build-remote.cc \
|
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
|
hydra_queue_runner_LDADD = $(NIX_LIBS) -lpqxx
|
||||||
|
|
||||||
AM_CXXFLAGS = $(NIX_CFLAGS) -Wall
|
AM_CXXFLAGS = $(NIX_CFLAGS) -Wall
|
||||||
|
|
|
@ -4,11 +4,10 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "build-remote.hh"
|
|
||||||
|
|
||||||
#include "util.hh"
|
|
||||||
#include "misc.hh"
|
#include "misc.hh"
|
||||||
#include "serve-protocol.hh"
|
#include "serve-protocol.hh"
|
||||||
|
#include "state.hh"
|
||||||
|
#include "util.hh"
|
||||||
#include "worker-protocol.hh"
|
#include "worker-protocol.hh"
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
@ -141,15 +140,12 @@ static void copyClosureFrom(std::shared_ptr<StoreAPI> store,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void buildRemote(std::shared_ptr<StoreAPI> store,
|
void State::buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
const string & sshName, const string & sshKey,
|
Machine::ptr machine, Step::ptr step,
|
||||||
const Path & drvPath, const Derivation & drv,
|
unsigned int maxSilentTime, unsigned int buildTimeout,
|
||||||
const nix::Path & logDir, unsigned int maxSilentTime, unsigned int buildTimeout,
|
RemoteResult & result)
|
||||||
TokenServer & copyClosureTokenServer, RemoteResult & result,
|
|
||||||
counter & nrStepsBuilding, counter & nrStepsCopyingTo, counter & nrStepsCopyingFrom,
|
|
||||||
counter & bytesSent, counter & bytesReceived)
|
|
||||||
{
|
{
|
||||||
string base = baseNameOf(drvPath);
|
string base = baseNameOf(step->drvPath);
|
||||||
result.logFile = logDir + "/" + string(base, 0, 2) + "/" + string(base, 2);
|
result.logFile = logDir + "/" + string(base, 0, 2) + "/" + string(base, 2);
|
||||||
AutoDelete autoDelete(result.logFile, false);
|
AutoDelete autoDelete(result.logFile, false);
|
||||||
|
|
||||||
|
@ -159,7 +155,7 @@ void buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
if (logFD == -1) throw SysError(format("creating log file ‘%1%’") % result.logFile);
|
if (logFD == -1) throw SysError(format("creating log file ‘%1%’") % result.logFile);
|
||||||
|
|
||||||
Child child;
|
Child child;
|
||||||
openConnection(sshName, sshKey, logFD, child);
|
openConnection(machine->sshName, machine->sshKey, logFD, child);
|
||||||
|
|
||||||
logFD.close();
|
logFD.close();
|
||||||
|
|
||||||
|
@ -174,19 +170,19 @@ void buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
|
|
||||||
unsigned int magic = readInt(from);
|
unsigned int magic = readInt(from);
|
||||||
if (magic != SERVE_MAGIC_2)
|
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);
|
unsigned int version = readInt(from);
|
||||||
if (GET_PROTOCOL_MAJOR(version) != 0x200)
|
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) {
|
} catch (EndOfFile & e) {
|
||||||
child.pid.wait(true);
|
child.pid.wait(true);
|
||||||
string s = chomp(readFile(result.logFile));
|
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. */
|
/* Gather the inputs. */
|
||||||
PathSet inputs({drvPath});
|
PathSet inputs({step->drvPath});
|
||||||
for (auto & input : drv.inputDrvs) {
|
for (auto & input : step->drv.inputDrvs) {
|
||||||
Derivation drv2 = readDerivation(input.first);
|
Derivation drv2 = readDerivation(input.first);
|
||||||
for (auto & name : input.second) {
|
for (auto & name : input.second) {
|
||||||
auto i = drv2.outputs.find(name);
|
auto i = drv2.outputs.find(name);
|
||||||
|
@ -195,8 +191,8 @@ void buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the input closure. */
|
/* Copy the input closure. */
|
||||||
if (sshName != "localhost") {
|
if (machine->sshName != "localhost") {
|
||||||
printMsg(lvlDebug, format("sending closure of ‘%1%’ to ‘%2%’") % drvPath % sshName);
|
printMsg(lvlDebug, format("sending closure of ‘%1%’ to ‘%2%’") % step->drvPath % machine->sshName);
|
||||||
MaintainCount mc(nrStepsCopyingTo);
|
MaintainCount mc(nrStepsCopyingTo);
|
||||||
copyClosureTo(store, from, to, inputs, copyClosureTokenServer, bytesSent);
|
copyClosureTo(store, from, to, inputs, copyClosureTokenServer, bytesSent);
|
||||||
}
|
}
|
||||||
|
@ -204,9 +200,9 @@ void buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
autoDelete.cancel();
|
autoDelete.cancel();
|
||||||
|
|
||||||
/* Do the build. */
|
/* 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);
|
writeInt(cmdBuildPaths, to);
|
||||||
writeStrings(PathSet({drvPath}), to);
|
writeStrings(PathSet({step->drvPath}), to);
|
||||||
writeInt(maxSilentTime, to);
|
writeInt(maxSilentTime, to);
|
||||||
writeInt(buildTimeout, to);
|
writeInt(buildTimeout, to);
|
||||||
// FIXME: send maxLogSize.
|
// FIXME: send maxLogSize.
|
||||||
|
@ -219,7 +215,7 @@ void buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
}
|
}
|
||||||
result.stopTime = time(0);
|
result.stopTime = time(0);
|
||||||
if (res) {
|
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;
|
if (res == 100) result.status = RemoteResult::rrPermanentFailure;
|
||||||
else if (res == 101) result.status = RemoteResult::rrTimedOut;
|
else if (res == 101) result.status = RemoteResult::rrTimedOut;
|
||||||
else result.status = RemoteResult::rrMiscFailure;
|
else result.status = RemoteResult::rrMiscFailure;
|
||||||
|
@ -227,10 +223,10 @@ void buildRemote(std::shared_ptr<StoreAPI> store,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the output paths. */
|
/* Copy the output paths. */
|
||||||
if (sshName != "localhost") {
|
if (machine->sshName != "localhost") {
|
||||||
printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % drvPath % sshName);
|
printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % step->drvPath % machine->sshName);
|
||||||
PathSet outputs;
|
PathSet outputs;
|
||||||
for (auto & output : drv.outputs)
|
for (auto & output : step->drv.outputs)
|
||||||
outputs.insert(output.second.path);
|
outputs.insert(output.second.path);
|
||||||
MaintainCount mc(nrStepsCopyingFrom);
|
MaintainCount mc(nrStepsCopyingFrom);
|
||||||
copyClosureFrom(store, from, to, outputs, bytesReceived);
|
copyClosureFrom(store, from, to, outputs, bytesReceived);
|
||||||
|
|
|
@ -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<nix::StoreAPI> 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);
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "build-result.hh"
|
#include "build-result.hh"
|
||||||
#include "build-remote.hh"
|
|
||||||
#include "state.hh"
|
#include "state.hh"
|
||||||
|
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
|
@ -848,10 +847,7 @@ bool State::doBuildStep(std::shared_ptr<StoreAPI> store, Step::ptr step,
|
||||||
/* Do the build. */
|
/* Do the build. */
|
||||||
try {
|
try {
|
||||||
/* FIXME: referring builds may have conflicting timeouts. */
|
/* FIXME: referring builds may have conflicting timeouts. */
|
||||||
buildRemote(store, machine->sshName, machine->sshKey, step->drvPath, step->drv,
|
buildRemote(store, machine, step, build->maxSilentTime, build->buildTimeout, result);
|
||||||
logDir, build->maxSilentTime, build->buildTimeout, copyClosureTokenServer,
|
|
||||||
result, nrStepsBuilding, nrStepsCopyingTo, nrStepsCopyingFrom,
|
|
||||||
bytesSent, bytesReceived);
|
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
result.status = RemoteResult::rrMiscFailure;
|
result.status = RemoteResult::rrMiscFailure;
|
||||||
result.errorMsg = e.msg();
|
result.errorMsg = e.msg();
|
||||||
|
|
|
@ -46,6 +46,20 @@ typedef enum {
|
||||||
} BuildStepStatus;
|
} 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 Step;
|
||||||
struct BuildResult;
|
struct BuildResult;
|
||||||
|
|
||||||
|
@ -265,6 +279,11 @@ private:
|
||||||
bool doBuildStep(std::shared_ptr<StoreAPI> store, Step::ptr step,
|
bool doBuildStep(std::shared_ptr<StoreAPI> store, Step::ptr step,
|
||||||
Machine::ptr machine);
|
Machine::ptr machine);
|
||||||
|
|
||||||
|
void buildRemote(std::shared_ptr<nix::StoreAPI> store,
|
||||||
|
Machine::ptr machine, Step::ptr step,
|
||||||
|
unsigned int maxSilentTime, unsigned int buildTimeout,
|
||||||
|
RemoteResult & result);
|
||||||
|
|
||||||
void markSucceededBuild(pqxx::work & txn, Build::ptr build,
|
void markSucceededBuild(pqxx::work & txn, Build::ptr build,
|
||||||
const BuildResult & res, bool isCachedBuild, time_t startTime, time_t stopTime);
|
const BuildResult & res, bool isCachedBuild, time_t startTime, time_t stopTime);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue