nix-daemon: Disable path info cache

This is useless because the client also caches path info, and can
cause problems for long-running clients like hydra-queue-runner
(i.e. it may return cached info about paths that have been
garbage-collected).
This commit is contained in:
Eelco Dolstra 2017-04-06 14:30:31 +02:00
parent 8decb07c31
commit 256940fc48
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 17 additions and 5 deletions

View file

@ -242,6 +242,7 @@ Path Store::computeStorePathForText(const string & name, const string & s,
Store::Store(const Params & params)
: storeDir(get(params, "store", settings.nixStore))
, state({std::stoi(get(params, "path-info-cache-size", "65536"))})
{
}

View file

@ -241,7 +241,7 @@ protected:
struct State
{
LRUCache<std::string, std::shared_ptr<ValidPathInfo>> pathInfoCache{64 * 1024};
LRUCache<std::string, std::shared_ptr<ValidPathInfo>> pathInfoCache;
};
Sync<State> state;
@ -252,6 +252,11 @@ protected:
public:
size_t getCacheSize()
{
return state.lock()->pathInfoCache.size();
}
virtual ~Store() { }
virtual std::string getUri() = 0;

View file

@ -11,7 +11,7 @@ class LRUCache
{
private:
size_t maxSize;
size_t capacity;
// Stupid wrapper to get around circular dependency between Data
// and LRU.
@ -27,14 +27,16 @@ private:
public:
LRUCache(size_t maxSize) : maxSize(maxSize) { }
LRUCache(size_t capacity) : capacity(capacity) { }
/* Insert or upsert an item in the cache. */
void upsert(const Key & key, const Value & value)
{
if (capacity == 0) return;
erase(key);
if (data.size() >= maxSize) {
if (data.size() >= capacity) {
/* Retire the oldest item. */
auto oldest = lru.begin();
data.erase(*oldest);

View file

@ -33,6 +33,7 @@ public:
Sync() { }
Sync(const T & data) : data(data) { }
Sync(T && data) noexcept : data(std::move(data)) { }
class Lock
{

View file

@ -637,7 +637,10 @@ static void processConnection(bool trusted)
#endif
/* Open the store. */
auto store = make_ref<LocalStore>(Store::Params()); // FIXME: get params from somewhere
Store::Params params; // FIXME: get params from somewhere
// Disable caching since the client already does that.
params["path-info-cache-size"] = "0";
auto store = make_ref<LocalStore>(params);
stopWork();
to.flush();