libstore: de-callback-ify Store::queryPathInfoUncached
Change-Id: I23a156aaff5328f67ca16ccd85c0ea1711b21e35
This commit is contained in:
parent
c77bd88259
commit
2f4a1dd6e0
|
@ -349,8 +349,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
|
|||
stats.narReadBytes += narSize.length;
|
||||
}
|
||||
|
||||
void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
std::shared_ptr<const ValidPathInfo> BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath)
|
||||
{
|
||||
auto uri = getUri();
|
||||
auto storePathS = printStorePath(storePath);
|
||||
|
@ -360,17 +359,13 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
|
|||
|
||||
auto narInfoFile = narInfoFileFor(storePath);
|
||||
|
||||
try {
|
||||
auto data = getFile(narInfoFile);
|
||||
|
||||
if (!data) return callback({});
|
||||
if (!data) return {};
|
||||
|
||||
stats.narInfoRead++;
|
||||
|
||||
callback(std::make_shared<NarInfo>(*this, *data, narInfoFile));
|
||||
} catch (...) {
|
||||
callback.rethrow();
|
||||
}
|
||||
return std::make_shared<NarInfo>(*this, *data, narInfoFile);
|
||||
}
|
||||
|
||||
StorePath BinaryCacheStore::addToStore(
|
||||
|
|
|
@ -107,8 +107,7 @@ public:
|
|||
|
||||
bool isValidPathUncached(const StorePath & path) override;
|
||||
|
||||
void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
|
||||
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override;
|
||||
|
||||
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
|
||||
|
||||
|
|
|
@ -1260,8 +1260,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual In
|
|||
return paths;
|
||||
}
|
||||
|
||||
void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override
|
||||
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override
|
||||
{
|
||||
if (goal.isAllowed(path)) {
|
||||
try {
|
||||
|
@ -1271,12 +1270,12 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual In
|
|||
info->registrationTime = 0;
|
||||
info->ultimate = false;
|
||||
info->sigs.clear();
|
||||
callback(info);
|
||||
return info;
|
||||
} catch (InvalidPath &) {
|
||||
callback(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
} else
|
||||
callback(nullptr);
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
void queryReferrers(const StorePath & path, StorePathSet & referrers) override
|
||||
|
|
|
@ -33,10 +33,9 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store
|
|||
return *uriSchemes().begin();
|
||||
}
|
||||
|
||||
void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override
|
||||
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override
|
||||
{
|
||||
callback(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -143,10 +143,8 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
|||
return *uriSchemes().begin() + "://" + host;
|
||||
}
|
||||
|
||||
void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override
|
||||
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override
|
||||
{
|
||||
try {
|
||||
auto conn(connections->get());
|
||||
|
||||
/* No longer support missing NAR hash */
|
||||
|
@ -158,7 +156,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
|||
conn->to.flush();
|
||||
|
||||
auto p = readString(conn->from);
|
||||
if (p.empty()) return callback(nullptr);
|
||||
if (p.empty()) return nullptr;
|
||||
auto path2 = parseStorePath(p);
|
||||
assert(path == path2);
|
||||
auto info = std::make_shared<ValidPathInfo>(
|
||||
|
@ -171,8 +169,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
|||
auto s = readString(conn->from);
|
||||
assert(s == "");
|
||||
|
||||
callback(std::move(info));
|
||||
} catch (...) { callback.rethrow(); }
|
||||
return info;
|
||||
}
|
||||
|
||||
void addToStore(const ValidPathInfo & info, Source & source,
|
||||
|
|
|
@ -880,16 +880,12 @@ uint64_t LocalStore::addValidPath(State & state,
|
|||
}
|
||||
|
||||
|
||||
void LocalStore::queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
std::shared_ptr<const ValidPathInfo> LocalStore::queryPathInfoUncached(const StorePath & path)
|
||||
{
|
||||
try {
|
||||
callback(retrySQLite<std::shared_ptr<const ValidPathInfo>>([&]() {
|
||||
return retrySQLite<std::shared_ptr<const ValidPathInfo>>([&]() {
|
||||
auto state(_state.lock());
|
||||
return queryPathInfoInternal(*state, path);
|
||||
}));
|
||||
|
||||
} catch (...) { callback.rethrow(); }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -168,8 +168,7 @@ public:
|
|||
|
||||
StorePathSet queryAllValidPaths() override;
|
||||
|
||||
void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
|
||||
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override;
|
||||
|
||||
void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
|
||||
|
||||
|
|
|
@ -304,11 +304,7 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
}
|
||||
|
||||
|
||||
void RemoteStore::queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
{
|
||||
try {
|
||||
std::shared_ptr<const ValidPathInfo> info;
|
||||
std::shared_ptr<const ValidPathInfo> RemoteStore::queryPathInfoUncached(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryPathInfo << printStorePath(path);
|
||||
|
@ -324,13 +320,10 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path,
|
|||
bool valid; conn->from >> valid;
|
||||
if (!valid) throw InvalidPath("path '%s' is not valid", printStorePath(path));
|
||||
}
|
||||
info = std::make_shared<ValidPathInfo>(
|
||||
return std::make_shared<ValidPathInfo>(
|
||||
StorePath{path},
|
||||
WorkerProto::Serialise<UnkeyedValidPathInfo>::read(*this, *conn));
|
||||
}
|
||||
callback(std::move(info));
|
||||
} catch (...) { callback.rethrow(); }
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::queryReferrers(const StorePath & path,
|
||||
|
|
|
@ -53,8 +53,7 @@ public:
|
|||
|
||||
StorePathSet queryAllValidPaths() override;
|
||||
|
||||
void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
|
||||
std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) override;
|
||||
|
||||
void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
|
||||
|
||||
|
|
|
@ -660,23 +660,6 @@ bool Store::isValidPathUncached(const StorePath & path)
|
|||
}
|
||||
|
||||
|
||||
ref<const ValidPathInfo> Store::queryPathInfo(const StorePath & storePath)
|
||||
{
|
||||
std::promise<ref<const ValidPathInfo>> promise;
|
||||
|
||||
queryPathInfo(storePath,
|
||||
{[&](std::future<ref<const ValidPathInfo>> result) {
|
||||
try {
|
||||
promise.set_value(result.get());
|
||||
} catch (...) {
|
||||
promise.set_exception(std::current_exception());
|
||||
}
|
||||
}});
|
||||
|
||||
return promise.get_future().get();
|
||||
}
|
||||
|
||||
|
||||
static bool goodStorePath(const StorePath & expected, const StorePath & actual)
|
||||
{
|
||||
return
|
||||
|
@ -685,19 +668,17 @@ static bool goodStorePath(const StorePath & expected, const StorePath & actual)
|
|||
}
|
||||
|
||||
|
||||
void Store::queryPathInfo(const StorePath & storePath,
|
||||
Callback<ref<const ValidPathInfo>> callback) noexcept
|
||||
ref<const ValidPathInfo> Store::queryPathInfo(const StorePath & storePath)
|
||||
{
|
||||
auto hashPart = std::string(storePath.hashPart());
|
||||
|
||||
try {
|
||||
{
|
||||
auto res = state.lock()->pathInfoCache.get(std::string(storePath.to_string()));
|
||||
if (res && res->isKnownNow()) {
|
||||
stats.narInfoReadAverted++;
|
||||
if (!res->didExist())
|
||||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||
return callback(ref<const ValidPathInfo>(res->value));
|
||||
return ref<const ValidPathInfo>(res->value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -713,19 +694,11 @@ void Store::queryPathInfo(const StorePath & storePath,
|
|||
!goodStorePath(storePath, res.second->path))
|
||||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||
}
|
||||
return callback(ref<const ValidPathInfo>(res.second));
|
||||
return ref<const ValidPathInfo>(res.second);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (...) { return callback.rethrow(); }
|
||||
|
||||
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
||||
|
||||
queryPathInfoUncached(storePath,
|
||||
{[this, storePath, hashPart, callbackPtr](std::future<std::shared_ptr<const ValidPathInfo>> fut) {
|
||||
|
||||
try {
|
||||
auto info = fut.get();
|
||||
auto info = queryPathInfoUncached(storePath);
|
||||
|
||||
if (diskCache)
|
||||
diskCache->upsertNarInfo(getUri(), hashPart, info);
|
||||
|
@ -740,9 +713,7 @@ void Store::queryPathInfo(const StorePath & storePath,
|
|||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||
}
|
||||
|
||||
(*callbackPtr)(ref<const ValidPathInfo>(info));
|
||||
} catch (...) { callbackPtr->rethrow(); }
|
||||
}});
|
||||
return ref<const ValidPathInfo>(info);
|
||||
}
|
||||
|
||||
void Store::queryRealisation(const DrvOutput & id,
|
||||
|
@ -852,10 +823,9 @@ StorePathSet Store::queryValidPaths(const StorePathSet & paths, SubstituteFlag m
|
|||
|
||||
auto doQuery = [&](const StorePath & path) {
|
||||
checkInterrupt();
|
||||
queryPathInfo(path, {[path, &state_, &wakeup](std::future<ref<const ValidPathInfo>> fut) {
|
||||
auto state(state_.lock());
|
||||
try {
|
||||
auto info = fut.get();
|
||||
auto info = queryPathInfo(path);
|
||||
state->valid.insert(path);
|
||||
} catch (InvalidPath &) {
|
||||
} catch (...) {
|
||||
|
@ -864,7 +834,6 @@ StorePathSet Store::queryValidPaths(const StorePathSet & paths, SubstituteFlag m
|
|||
assert(state->left);
|
||||
if (!--state->left)
|
||||
wakeup.notify_one();
|
||||
}});
|
||||
};
|
||||
|
||||
for (auto & path : paths)
|
||||
|
|
|
@ -366,12 +366,6 @@ public:
|
|||
*/
|
||||
ref<const ValidPathInfo> queryPathInfo(const StorePath & path);
|
||||
|
||||
/**
|
||||
* Asynchronous version of queryPathInfo().
|
||||
*/
|
||||
void queryPathInfo(const StorePath & path,
|
||||
Callback<ref<const ValidPathInfo>> callback) noexcept;
|
||||
|
||||
/**
|
||||
* Query the information about a realisation.
|
||||
*/
|
||||
|
@ -407,8 +401,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual void queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept = 0;
|
||||
virtual std::shared_ptr<const ValidPathInfo> queryPathInfoUncached(const StorePath & path) = 0;
|
||||
virtual void queryRealisationUncached(const DrvOutput &,
|
||||
Callback<std::shared_ptr<const Realisation>> callback) noexcept = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue