From d5d498ab22b5255d2a36d5a557b18eef5cef8bd5 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 4 Mar 2025 23:08:34 +0100 Subject: [PATCH] libstore: asyncify Store::queryReferrers Change-Id: Iec5c85a22738f1a427774936d369e5f30af1a8a5 --- lix/legacy/nix-store.cc | 2 +- lix/libstore/build/local-derivation-goal.cc | 5 +++-- lix/libstore/daemon.cc | 2 +- lix/libstore/gc.cc | 2 +- lix/libstore/local-store.cc | 24 +++++++++++++++------ lix/libstore/local-store.hh | 3 ++- lix/libstore/misc.cc | 2 +- lix/libstore/remote-store.cc | 7 ++++-- lix/libstore/remote-store.hh | 3 ++- lix/libstore/store-api.hh | 5 +++-- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 3c8985ce5..69e7ef178 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -373,7 +373,7 @@ static void opQuery(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) } else if (query == qReferrers) { StorePathSet tmp; - store->queryReferrers(j, tmp); + aio.blockOn(store->queryReferrers(j, tmp)); for (auto & i : tmp) paths.insert(i); } diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index a4e3ffd8f..54e787973 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -1068,8 +1068,9 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor return nullptr; }; - void queryReferrers(const StorePath & path, StorePathSet & referrers) override - { } + kj::Promise> + queryReferrers(const StorePath & path, StorePathSet & referrers) override + { return {result::success()}; } kj::Promise>>> queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore = nullptr) override diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index db2aa3142..4a0062489 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -349,7 +349,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store #pragma GCC diagnostic ignored "-Wswitch-enum" switch (op) { case WorkerProto::Op::QueryReferrers: { - store->queryReferrers(path, paths); + aio.blockOn(store->queryReferrers(path, paths)); break; } case WorkerProto::Op::QueryValidDerivers: { diff --git a/lix/libstore/gc.cc b/lix/libstore/gc.cc index 5d5a10319..185709c1c 100644 --- a/lix/libstore/gc.cc +++ b/lix/libstore/gc.cc @@ -760,7 +760,7 @@ try { auto i = referrersCache.find(*path); if (i == referrersCache.end()) { StorePathSet referrers; - queryReferrers(*path, referrers); + TRY_AWAIT(queryReferrers(*path, referrers)); referrersCache.emplace(*path, std::move(referrers)); i = referrersCache.find(*path); } diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index cb136e982..07bc63072 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -1051,12 +1051,22 @@ void LocalStore::queryReferrers(DBState & state, const StorePath & path, StorePa } -void LocalStore::queryReferrers(const StorePath & path, StorePathSet & referrers) -{ - return retrySQLite([&]() { - auto state = dbPool.get(); - queryReferrers(*state, path, referrers); - }, always_progresses); +kj::Promise> +LocalStore::queryReferrers(const StorePath & path, StorePathSet & referrers) +try { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + TRY_AWAIT(retrySQLite([&]() -> kj::Promise> { + try { + auto state = dbPool.get(); + queryReferrers(*state, path, referrers); + co_return result::success(); + } catch (...) { + co_return result::current_exception(); + } + })); + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } @@ -1777,7 +1787,7 @@ try { /* Check any referrers first. If we can invalidate them first, then we can invalidate this path as well. */ bool canInvalidate = true; - StorePathSet referrers; queryReferrers(path, referrers); + StorePathSet referrers; TRY_AWAIT(queryReferrers(path, referrers)); for (auto & i : referrers) if (i != path) { TRY_AWAIT(verifyPath(i, storePathsInStoreDir, done, validPaths, repair, errors)); diff --git a/lix/libstore/local-store.hh b/lix/libstore/local-store.hh index 7c08369fa..b0cf8c553 100644 --- a/lix/libstore/local-store.hh +++ b/lix/libstore/local-store.hh @@ -198,7 +198,8 @@ public: std::shared_ptr queryPathInfoUncached(const StorePath & path) override; - void queryReferrers(const StorePath & path, StorePathSet & referrers) override; + kj::Promise> + queryReferrers(const StorePath & path, StorePathSet & referrers) override; kj::Promise> queryValidDerivers(const StorePath & path) override; diff --git a/lix/libstore/misc.cc b/lix/libstore/misc.cc index 707d3f137..b8329e390 100644 --- a/lix/libstore/misc.cc +++ b/lix/libstore/misc.cc @@ -26,7 +26,7 @@ try { try { StorePathSet res; StorePathSet referrers; - queryReferrers(path, referrers); + TRY_AWAIT(queryReferrers(path, referrers)); for (auto& ref : referrers) if (ref != path) res.insert(ref); diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 1bcce6250..e3e44e0d5 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -306,14 +306,17 @@ std::shared_ptr RemoteStore::queryPathInfoUncached(const St } -void RemoteStore::queryReferrers(const StorePath & path, +kj::Promise> RemoteStore::queryReferrers(const StorePath & path, StorePathSet & referrers) -{ +try { auto conn(getConnection()); conn->to << WorkerProto::Op::QueryReferrers << printStorePath(path); conn.processStderr(); for (auto & i : WorkerProto::Serialise::read(*this, *conn)) referrers.insert(i); + 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 8d4c7c235..ddbcd87b8 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -59,7 +59,8 @@ public: std::shared_ptr queryPathInfoUncached(const StorePath & path) override; - void queryReferrers(const StorePath & path, StorePathSet & referrers) override; + kj::Promise> + queryReferrers(const StorePath & path, StorePathSet & referrers) override; kj::Promise> queryValidDerivers(const StorePath & path) override; diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 187c3ac96..a32a0e1ce 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -429,8 +429,9 @@ public: * Queries the set of incoming FS references for a store path. * The result is not cleared. */ - virtual void queryReferrers(const StorePath & path, StorePathSet & referrers) - { unsupported("queryReferrers"); } + virtual kj::Promise> + queryReferrers(const StorePath & path, StorePathSet & referrers) + try { unsupported("queryReferrers"); } catch (...) { return {result::current_exception()}; } /** * @return all currently valid derivations that have `path` as an