From 451ebf24ce532f8d59f929efd486104fcebf1aa6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 20 Apr 2016 14:12:38 +0200 Subject: Cache path info lookups in SQLite This re-implements the binary cache database in C++, allowing it to be used by other Store backends, in particular the S3 backend. --- src/libstore/store-api.cc | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'src/libstore/store-api.cc') diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 6543ed1f6d19..cac137a99d7c 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -2,6 +2,7 @@ #include "globals.hh" #include "store-api.hh" #include "util.hh" +#include "nar-info-disk-cache.hh" namespace nix { @@ -225,6 +226,12 @@ Path computeStorePathForText(const string & name, const string & s, } +std::string Store::getUri() +{ + return ""; +} + + bool Store::isValidPath(const Path & storePath) { { @@ -236,7 +243,19 @@ bool Store::isValidPath(const Path & storePath) } } + if (diskCache) { + auto res = diskCache->lookupNarInfo(getUri(), storePath); + if (res.first != NarInfoDiskCache::oUnknown) { + auto state_(state.lock()); + state_->pathInfoCache.upsert(storePath, + res.first == NarInfoDiskCache::oInvalid ? 0 : res.second); + return res.first == NarInfoDiskCache::oValid; + } + } + return isValidPathUncached(storePath); + + // FIXME: insert result into NARExistence table of diskCache. } @@ -253,12 +272,26 @@ ref Store::queryPathInfo(const Path & storePath) } } + if (diskCache) { + auto res = diskCache->lookupNarInfo(getUri(), storePath); + if (res.first != NarInfoDiskCache::oUnknown) { + auto state_(state.lock()); + state_->pathInfoCache.upsert(storePath, + res.first == NarInfoDiskCache::oInvalid ? 0 : res.second); + if (res.first == NarInfoDiskCache::oInvalid) + throw InvalidPath(format("path ā€˜%sā€™ is not valid") % storePath); + return ref(res.second); + } + } + auto info = queryPathInfoUncached(storePath); + if (diskCache && info) + diskCache->upsertNarInfo(getUri(), info); + { auto state_(state.lock()); state_->pathInfoCache.upsert(storePath, info); - stats.pathInfoCacheSize = state_->pathInfoCache.size(); } if (!info) { @@ -303,6 +336,10 @@ string Store::makeValidityRegistration(const PathSet & paths, const Store::Stats & Store::getStats() { + { + auto state_(state.lock()); + stats.pathInfoCacheSize = state_->pathInfoCache.size(); + } return stats; } @@ -356,7 +393,7 @@ void Store::exportPaths(const Paths & paths, std::string ValidPathInfo::fingerprint() const { - if (narSize == 0 || narHash.type == htUnknown) + if (narSize == 0 || !narHash) throw Error(format("cannot calculate fingerprint of path ā€˜%sā€™ because its size/hash is not known") % path); return @@ -389,6 +426,15 @@ bool ValidPathInfo::checkSignature(const PublicKeys & publicKeys, const std::str } +Strings ValidPathInfo::shortRefs() const +{ + Strings refs; + for (auto & r : references) + refs.push_back(baseNameOf(r)); + return refs; +} + + } -- cgit 1.4.1