From 74dd603495273fe8b81d8635676861792cf420e8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 20 Jun 2016 17:39:05 +0200 Subject: Re-implement negative binary cache lookup caching --- src/libstore/nar-info-disk-cache.cc | 27 +++++++++++++++------------ src/libstore/store-api.cc | 10 +++++++--- 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 39510f38f870..172a918ff453 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -20,7 +20,7 @@ create table if not exists BinaryCaches ( create table if not exists NARs ( cache integer not null, hashPart text not null, - namePart text not null, + namePart text, url text, compression text, fileHash text, @@ -31,6 +31,7 @@ create table if not exists NARs ( deriver text, sigs text, timestamp integer not null, + present integer not null, primary key (cache, hashPart), foreign key (cache) references BinaryCaches(id) on delete cascade ); @@ -64,7 +65,7 @@ public: struct State { SQLite db; - SQLiteStmt insertCache, queryCache, insertNAR, queryNAR, insertNARExistence, queryNARExistence; + SQLiteStmt insertCache, queryCache, insertNAR, insertMissingNAR, queryNAR; std::map caches; }; @@ -74,7 +75,7 @@ public: { auto state(_state.lock()); - Path dbPath = getCacheDir() + "/nix/binary-cache-v4.sqlite"; + Path dbPath = getCacheDir() + "/nix/binary-cache-v5.sqlite"; createDirs(dirOf(dbPath)); if (sqlite3_open_v2(dbPath.c_str(), &state->db.db, @@ -101,16 +102,13 @@ public: state->insertNAR.create(state->db, "insert or replace into NARs(cache, hashPart, namePart, url, compression, fileHash, fileSize, narHash, " - "narSize, refs, deriver, sigs, timestamp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "narSize, refs, deriver, sigs, timestamp, present) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)"); + + state->insertMissingNAR.create(state->db, + "insert or replace into NARs(cache, hashPart, timestamp, present) values (?, ?, ?, 0)"); state->queryNAR.create(state->db, "select * from NARs where cache = ? and hashPart = ?"); - - state->insertNARExistence.create(state->db, - "insert or replace into NARExistence(cache, storePath, exist, timestamp) values (?, ?, ?, ?)"); - - state->queryNARExistence.create(state->db, - "select exist, timestamp from NARExistence where cache = ? and storePath = ?"); } Cache & getCache(State & state, const std::string & uri) @@ -165,6 +163,9 @@ public: // FIXME: check NARExistence return {oUnknown, 0}; + if (!queryNAR.getInt(13)) + return {oInvalid, 0}; + auto narInfo = make_ref(); // FIXME: implement TTL. @@ -219,8 +220,10 @@ public: (time(0)).exec(); } else { - // not implemented - abort(); + state->insertMissingNAR.use() + (cache.id) + (hashPart) + (time(0)).exec(); } } }; diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index c6616a43d708..2a062b9b2cd3 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -265,9 +265,13 @@ bool Store::isValidPath(const Path & storePath) } } - return isValidPathUncached(storePath); + bool valid = isValidPathUncached(storePath); - // FIXME: insert result into NARExistence table of diskCache. + if (diskCache && !valid) + // FIXME: handle valid = true case. + diskCache->upsertNarInfo(getUri(), hashPart, 0); + + return valid; } @@ -302,7 +306,7 @@ ref Store::queryPathInfo(const Path & storePath) auto info = queryPathInfoUncached(storePath); - if (diskCache && info) + if (diskCache) diskCache->upsertNarInfo(getUri(), hashPart, info); { -- cgit 1.4.1