Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc
- index 81692849..e14bfd28 100644
- --- a/src/hydra-queue-runner/build-remote.cc
- +++ b/src/hydra-queue-runner/build-remote.cc
- @@ -1,19 +1,14 @@
- #include <algorithm>
- #include <cmath>
- -#include <sys/types.h>
- -#include <sys/stat.h>
- -#include <fcntl.h>
- -
- -#include "serve-protocol.hh"
- #include "state.hh"
- #include "util.hh"
- -#include "worker-protocol.hh"
- #include "finally.hh"
- using namespace nix;
- +#if 0
- struct Child
- {
- Pid pid;
- @@ -21,12 +16,6 @@ struct Child
- };
- -static void append(Strings & dst, const Strings & src)
- -{
- - dst.insert(dst.end(), src.begin(), src.end());
- -}
- -
- -
- static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Child & child)
- {
- string pgmName;
- @@ -121,6 +110,7 @@ static void copyClosureTo(std::timed_mutex & sendMutex, ref<Store> destStore,
- if (readInt(from) != 1)
- throw Error("remote machine failed to import closure");
- }
- +#endif
- void State::buildRemote(ref<Store> destStore,
- @@ -137,23 +127,36 @@ void State::buildRemote(ref<Store> destStore,
- createDirs(dirOf(result.logFile));
- + #if 0
- AutoCloseFD logFD = open(result.logFile.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666);
- if (!logFD) throw SysError(format("creating log file ‘%1%’") % result.logFile);
- -
- - nix::Path tmpDir = createTempDir();
- - AutoDelete tmpDirDel(tmpDir, true);
- + #endif
- try {
- updateStep(ssConnecting);
- - Child child;
- - openConnection(machine, tmpDir, logFD.get(), child);
- + Store::Params storeParams;
- + if (hasPrefix(machine->sshName, "ssh://")) {
- + storeParams["max-connections"] = "1";
- + if (machine->sshKey != "")
- + storeParams["ssh-key"] = machine->sshKey;
- + // FIXME: set machine->sshPublicHostKey
- + }
- +
- + auto builderStore = openStore(machine->sshName, storeParams);
- +
- + try {
- + builderStore->connect();
- + } catch (std::exception & e) {
- + throw Error("cannot connect to ‘%s’: %s", machine->sshName, e.what());
- + }
- {
- auto activeStepState(activeStep->state_.lock());
- if (activeStepState->cancelled) throw Error("step cancelled");
- - activeStepState->pid = child.pid;
- + // FIXME: cancellation
- + //activeStepState->pid = child.pid;
- }
- Finally clearPid([&]() {
- @@ -168,48 +171,20 @@ void State::buildRemote(ref<Store> destStore,
- process. Meh. */
- });
- - FdSource from(child.from.get());
- - FdSink to(child.to.get());
- -
- + #if 0
- Finally updateStats([&]() {
- bytesReceived += from.read;
- bytesSent += to.written;
- });
- -
- - /* Handshake. */
- - bool sendDerivation = true;
- - unsigned int remoteVersion;
- -
- - try {
- - to << SERVE_MAGIC_1 << 0x203;
- - to.flush();
- -
- - unsigned int magic = readInt(from);
- - if (magic != SERVE_MAGIC_2)
- - throw Error(format("protocol mismatch with ‘nix-store --serve’ on ‘%1%’") % machine->sshName);
- - remoteVersion = readInt(from);
- - if (GET_PROTOCOL_MAJOR(remoteVersion) != 0x200)
- - throw Error(format("unsupported ‘nix-store --serve’ protocol version on ‘%1%’") % machine->sshName);
- - // Always send the derivation to localhost, since it's a
- - // no-op anyway but we might not be privileged to use
- - // cmdBuildDerivation (e.g. if we're running in a NixOS
- - // container).
- - if (GET_PROTOCOL_MINOR(remoteVersion) >= 1 && !machine->isLocalhost())
- - sendDerivation = false;
- - if (GET_PROTOCOL_MINOR(remoteVersion) < 3 && repeats > 0)
- - throw Error("machine ‘%1%’ does not support repeating a build; please upgrade it to Nix 1.12", machine->sshName);
- -
- - } catch (EndOfFile & e) {
- - child.pid.wait();
- - string s = chomp(readFile(result.logFile));
- - throw Error(format("cannot connect to ‘%1%’: %2%") % machine->sshName % s);
- - }
- + #endif
- {
- auto info(machine->state->connectInfo.lock());
- info->consecutiveFailures = 0;
- }
- + bool sendDerivation = false;
- +
- /* Gather the inputs. If the remote side is Nix <= 1.9, we have to
- copy the entire closure of ‘drvPath’, as well as the required
- outputs of the input derivations. On Nix > 1.9, we only need to
- @@ -236,10 +211,11 @@ void State::buildRemote(ref<Store> destStore,
- }
- }
- - /* Ensure that the inputs exist in the destination store. This is
- - a no-op for regular stores, but for the binary cache store,
- - this will copy the inputs to the binary cache from the local
- - store. */
- + /* Ensure that the inputs exist in the destination store (so
- + that the builder can substitute them from the destination
- + store). This is a no-op for regular stores, but for the
- + binary cache store, this will copy the inputs to the binary
- + cache from the local store. */
- if (localStore != std::shared_ptr<Store>(destStore))
- copyClosure(ref<Store>(localStore), destStore, step->drv.inputSrcs, NoRepair, NoCheckSigs);
- @@ -252,7 +228,7 @@ void State::buildRemote(ref<Store> destStore,
- auto now1 = std::chrono::steady_clock::now();
- - copyClosureTo(machine->state->sendLock, destStore, from, to, inputs, true);
- + copyPaths(destStore, builderStore, inputs, NoRepair, NoCheckSigs, Substitute);
- auto now2 = std::chrono::steady_clock::now();
- @@ -261,6 +237,7 @@ void State::buildRemote(ref<Store> destStore,
- autoDelete.cancel();
- + #if 0
- /* Truncate the log to get rid of messages about substitutions
- etc. on the remote system. */
- if (lseek(logFD.get(), SEEK_SET, 0) != 0)
- @@ -270,65 +247,30 @@ void State::buildRemote(ref<Store> destStore,
- throw SysError("truncating log file ‘%s’", result.logFile);
- logFD = -1;
- + #endif
- /* Do the build. */
- - printMsg(lvlDebug, format("building ‘%1%’ on ‘%2%’") % step->drvPath % machine->sshName);
- + printMsg(lvlDebug, "building ‘%s’ on ‘%s’", step->drvPath, machine->sshName);
- updateStep(ssBuilding);
- - if (sendDerivation)
- - to << cmdBuildPaths << PathSet({step->drvPath});
- - else
- - to << cmdBuildDerivation << step->drvPath << basicDrv;
- - to << maxSilentTime << buildTimeout;
- - if (GET_PROTOCOL_MINOR(remoteVersion) >= 2)
- - to << maxLogSize;
- - if (GET_PROTOCOL_MINOR(remoteVersion) >= 3) {
- - to << repeats // == build-repeat
- - << step->isDeterministic; // == enforce-determinism
- - }
- - to.flush();
- + // FIXME: send timeout, maxLogSize, repeats, isDeterministic
- - result.startTime = time(0);
- - int res;
- {
- MaintainCount<counter> mc(nrStepsBuilding);
- - res = readInt(from);
- - }
- - result.stopTime = time(0);
- -
- - if (sendDerivation) {
- - if (res) {
- - result.errorMsg = (format("%1% on ‘%2%’") % readString(from) % machine->sshName).str();
- - if (res == 100) {
- - result.stepStatus = bsFailed;
- - result.canCache = true;
- - }
- - else if (res == 101) {
- - result.stepStatus = bsTimedOut;
- - }
- - else {
- - result.stepStatus = bsAborted;
- - result.canRetry = true;
- - }
- - return;
- + result.startTime = time(0);
- + auto buildResult = builderStore->buildDerivation(step->drvPath, basicDrv);
- + result.stopTime = time(0);
- + result.errorMsg = buildResult.errorMsg;
- + result.timesBuilt = buildResult.timesBuilt;
- + result.isNonDeterministic = buildResult.isNonDeterministic;
- + if (buildResult.startTime && buildResult.stopTime) {
- + /* Note: this represents the duration of a single
- + round, rather than all rounds. */
- + result.startTime = buildResult.startTime;
- + result.stopTime = buildResult.stopTime;;
- }
- - result.stepStatus = bsSuccess;
- - } else {
- - result.errorMsg = readString(from);
- - if (GET_PROTOCOL_MINOR(remoteVersion) >= 3) {
- - result.timesBuilt = readInt(from);
- - result.isNonDeterministic = readInt(from);
- - auto start = readInt(from);
- - auto stop = readInt(from);
- - if (start && start) {
- - /* Note: this represents the duration of a single
- - round, rather than all rounds. */
- - result.startTime = start;
- - result.stopTime = stop;
- - }
- - }
- - switch ((BuildResult::Status) res) {
- + switch ((BuildResult::Status) buildResult.status) {
- case BuildResult::Built:
- result.stepStatus = bsSuccess;
- break;
- @@ -375,8 +317,6 @@ void State::buildRemote(ref<Store> destStore,
- if (result.stepStatus != bsSuccess) return;
- }
- - result.errorMsg = "";
- -
- /* If the path was substituted or already valid, then we didn't
- get a build log. */
- if (result.isCached) {
- @@ -400,16 +340,9 @@ void State::buildRemote(ref<Store> destStore,
- outputs.insert(output.second.path);
- /* Query the size of the output paths. */
- - size_t totalNarSize = 0;
- - to << cmdQueryPathInfos << outputs;
- - to.flush();
- - while (true) {
- - if (readString(from) == "") break;
- - readString(from); // deriver
- - readStrings<PathSet>(from); // references
- - readLongLong(from); // download size
- - totalNarSize += readLongLong(from);
- - }
- + unsigned long long totalNarSize = 0;
- + for (auto & output : outputs)
- + totalNarSize += builderStore->queryPathInfo(output)->narSize;
- if (totalNarSize > maxOutputSize) {
- result.stepStatus = bsNarSizeLimitExceeded;
- @@ -434,9 +367,8 @@ void State::buildRemote(ref<Store> destStore,
- printMsg(lvlError, format("warning: had to wait %d ms for %d memory tokens for %s")
- % resMs % totalNarSize % step->drvPath);
- - to << cmdExportPaths << 0 << outputs;
- - to.flush();
- - destStore->importPaths(from, result.accessor, NoCheckSigs);
- + // FIXME: use result.accessor
- + copyPaths(builderStore, destStore, outputs, NoRepair, NoCheckSigs);
- /* Release the tokens pertaining to NAR
- compression. After this we only have the uncompressed
- @@ -448,10 +380,6 @@ void State::buildRemote(ref<Store> destStore,
- result.overhead += std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1).count();
- }
- - /* Shut down the connection. */
- - child.to = -1;
- - child.pid.wait();
- -
- } catch (Error & e) {
- /* Disable this machine until a certain period of time has
- passed. This period increases on every consecutive
Advertisement
Add Comment
Please, Sign In to add comment