forked from lix-project/lix
BinaryCacheStore: Do negative caching of .narinfo lookups
This commit is contained in:
parent
d1b0909894
commit
a7d8eaba54
|
@ -114,14 +114,22 @@ NarInfo BinaryCacheStore::readNarInfo(const Path & storePath)
|
|||
auto res = state_->narInfoCache.get(storePath);
|
||||
if (res) {
|
||||
stats.narInfoReadAverted++;
|
||||
if (!*res)
|
||||
throw InvalidPath(format("path ‘%s’ is not valid") % storePath);
|
||||
return **res;
|
||||
}
|
||||
}
|
||||
|
||||
auto narInfoFile = narInfoFileFor(storePath);
|
||||
auto data = getFile(narInfoFile);
|
||||
if (!data)
|
||||
if (!data) {
|
||||
stats.narInfoMissing++;
|
||||
auto state_(state.lock());
|
||||
state_->narInfoCache.upsert(storePath, 0);
|
||||
stats.narInfoCacheSize = state_->narInfoCache.size();
|
||||
throw InvalidPath(format("path ‘%s’ is not valid") % storePath);
|
||||
}
|
||||
|
||||
auto narInfo = make_ref<NarInfo>(*data, narInfoFile);
|
||||
if (narInfo->path != storePath)
|
||||
throw Error(format("NAR info file for store path ‘%1%’ does not match ‘%2%’") % narInfo->path % storePath);
|
||||
|
@ -149,7 +157,7 @@ bool BinaryCacheStore::isValidPath(const Path & storePath)
|
|||
auto res = state_->narInfoCache.get(storePath);
|
||||
if (res) {
|
||||
stats.narInfoReadAverted++;
|
||||
return true;
|
||||
return *res != 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ private:
|
|||
|
||||
struct State
|
||||
{
|
||||
LRUCache<Path, ref<NarInfo>> narInfoCache{32 * 1024};
|
||||
LRUCache<Path, std::shared_ptr<NarInfo>> narInfoCache{32 * 1024};
|
||||
};
|
||||
|
||||
Sync<State> state;
|
||||
|
@ -51,6 +51,7 @@ public:
|
|||
{
|
||||
std::atomic<uint64_t> narInfoRead{0};
|
||||
std::atomic<uint64_t> narInfoReadAverted{0};
|
||||
std::atomic<uint64_t> narInfoMissing{0};
|
||||
std::atomic<uint64_t> narInfoWrite{0};
|
||||
std::atomic<uint64_t> narInfoCacheSize{0};
|
||||
std::atomic<uint64_t> narRead{0};
|
||||
|
|
Loading…
Reference in a new issue