1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-24 03:09:35 +01:00

Merge commit 'f4c869977c' into progress-bar

This commit is contained in:
John Ericson 2023-03-11 16:58:03 -05:00
commit 68e32b7728
3 changed files with 69 additions and 14 deletions

View file

@ -441,16 +441,25 @@ void BinaryCacheStore::queryRealisationUncached(const DrvOutput & id,
Callback<std::shared_ptr<const Realisation>> callback) noexcept Callback<std::shared_ptr<const Realisation>> callback) noexcept
{ {
auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi"; auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi";
auto rawOutputInfo = getFile(outputInfoFilePath);
if (rawOutputInfo) { auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
auto realisation = Realisation::fromJSON(
nlohmann::json::parse(*rawOutputInfo), outputInfoFilePath); Callback<std::shared_ptr<std::string>> newCallback = {
callback(std::make_shared<const Realisation>(realisation)); [=](std::future<std::shared_ptr<std::string>> fut) {
return; try {
} else { auto data = fut.get();
callback(nullptr); if (!data) return (*callbackPtr)(nullptr);
}
auto realisation = Realisation::fromJSON(
nlohmann::json::parse(*data), outputInfoFilePath);
return (*callbackPtr)(std::make_shared<const Realisation>(realisation));
} catch (...) {
callbackPtr->rethrow();
}
}
};
getFile(outputInfoFilePath, std::move(newCallback));
} }
void BinaryCacheStore::registerDrvOutput(const Realisation& info) { void BinaryCacheStore::registerDrvOutput(const Realisation& info) {

View file

@ -1,6 +1,8 @@
#include "drv-output-substitution-goal.hh" #include "drv-output-substitution-goal.hh"
#include "finally.hh"
#include "worker.hh" #include "worker.hh"
#include "substitution-goal.hh" #include "substitution-goal.hh"
#include "callback.hh"
namespace nix { namespace nix {
@ -50,14 +52,42 @@ void DrvOutputSubstitutionGoal::tryNext()
return; return;
} }
auto sub = subs.front(); sub = subs.front();
subs.pop_front(); subs.pop_front();
// FIXME: Make async // FIXME: Make async
outputInfo = sub->queryRealisation(id); // outputInfo = sub->queryRealisation(id);
outPipe.create();
promise = decltype(promise)();
sub->queryRealisation(
id, { [&](std::future<std::shared_ptr<const Realisation>> res) {
try {
Finally updateStats([this]() { outPipe.writeSide.close(); });
promise.set_value(res.get());
} catch (...) {
promise.set_exception(std::current_exception());
}
} });
worker.childStarted(shared_from_this(), {outPipe.readSide.get()}, true, false);
state = &DrvOutputSubstitutionGoal::realisationFetched;
}
void DrvOutputSubstitutionGoal::realisationFetched()
{
worker.childTerminated(this);
try {
outputInfo = promise.get_future().get();
} catch (std::exception & e) {
printError(e.what());
substituterFailed = true;
}
if (!outputInfo) { if (!outputInfo) {
tryNext(); return tryNext();
return;
} }
for (const auto & [depId, depPath] : outputInfo->dependentRealisations) { for (const auto & [depId, depPath] : outputInfo->dependentRealisations) {
@ -119,4 +149,10 @@ void DrvOutputSubstitutionGoal::work()
(this->*state)(); (this->*state)();
} }
void DrvOutputSubstitutionGoal::handleEOF(int fd)
{
if (fd == outPipe.readSide.get()) worker.wakeUp(shared_from_this());
}
} }

View file

@ -3,6 +3,8 @@
#include "store-api.hh" #include "store-api.hh"
#include "goal.hh" #include "goal.hh"
#include "realisation.hh" #include "realisation.hh"
#include <thread>
#include <future>
namespace nix { namespace nix {
@ -25,6 +27,13 @@ private:
/* The remaining substituters. */ /* The remaining substituters. */
std::list<ref<Store>> subs; std::list<ref<Store>> subs;
/* The current substituter. */
std::shared_ptr<Store> sub;
Pipe outPipe;
std::thread thr;
std::promise<std::shared_ptr<const Realisation>> promise;
/* Whether a substituter failed. */ /* Whether a substituter failed. */
bool substituterFailed = false; bool substituterFailed = false;
@ -36,6 +45,7 @@ public:
void init(); void init();
void tryNext(); void tryNext();
void realisationFetched();
void outPathValid(); void outPathValid();
void finished(); void finished();
@ -44,7 +54,7 @@ public:
string key() override; string key() override;
void work() override; void work() override;
void handleEOF(int fd) override;
}; };
} }