From c2f71d5b301593dcbe0d7c77246634c45eca2f43 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 2 Feb 2025 15:58:21 +0100 Subject: [PATCH] libstore: asyncify Store::querySubstitutablePaths the LocalStore implementation calls `getDefaultSubstituters`, which calls `openStore`, which calls `Store::init`, which does network io in binary caches, which will eventually be properly asyncified curl Change-Id: If6a7a0294e2c4ba8e35722583be6ccde21ed6585 --- lix/legacy/nix-env.cc | 4 ++-- lix/libstore/daemon.cc | 2 +- lix/libstore/local-store.cc | 10 ++++++---- lix/libstore/local-store.hh | 2 +- lix/libstore/remote-store.cc | 8 +++++--- lix/libstore/remote-store.hh | 2 +- lix/libstore/store-api.hh | 5 ++++- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index d6b800569..499b93295 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -231,7 +231,7 @@ static bool isPrebuilt(EvalState & state, DrvInfo & elem) { auto path = elem.queryOutPath(state); if (state.ctx.store->isValidPath(path)) return true; - return state.ctx.store->querySubstitutablePaths({path}).count(path); + return state.aio.blockOn(state.ctx.store->querySubstitutablePaths({path})).count(path); } @@ -1103,7 +1103,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) i.setFailed(); } validPaths = store.queryValidPaths(paths); - substitutablePaths = store.querySubstitutablePaths(paths); + substitutablePaths = globals.aio.blockOn(store.querySubstitutablePaths(paths)); } diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index aca828057..43d011075 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -300,7 +300,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store case WorkerProto::Op::QuerySubstitutablePaths: { auto paths = WorkerProto::Serialise::read(*store, rconn); logger->startWork(); - auto res = store->querySubstitutablePaths(paths); + auto res = aio.blockOn(store->querySubstitutablePaths(paths)); logger->stopWork(); to << WorkerProto::write(*store, wconn, res); break; diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 53d497af1..5cde2ff6c 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -1062,9 +1062,9 @@ std::optional LocalStore::queryPathFromHashPart(const std::string & h } -StorePathSet LocalStore::querySubstitutablePaths(const StorePathSet & paths) -{ - if (!settings.useSubstitutes) return StorePathSet(); +kj::Promise> LocalStore::querySubstitutablePaths(const StorePathSet & paths) +try { + if (!settings.useSubstitutes) co_return StorePathSet(); StorePathSet remaining; for (auto & i : paths) @@ -1089,7 +1089,9 @@ StorePathSet LocalStore::querySubstitutablePaths(const StorePathSet & paths) std::swap(remaining, remaining2); } - return res; + co_return res; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/local-store.hh b/lix/libstore/local-store.hh index 79bb3b3ec..57dace264 100644 --- a/lix/libstore/local-store.hh +++ b/lix/libstore/local-store.hh @@ -199,7 +199,7 @@ public: std::optional queryPathFromHashPart(const std::string & hashPart) override; - StorePathSet querySubstitutablePaths(const StorePathSet & paths) override; + kj::Promise> querySubstitutablePaths(const StorePathSet & paths) override; bool pathInfoIsUntrusted(const ValidPathInfo &) override; bool realisationIsUntrusted(const Realisation & ) override; diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 7bf2d24d1..1458e7339 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -227,13 +227,15 @@ StorePathSet RemoteStore::queryAllValidPaths() } -StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths) -{ +kj::Promise> RemoteStore::querySubstitutablePaths(const StorePathSet & paths) +try { auto conn(getConnection()); conn->to << WorkerProto::Op::QuerySubstitutablePaths; conn->to << WorkerProto::write(*this, *conn, paths); conn.processStderr(); - return WorkerProto::Serialise::read(*this, *conn); + return {WorkerProto::Serialise::read(*this, *conn)}; +} catch (...) { + return {result::current_exception()}; } diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index 49001a034..90fc56d77 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -66,7 +66,7 @@ public: std::map> queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore = nullptr) override; std::optional queryPathFromHashPart(const std::string & hashPart) override; - StorePathSet querySubstitutablePaths(const StorePathSet & paths) override; + kj::Promise> querySubstitutablePaths(const StorePathSet & paths) override; void querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos) override; diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 0032f8a80..7f647e2c5 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -477,7 +477,10 @@ public: /** * Query which of the given paths have substitutes. */ - virtual StorePathSet querySubstitutablePaths(const StorePathSet & paths) { return {}; }; + virtual kj::Promise> querySubstitutablePaths(const StorePathSet & paths) + { + return {StorePathSet{}}; + } /** * Query substitute info (i.e. references, derivers and download