From bf1c5cb27d0f5e25a41b56ea20b8a67ec97ba6ba Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 2 Feb 2025 16:10:32 +0100 Subject: [PATCH] libstore: asyncify Store::querySubstitutablePathInfos this also calls getDefaultSubstituters. Change-Id: I9c80d8b8311a712a3e73964445c42d10a5dab7db --- lix/libstore/daemon.cc | 4 ++-- lix/libstore/misc.cc | 10 +++++----- lix/libstore/remote-store.cc | 10 +++++++--- lix/libstore/remote-store.hh | 2 +- lix/libstore/store-api.cc | 10 +++++++--- lix/libstore/store-api.hh | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index 43d011075..8622de0be 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -776,7 +776,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store auto path = store->parseStorePath(readString(from)); logger->startWork(); SubstitutablePathInfos infos; - store->querySubstitutablePathInfos({{path, std::nullopt}}, infos); + aio.blockOn(store->querySubstitutablePathInfos({{path, std::nullopt}}, infos)); logger->stopWork(); auto i = infos.find(path); if (i == infos.end()) @@ -801,7 +801,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store } else pathsMap = WorkerProto::Serialise::read(*store, rconn); logger->startWork(); - store->querySubstitutablePathInfos(pathsMap, infos); + aio.blockOn(store->querySubstitutablePathInfos(pathsMap, infos)); logger->stopWork(); to << infos.size(); for (auto & i : infos) { diff --git a/lix/libstore/misc.cc b/lix/libstore/misc.cc index ca62e998d..336c69d03 100644 --- a/lix/libstore/misc.cc +++ b/lix/libstore/misc.cc @@ -159,12 +159,12 @@ struct QueryMissingContext SubstitutablePathInfos infos; auto * cap = getDerivationCA(*drv); - store.querySubstitutablePathInfos({ + aio.blockOn(store.querySubstitutablePathInfos({ { outPath, cap ? std::optional { *cap } : std::nullopt, }, - }, infos); + }, infos)); if (infos.empty()) { drvState_->lock()->done = true; @@ -198,7 +198,7 @@ struct QueryMissingContext std::visit( overloaded{ [&](const DerivedPath::Built & bfd) { doPathBuilt(aio, bfd); }, - [&](const DerivedPath::Opaque & bo) { doPathOpaque(bo); }, + [&](const DerivedPath::Opaque & bo) { doPathOpaque(aio, bo); }, }, req.raw() ); @@ -280,12 +280,12 @@ struct QueryMissingContext } } - void doPathOpaque(const DerivedPath::Opaque & bo) + void doPathOpaque(AsyncIoRoot & aio, const DerivedPath::Opaque & bo) { if (store.isValidPath(bo.path)) return; SubstitutablePathInfos infos; - store.querySubstitutablePathInfos({{bo.path, std::nullopt}}, infos); + aio.blockOn(store.querySubstitutablePathInfos({{bo.path, std::nullopt}}, infos)); if (infos.empty()) { auto state(state_.lock()); diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 1458e7339..ba4b747ed 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -239,9 +239,9 @@ try { } -void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, SubstitutablePathInfos & infos) -{ - if (pathsMap.empty()) return; +kj::Promise> RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, SubstitutablePathInfos & infos) +try { + if (pathsMap.empty()) return {result::success()}; auto conn(getConnection()); @@ -265,6 +265,10 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S info.downloadSize = readLongLong(conn->from); info.narSize = readLongLong(conn->from); } + + return {result::success()}; +} catch (...) { + return {result::current_exception()}; } diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index 90fc56d77..8921c1ca7 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -68,7 +68,7 @@ public: kj::Promise> querySubstitutablePaths(const StorePathSet & paths) override; - void querySubstitutablePathInfos(const StorePathCAMap & paths, + kj::Promise> querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos) override; /** diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index b4b4cfb27..7a686bbe1 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -604,9 +604,9 @@ StorePathSet Store::queryDerivationOutputs(const StorePath & path) } -void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos) -{ - if (!settings.useSubstitutes) return; +kj::Promise> Store::querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos) +try { + if (!settings.useSubstitutes) co_return result::success(); for (auto & sub : getDefaultSubstituters()) { for (auto & path : paths) { if (infos.count(path.first)) @@ -654,6 +654,10 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta } } } + + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 7f647e2c5..cdd491d32 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -489,7 +489,7 @@ public: * If a path does not have substitute info, it's omitted from the * resulting ‘infos’ map. */ - virtual void querySubstitutablePathInfos(const StorePathCAMap & paths, + virtual kj::Promise> querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos); /**