From 42a8fb96567ef4ffae9494056da0c8ca5a7634df Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 24 Feb 2025 04:54:41 +0100 Subject: [PATCH] libstore: asyncify Realisation::closure Change-Id: I8ed52455bea0e166098de9c77d55a2f843530d64 --- lix/libstore/build/local-derivation-goal.cc | 2 +- lix/libstore/misc.cc | 6 +++--- lix/libstore/realisation.cc | 20 ++++++++++++++------ lix/libstore/realisation.hh | 6 ++++-- lix/libstore/store-api.cc | 3 ++- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 1ebe066c2..330965941 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -1204,7 +1204,7 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor TRY_AWAIT(next->computeFSClosure(newPaths, closure)); for (auto & path : closure) goal.addDependency(path); - for (auto & real : Realisation::closure(*next, newRealisations)) + for (auto & real : TRY_AWAIT(Realisation::closure(*next, newRealisations))) goal.addedDrvOutputs.insert(real.id); co_return results; diff --git a/lix/libstore/misc.cc b/lix/libstore/misc.cc index e9da3b495..3ebbdeafb 100644 --- a/lix/libstore/misc.cc +++ b/lix/libstore/misc.cc @@ -453,9 +453,9 @@ try { auto info = store.queryPathInfo(outputPath); - co_return TRY_AWAIT( - drvOutputReferences(Realisation::closure(store, inputRealisations), info->references) - ); + co_return TRY_AWAIT(drvOutputReferences( + TRY_AWAIT(Realisation::closure(store, inputRealisations)), info->references + )); } catch (...) { co_return result::current_exception(); } diff --git a/lix/libstore/realisation.cc b/lix/libstore/realisation.cc index 5ac1c3fb6..a30e2dc9e 100644 --- a/lix/libstore/realisation.cc +++ b/lix/libstore/realisation.cc @@ -23,15 +23,20 @@ std::string DrvOutput::to_string() const { return strHash() + "!" + outputName; } -std::set Realisation::closure(Store & store, const std::set & startOutputs) -{ +kj::Promise>> +Realisation::closure(Store & store, const std::set & startOutputs) +try { std::set res; - Realisation::closure(store, startOutputs, res); - return res; + TRY_AWAIT(Realisation::closure(store, startOutputs, res)); + co_return res; +} catch (...) { + co_return result::current_exception(); } -void Realisation::closure(Store & store, const std::set & startOutputs, std::set & res) -{ +kj::Promise> Realisation::closure( + Store & store, const std::set & startOutputs, std::set & res +) +try { auto getDeps = [&](const Realisation& current) -> std::set { std::set res; for (auto& [currentDep, _] : current.dependentRealisations) { @@ -45,6 +50,9 @@ void Realisation::closure(Store & store, const std::set & startOutp }; res.merge(computeClosure(startOutputs, getDeps)); + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } nlohmann::json Realisation::toJSON() const { diff --git a/lix/libstore/realisation.hh b/lix/libstore/realisation.hh index 02697f267..1d367b086 100644 --- a/lix/libstore/realisation.hh +++ b/lix/libstore/realisation.hh @@ -68,8 +68,10 @@ struct Realisation { bool checkSignature(const PublicKeys & publicKeys, const std::string & sig) const; size_t checkSignatures(const PublicKeys & publicKeys) const; - static std::set closure(Store &, const std::set &); - static void closure(Store &, const std::set &, std::set & res); + static kj::Promise>> + closure(Store &, const std::set &); + static kj::Promise> + closure(Store &, const std::set &, std::set & res); bool isCompatibleWith(const Realisation & other) const; diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 1cb285a53..72f40f4e9 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -1194,7 +1194,8 @@ try { try { // Copy the realisation closure processGraph( - "copyPaths pool", Realisation::closure(srcStore, toplevelRealisations), + "copyPaths pool", + TRY_AWAIT(Realisation::closure(srcStore, toplevelRealisations)), [&](const Realisation & current) -> std::set { std::set children; for (const auto & [drvOutput, _] : current.dependentRealisations) {