diff options
-rw-r--r-- | src/libstore/nar-info-disk-cache.cc | 27 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 10 |
2 files changed, 22 insertions, 15 deletions
diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 39510f38f..172a918ff 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<std::string, Cache> 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<NarInfo>(); // 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 c6616a43d..2a062b9b2 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<const ValidPathInfo> Store::queryPathInfo(const Path & storePath) auto info = queryPathInfoUncached(storePath); - if (diskCache && info) + if (diskCache) diskCache->upsertNarInfo(getUri(), hashPart, info); { |