From 87efae8a534b65cb1f14ae97633f24ebd1eb42b5 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 5 Mar 2025 16:42:11 +0100 Subject: [PATCH] libstore: asyncify Store::queryMissing Change-Id: I33cc483a3a60208dc2a2c99fa277738be356f5f2 --- lix/legacy/nix-build.cc | 4 ++-- lix/legacy/nix-store.cc | 4 ++-- lix/libmain/shared.cc | 2 +- lix/libstore/build/local-derivation-goal.cc | 11 +++++---- lix/libstore/daemon.cc | 4 +++- lix/libstore/misc.cc | 25 ++++++++++++++------- lix/libstore/remote-store.cc | 7 ++++-- lix/libstore/remote-store.hh | 2 +- lix/libstore/store-api.cc | 4 ++-- lix/libstore/store-api.hh | 2 +- 10 files changed, 41 insertions(+), 24 deletions(-) diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index 84a982e20..6bc6b1870 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -314,8 +314,8 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a fetch binary cache data. */ uint64_t downloadSize, narSize; StorePathSet willBuild, willSubstitute, unknown; - store->queryMissing(paths, - willBuild, willSubstitute, unknown, downloadSize, narSize); + aio.blockOn(store->queryMissing(paths, + willBuild, willSubstitute, unknown, downloadSize, narSize)); if (settings.printMissing) { aio.blockOn(printMissing( diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 00a23cbe8..0f858d345 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -142,9 +142,9 @@ static void opRealise(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) uint64_t downloadSize, narSize; StorePathSet willBuild, willSubstitute, unknown; - store->queryMissing( + aio.blockOn(store->queryMissing( toDerivedPaths(paths), - willBuild, willSubstitute, unknown, downloadSize, narSize); + willBuild, willSubstitute, unknown, downloadSize, narSize)); /* Filter out unknown paths from `paths`. */ if (ignoreUnknown) { diff --git a/lix/libmain/shared.cc b/lix/libmain/shared.cc index 5f21c13b3..184c6bec9 100644 --- a/lix/libmain/shared.cc +++ b/lix/libmain/shared.cc @@ -52,7 +52,7 @@ printMissing(ref store, const std::vector & paths, Verbosity try { uint64_t downloadSize, narSize; StorePathSet willBuild, willSubstitute, unknown; - store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize); + TRY_AWAIT(store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize)); TRY_AWAIT(printMissing(store, willBuild, willSubstitute, unknown, downloadSize, narSize, lvl)); co_return result::success(); } catch (...) { diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 1b7c5fc15..6ba108caa 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -1240,10 +1240,10 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor void addSignatures(const StorePath & storePath, const StringSet & sigs) override { unsupported("addSignatures"); } - void queryMissing(const std::vector & targets, + kj::Promise> queryMissing(const std::vector & targets, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, uint64_t & downloadSize, uint64_t & narSize) override - { + try { /* This is slightly impure since it leaks information to the client about what paths will be built/substituted or are already present. Probably not a big deal. */ @@ -1256,8 +1256,11 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor unknown.insert(pathPartOfReq(req)); } - next->queryMissing(allowed, willBuild, willSubstitute, - unknown, downloadSize, narSize); + TRY_AWAIT(next->queryMissing(allowed, willBuild, willSubstitute, + unknown, downloadSize, narSize)); + co_return result::success(); + } catch (...) { + co_return result::current_exception(); } virtual kj::Promise>> getBuildLogExact(const StorePath & path) override diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index fcc8b9404..3c02c6bd1 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -940,7 +940,9 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store logger->startWork(); StorePathSet willBuild, willSubstitute, unknown; uint64_t downloadSize, narSize; - store->queryMissing(targets, willBuild, willSubstitute, unknown, downloadSize, narSize); + aio.blockOn( + store->queryMissing(targets, willBuild, willSubstitute, unknown, downloadSize, narSize) + ); logger->stopWork(); to << WorkerProto::write(*store, wconn, willBuild); to << WorkerProto::write(*store, wconn, willSubstitute); diff --git a/lix/libstore/misc.cc b/lix/libstore/misc.cc index 3ebbdeafb..6850efe66 100644 --- a/lix/libstore/misc.cc +++ b/lix/libstore/misc.cc @@ -142,7 +142,7 @@ struct QueryMissingContext KJ_DISALLOW_COPY_AND_MOVE(QueryMissingContext); - void queryMissing(const std::vector & targets); + kj::Promise> queryMissing(const std::vector & targets); void enqueueDerivedPaths(ref inputDrv, const DerivedPathMap::ChildNode & inputNode) { @@ -336,25 +336,34 @@ struct QueryMissingContext }; } -void QueryMissingContext::queryMissing(const std::vector & targets) -{ +kj::Promise> QueryMissingContext::queryMissing(const std::vector & targets) +try { for (auto & path : targets) { pool.enqueueWithAio([=, this](AsyncIoRoot & aio) { doPath(aio, path); }); } - pool.process(); + TRY_AWAIT(pool.processAsync()); + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } -void Store::queryMissing(const std::vector & targets, + +kj::Promise> Store::queryMissing(const std::vector & targets, StorePathSet & willBuild_, StorePathSet & willSubstitute_, StorePathSet & unknown_, uint64_t & downloadSize_, uint64_t & narSize_) -{ +try { Activity act(*logger, lvlDebug, actUnknown, "querying info about missing paths"); downloadSize_ = narSize_ = 0; - QueryMissingContext{*this, willBuild_, willSubstitute_, unknown_, downloadSize_, narSize_} - .queryMissing(targets); + TRY_AWAIT( + QueryMissingContext{*this, willBuild_, willSubstitute_, unknown_, downloadSize_, narSize_} + .queryMissing(targets) + ); + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 327311541..f34332376 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -895,10 +895,10 @@ void RemoteStore::addSignatures(const StorePath & storePath, const StringSet & s } -void RemoteStore::queryMissing(const std::vector & targets, +kj::Promise> RemoteStore::queryMissing(const std::vector & targets, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, uint64_t & downloadSize, uint64_t & narSize) -{ +try { auto conn(getConnection()); conn->to << WorkerProto::Op::QueryMissing; conn->to << WorkerProto::write(*this, *conn, targets); @@ -907,6 +907,9 @@ void RemoteStore::queryMissing(const std::vector & targets, willSubstitute = WorkerProto::Serialise::read(*this, *conn); unknown = WorkerProto::Serialise::read(*this, *conn); conn->from >> downloadSize >> narSize; + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index ec74060ae..60a23adb3 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -157,7 +157,7 @@ public: void addSignatures(const StorePath & storePath, const StringSet & sigs) override; - void queryMissing(const std::vector & targets, + kj::Promise> queryMissing(const std::vector & targets, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, uint64_t & downloadSize, uint64_t & narSize) override; diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 1209d545d..4fc1ada0e 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -783,8 +783,8 @@ try { paths2.emplace_back(DerivedPath::Opaque{path}); uint64_t downloadSize, narSize; StorePathSet willBuild, willSubstitute, unknown; - queryMissing(paths2, - willBuild, willSubstitute, unknown, downloadSize, narSize); + TRY_AWAIT(queryMissing(paths2, + willBuild, willSubstitute, unknown, downloadSize, narSize)); if (!willSubstitute.empty()) try { diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index a0171738d..92e92601c 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -790,7 +790,7 @@ public: * derivations that will be built, and the set of output paths that * will be substituted. */ - virtual void queryMissing(const std::vector & targets, + virtual kj::Promise> queryMissing(const std::vector & targets, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, uint64_t & downloadSize, uint64_t & narSize);