diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-05-30 13:33:05 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-05-30 15:18:12 +0200 |
commit | e2224844019d58fc947ce00e18e9fa9974d2c8b5 (patch) | |
tree | 20204fa548e7a926e838486c63250572f4d6c2e8 /src | |
parent | b66ab6cdbce5f4ac2db8976872547680242166e8 (diff) |
Re-implement the WantMassQuery property of binary caches
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/binary-cache-store.cc | 21 | ||||
-rw-r--r-- | src/libstore/binary-cache-store.hh | 5 | ||||
-rw-r--r-- | src/libstore/http-binary-cache-store.cc | 11 | ||||
-rw-r--r-- | src/libstore/local-store.cc | 1 | ||||
-rw-r--r-- | src/libstore/nar-info-disk-cache.cc | 4 | ||||
-rw-r--r-- | src/libstore/nar-info-disk-cache.hh | 2 | ||||
-rw-r--r-- | src/libstore/s3-binary-cache-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 2 |
8 files changed, 40 insertions, 8 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 642da9f04..58cb87a51 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -29,8 +29,27 @@ BinaryCacheStore::BinaryCacheStore(const StoreParams & params) void BinaryCacheStore::init() { std::string cacheInfoFile = "nix-cache-info"; - if (!fileExists(cacheInfoFile)) + + auto cacheInfo = getFile(cacheInfoFile); + if (!cacheInfo) { upsertFile(cacheInfoFile, "StoreDir: " + settings.nixStore + "\n"); + } else { + for (auto & line : tokenizeString<Strings>(*cacheInfo, "\n")) { + size_t colon = line.find(':'); + if (colon == std::string::npos) continue; + auto name = line.substr(0, colon); + auto value = trim(line.substr(colon + 1, std::string::npos)); + if (name == "StoreDir") { + if (value != settings.nixStore) + throw Error(format("binary cache ‘%s’ is for Nix stores with prefix ‘%s’, not ‘%s’") + % getUri() % value % settings.nixStore); + } else if (name == "WantMassQuery") { + wantMassQuery_ = value == "1"; + } else if (name == "Priority") { + string2Int(value, priority); + } + } + } } void BinaryCacheStore::notImpl() diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index bb67a8581..c14ab8676 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -33,6 +33,9 @@ protected: doesn't exist. */ virtual std::shared_ptr<std::string> getFile(const std::string & path) = 0; + bool wantMassQuery_ = false; + int priority = 50; + public: virtual void init(); @@ -78,6 +81,8 @@ public: SubstitutablePathInfos & infos) { } + bool wantMassQuery() { return wantMassQuery_; } + void addToStore(const ValidPathInfo & info, const std::string & nar, bool repair = false) override; diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index 073f76cc9..8c8d545c6 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -5,6 +5,8 @@ namespace nix { +MakeError(UploadToHTTP, Error); + class HttpBinaryCacheStore : public BinaryCacheStore { private: @@ -38,9 +40,12 @@ public: { // FIXME: do this lazily? if (!diskCache->cacheExists(cacheUri)) { - if (!fileExists("nix-cache-info")) + try { + BinaryCacheStore::init(); + } catch (UploadToHTTP &) { throw Error(format("‘%s’ does not appear to be a binary cache") % cacheUri); - diskCache->createCache(cacheUri); + } + diskCache->createCache(cacheUri, wantMassQuery_, priority); } } @@ -66,7 +71,7 @@ protected: void upsertFile(const std::string & path, const std::string & data) override { - throw Error("uploading to an HTTP binary cache is not supported"); + throw UploadToHTTP("uploading to an HTTP binary cache is not supported"); } std::shared_ptr<std::string> getFile(const std::string & path) override diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 6f33c1e81..acd02eb48 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -788,6 +788,7 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths) { PathSet res; for (auto & sub : getDefaultSubstituters()) { + if (!sub->wantMassQuery()) continue; for (auto & path : paths) { if (res.count(path)) continue; debug(format("checking substituter ‘%s’ for path ‘%s’") diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index d8b0815bf..ae368e152 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -113,13 +113,13 @@ public: return i->second; } - void createCache(const std::string & uri) override + void createCache(const std::string & uri, bool wantMassQuery, int priority) override { auto state(_state.lock()); // FIXME: race - state->insertCache.use()(uri)(time(0))(settings.nixStore)(1)(0).exec(); + state->insertCache.use()(uri)(time(0))(settings.nixStore)(wantMassQuery)(priority).exec(); assert(sqlite3_changes(state->db) == 1); state->caches[uri] = sqlite3_last_insert_rowid(state->db); } diff --git a/src/libstore/nar-info-disk-cache.hh b/src/libstore/nar-info-disk-cache.hh index f4e3fbbdc..ce5da062c 100644 --- a/src/libstore/nar-info-disk-cache.hh +++ b/src/libstore/nar-info-disk-cache.hh @@ -10,7 +10,7 @@ class NarInfoDiskCache public: typedef enum { oValid, oInvalid, oUnknown } Outcome; - virtual void createCache(const std::string & uri) = 0; + virtual void createCache(const std::string & uri, bool wantMassQuery, int priority) = 0; virtual bool cacheExists(const std::string & uri) = 0; diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index bd8abe482..8e85e2149 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -95,7 +95,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore BinaryCacheStore::init(); - diskCache->createCache(getUri()); + diskCache->createCache(getUri(), wantMassQuery, priority); } } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 65c4cdc97..8c618bf3e 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -253,6 +253,8 @@ public: virtual void querySubstitutablePathInfos(const PathSet & paths, SubstitutablePathInfos & infos) = 0; + virtual bool wantMassQuery() { return false; } + /* Import a path into the store. */ virtual void addToStore(const ValidPathInfo & info, const std::string & nar, bool repair = false) = 0; |