Skip to content

Commit

Permalink
Integrate other exposed serialized logic from Nix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Dec 7, 2023
1 parent 5100ee9 commit c1fa2f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
49 changes: 14 additions & 35 deletions src/hydra-queue-runner/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void copyClosureTo(


// FIXME: use Store::topoSortPaths().
static StorePaths reverseTopoSortPaths(const std::map<StorePath, ValidPathInfo> & paths)
static StorePaths reverseTopoSortPaths(const std::map<StorePath, UnkeyedValidPathInfo> & paths)
{
StorePaths sorted;
StorePathSet visited;
Expand Down Expand Up @@ -280,21 +280,11 @@ static BuildResult performBuild(
Store & localStore,
StorePath drvPath,
const BasicDerivation & drv,
const State::BuildOptions & options,
const ServeProto::BasicClientConnection::BuildOptions & options,
counter & nrStepsBuilding
)
{
conn.to << ServeProto::Command::BuildDerivation << localStore.printStorePath(drvPath);
writeDerivation(conn.to, localStore, drv);
conn.to << options.maxSilentTime << options.buildTimeout;
if (GET_PROTOCOL_MINOR(conn.remoteVersion) >= 2)
conn.to << options.maxLogSize;
if (GET_PROTOCOL_MINOR(conn.remoteVersion) >= 3) {
conn.to
<< options.repeats // == build-repeat
<< options.enforceDeterminism;
}
conn.to.flush();
conn.buildDerivationRequest(localStore, drvPath, drv, options);

BuildResult result;

Expand All @@ -320,7 +310,7 @@ static BuildResult performBuild(
return result;
}

static std::map<StorePath, ValidPathInfo> queryPathInfos(
static std::map<StorePath, UnkeyedValidPathInfo> queryPathInfos(
Machine::Connection & conn,
Store & localStore,
StorePathSet & outputs,
Expand All @@ -329,30 +319,17 @@ static std::map<StorePath, ValidPathInfo> queryPathInfos(
{

/* Get info about each output path. */
std::map<StorePath, ValidPathInfo> infos;
std::map<StorePath, UnkeyedValidPathInfo> infos;
conn.to << ServeProto::Command::QueryPathInfos;
ServeProto::write(localStore, conn, outputs);
conn.to.flush();
while (true) {
auto storePathS = readString(conn.from);
if (storePathS == "") break;
auto deriver = readString(conn.from); // deriver
auto references = ServeProto::Serialise<StorePathSet>::read(localStore, conn);
readLongLong(conn.from); // download size
auto narSize = readLongLong(conn.from);
auto narHash = Hash::parseAny(readString(conn.from), HashAlgorithm::SHA256);
auto ca = ContentAddress::parseOpt(readString(conn.from));
readStrings<StringSet>(conn.from); // sigs
ValidPathInfo info(localStore.parseStorePath(storePathS), narHash);
assert(outputs.count(info.path));
info.references = references;
info.narSize = narSize;
totalNarSize += info.narSize;
info.narHash = narHash;
info.ca = ca;
if (deriver != "")
info.deriver = localStore.parseStorePath(deriver);
infos.insert_or_assign(info.path, info);

auto storePath = localStore.parseStorePath(storePathS);
auto info = ServeProto::Serialise<UnkeyedValidPathInfo>::read(localStore, conn);
infos.insert_or_assign(storePath, info);
}

return infos;
Expand Down Expand Up @@ -393,14 +370,16 @@ static void copyPathsFromRemote(
NarMemberDatas & narMembers,
Store & localStore,
Store & destStore,
const std::map<StorePath, ValidPathInfo> & infos
const std::map<StorePath, UnkeyedValidPathInfo> & infos
)
{
auto pathsSorted = reverseTopoSortPaths(infos);

for (auto & path : pathsSorted) {
auto & info = infos.find(path)->second;
copyPathFromRemote(conn, narMembers, localStore, destStore, info);
copyPathFromRemote(
conn, narMembers, localStore, destStore,
ValidPathInfo { path, info });
}

}
Expand Down Expand Up @@ -467,7 +446,7 @@ void RemoteResult::updateWithBuildResult(const nix::BuildResult & buildResult)

void State::buildRemote(ref<Store> destStore,
Machine::ptr machine, Step::ptr step,
const BuildOptions & buildOptions,
const ServeProto::BasicClientConnection::BuildOptions & buildOptions,
RemoteResult & result, std::shared_ptr<ActiveStep> activeStep,
std::function<void(StepState)> updateStep,
NarMemberDatas & narMembers)
Expand Down
11 changes: 7 additions & 4 deletions src/hydra-queue-runner/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ State::StepResult State::doBuildStep(nix::ref<Store> destStore,
it). */
BuildID buildId;
std::optional<StorePath> buildDrvPath;
BuildOptions buildOptions;
buildOptions.repeats = step->isDeterministic ? 1 : 0;
buildOptions.maxLogSize = maxLogSize;
buildOptions.enforceDeterminism = step->isDeterministic;
// Other fields set below
nix::ServeProto::BasicClientConnection::BuildOptions buildOptions {
.repeats = step->isDeterministic ? 1 : 0,
.maxLogSize = maxLogSize,
.enforceDeterminism = step->isDeterministic,
.keepFailed = false,
};

auto conn(dbPool.get());

Expand Down
8 changes: 1 addition & 7 deletions src/hydra-queue-runner/state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,6 @@ private:
public:
State(std::optional<std::string> metricsAddrOpt);

struct BuildOptions {
unsigned int maxSilentTime, buildTimeout, repeats;
size_t maxLogSize;
bool enforceDeterminism;
};

private:

nix::MaintainCount<counter> startDbUpdate();
Expand Down Expand Up @@ -559,7 +553,7 @@ private:

void buildRemote(nix::ref<nix::Store> destStore,
Machine::ptr machine, Step::ptr step,
const BuildOptions & buildOptions,
const nix::ServeProto::BasicClientConnection::BuildOptions & buildOptions,
RemoteResult & result, std::shared_ptr<ActiveStep> activeStep,
std::function<void(StepState)> updateStep,
NarMemberDatas & narMembers);
Expand Down

0 comments on commit c1fa2f9

Please sign in to comment.