libstore: asyncify Store::isValidPathUncached

Change-Id: I5a2df380490325282768b2edbe42656ffe40d10e
This commit is contained in:
eldritch horrors
2025-03-05 18:49:45 +01:00
parent 90caba8489
commit 09727e15c5
9 changed files with 44 additions and 33 deletions
+5 -3
View File
@@ -328,12 +328,14 @@ try {
co_return result::current_exception();
}
bool BinaryCacheStore::isValidPathUncached(const StorePath & storePath)
{
kj::Promise<Result<bool>> BinaryCacheStore::isValidPathUncached(const StorePath & storePath)
try {
// FIXME: this only checks whether a .narinfo with a matching hash
// part exists. So f4kb...-foo matches f4kb...-bar, even
// though they shouldn't. Not easily fixed.
return fileExists(narInfoFileFor(storePath));
co_return fileExists(narInfoFileFor(storePath));
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<std::optional<StorePath>>>
+1 -1
View File
@@ -109,7 +109,7 @@ private:
public:
bool isValidPathUncached(const StorePath & path) override;
kj::Promise<Result<bool>> isValidPathUncached(const StorePath & path) override;
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override;
+13 -6
View File
@@ -1004,12 +1004,19 @@ bool LocalStore::isValidPath_(DBState & state, const StorePath & path)
}
bool LocalStore::isValidPathUncached(const StorePath & path)
{
return retrySQLite([&]() {
auto state = dbPool.get();
return isValidPath_(*state, path);
}, always_progresses);
kj::Promise<Result<bool>> LocalStore::isValidPathUncached(const StorePath & path)
try {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
co_return TRY_AWAIT(retrySQLite([&]() -> kj::Promise<Result<bool>> {
try {
auto state = dbPool.get();
co_return isValidPath_(*state, path);
} catch (...) {
co_return result::current_exception();
}
}));
} catch (...) {
co_return result::current_exception();
}
+1 -1
View File
@@ -189,7 +189,7 @@ public:
std::string getUri() override;
bool isValidPathUncached(const StorePath & path) override;
kj::Promise<Result<bool>> isValidPathUncached(const StorePath & path) override;
kj::Promise<Result<StorePathSet>> queryValidPaths(const StorePathSet & paths,
SubstituteFlag maybeSubstitute = NoSubstitute) override;
+5 -3
View File
@@ -203,12 +203,14 @@ try {
co_return result::current_exception();
}
bool RemoteStore::isValidPathUncached(const StorePath & path)
{
kj::Promise<Result<bool>> RemoteStore::isValidPathUncached(const StorePath & path)
try {
auto conn(getConnection());
conn->to << WorkerProto::Op::IsValidPath << printStorePath(path);
conn.processStderr();
return readInt(conn->from);
co_return readInt(conn->from);
} catch (...) {
co_return result::current_exception();
}
+1 -1
View File
@@ -50,7 +50,7 @@ public:
/* Implementations of abstract store API methods. */
bool isValidPathUncached(const StorePath & path) override;
kj::Promise<Result<bool>> isValidPathUncached(const StorePath & path) override;
kj::Promise<Result<StorePathSet>> queryValidPaths(const StorePathSet & paths,
SubstituteFlag maybeSubstitute = NoSubstitute) override;
+8 -8
View File
@@ -313,14 +313,14 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
fetches the .narinfo file, rather than first checking for its
existence via a HEAD request. Since .narinfos are small, doing
a GET is unlikely to be slower than HEAD. */
bool isValidPathUncached(const StorePath & storePath) override
{
try {
queryPathInfo(storePath);
return true;
} catch (InvalidPath & e) {
return false;
}
kj::Promise<Result<bool>> isValidPathUncached(const StorePath & storePath) override
try {
queryPathInfo(storePath);
co_return true;
} catch (InvalidPath & e) {
co_return false;
} catch (...) {
co_return result::current_exception();
}
bool fileExists(const std::string & path) override
+9 -9
View File
@@ -655,7 +655,7 @@ try {
}
}
bool valid = isValidPathUncached(storePath);
bool valid = TRY_AWAIT(isValidPathUncached(storePath));
if (diskCache && !valid)
// FIXME: handle valid = true case.
@@ -669,14 +669,14 @@ try {
/* Default implementation for stores that only implement
queryPathInfoUncached(). */
bool Store::isValidPathUncached(const StorePath & path)
{
try {
queryPathInfo(path);
return true;
} catch (InvalidPath &) {
return false;
}
kj::Promise<Result<bool>> Store::isValidPathUncached(const StorePath & path)
try {
queryPathInfo(path);
co_return true;
} catch (InvalidPath &) {
co_return false;
} catch (...) {
co_return result::current_exception();
}
+1 -1
View File
@@ -350,7 +350,7 @@ public:
protected:
virtual bool isValidPathUncached(const StorePath & path);
virtual kj::Promise<Result<bool>> isValidPathUncached(const StorePath & path);
public: