libstore: asyncify Store::queryReferrers

Change-Id: Iec5c85a22738f1a427774936d369e5f30af1a8a5
This commit is contained in:
eldritch horrors
2025-03-05 18:49:45 +01:00
parent 85cd558b6d
commit d5d498ab22
10 changed files with 36 additions and 19 deletions
+1 -1
View File
@@ -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);
}
+3 -2
View File
@@ -1068,8 +1068,9 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor
return nullptr;
};
void queryReferrers(const StorePath & path, StorePathSet & referrers) override
{ }
kj::Promise<Result<void>>
queryReferrers(const StorePath & path, StorePathSet & referrers) override
{ return {result::success()}; }
kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore = nullptr) override
+1 -1
View File
@@ -349,7 +349,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref<Store> 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: {
+1 -1
View File
@@ -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);
}
+17 -7
View File
@@ -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<Result<void>>
LocalStore::queryReferrers(const StorePath & path, StorePathSet & referrers)
try {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
TRY_AWAIT(retrySQLite([&]() -> kj::Promise<Result<void>> {
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));
+2 -1
View File
@@ -198,7 +198,8 @@ public:
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override;
void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
kj::Promise<Result<void>>
queryReferrers(const StorePath & path, StorePathSet & referrers) override;
kj::Promise<Result<StorePathSet>> queryValidDerivers(const StorePath & path) override;
+1 -1
View File
@@ -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);
+5 -2
View File
@@ -306,14 +306,17 @@ std::shared_ptr<const ValidPathInfo> RemoteStore::queryPathInfoUncached(const St
}
void RemoteStore::queryReferrers(const StorePath & path,
kj::Promise<Result<void>> 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<StorePathSet>::read(*this, *conn))
referrers.insert(i);
co_return result::success();
} catch (...) {
co_return result::current_exception();
}
+2 -1
View File
@@ -59,7 +59,8 @@ public:
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override;
void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
kj::Promise<Result<void>>
queryReferrers(const StorePath & path, StorePathSet & referrers) override;
kj::Promise<Result<StorePathSet>> queryValidDerivers(const StorePath & path) override;
+3 -2
View File
@@ -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<Result<void>>
queryReferrers(const StorePath & path, StorePathSet & referrers)
try { unsupported("queryReferrers"); } catch (...) { return {result::current_exception()}; }
/**
* @return all currently valid derivations that have `path` as an