about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-30T11·33+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-30T13·18+0200
commite2224844019d58fc947ce00e18e9fa9974d2c8b5 (patch)
tree20204fa548e7a926e838486c63250572f4d6c2e8 /src
parentb66ab6cdbce5f4ac2db8976872547680242166e8 (diff)
Re-implement the WantMassQuery property of binary caches
Diffstat (limited to 'src')
-rw-r--r--src/libstore/binary-cache-store.cc21
-rw-r--r--src/libstore/binary-cache-store.hh5
-rw-r--r--src/libstore/http-binary-cache-store.cc11
-rw-r--r--src/libstore/local-store.cc1
-rw-r--r--src/libstore/nar-info-disk-cache.cc4
-rw-r--r--src/libstore/nar-info-disk-cache.hh2
-rw-r--r--src/libstore/s3-binary-cache-store.cc2
-rw-r--r--src/libstore/store-api.hh2
8 files changed, 40 insertions, 8 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index 642da9f047..58cb87a516 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 bb67a8581a..c14ab8676a 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 073f76cc9e..8c8d545c6d 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 6f33c1e810..acd02eb48a 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 d8b0815bf7..ae368e1528 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 f4e3fbbdcb..ce5da062c5 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 bd8abe4821..8e85e21492 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 65c4cdc97f..8c618bf3e7 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;