From a7d8eaba540ce272bc4fc19afdeae177a3b086d9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 Apr 2016 15:25:15 +0200 Subject: [PATCH] BinaryCacheStore: Do negative caching of .narinfo lookups --- src/libstore/binary-cache-store.cc | 12 ++++++++++-- src/libstore/binary-cache-store.hh | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 7c8fdfd08..7016eedfa 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -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(*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; } } diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index 55bba6278..dcf06b3d1 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -24,7 +24,7 @@ private: struct State { - LRUCache> narInfoCache{32 * 1024}; + LRUCache> narInfoCache{32 * 1024}; }; Sync state; @@ -51,6 +51,7 @@ public: { std::atomic narInfoRead{0}; std::atomic narInfoReadAverted{0}; + std::atomic narInfoMissing{0}; std::atomic narInfoWrite{0}; std::atomic narInfoCacheSize{0}; std::atomic narRead{0};