aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-12-18 14:25:25 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-12-18 14:25:25 +0100
commit87873d0d656890f693aa29f062dd8fc496a9d6ae (patch)
tree16e332e447e01114cd296dc94d9aa9937c9d7602 /src/libstore
parent31c240ee8b5f7949439eede0d7953d04261147fe (diff)
parentf8abbdd4565542464f31f4dc203a9c3e091b3536 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/binary-cache-store.cc4
-rw-r--r--src/libstore/binary-cache-store.hh9
-rw-r--r--src/libstore/daemon.cc4
-rw-r--r--src/libstore/derivations.cc10
-rw-r--r--src/libstore/globals.cc2
-rw-r--r--src/libstore/http-binary-cache-store.cc7
-rw-r--r--src/libstore/local-store.cc2
-rw-r--r--src/libstore/nar-info-disk-cache.cc16
-rw-r--r--src/libstore/nar-info-disk-cache.hh9
-rw-r--r--src/libstore/path.cc15
-rw-r--r--src/libstore/path.hh24
-rw-r--r--src/libstore/s3-binary-cache-store.cc9
-rw-r--r--src/libstore/sqlite.hh4
-rw-r--r--src/libstore/store-api.cc15
-rw-r--r--src/libstore/store-api.hh36
15 files changed, 92 insertions, 74 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index aaacf8281..717faec92 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -49,9 +49,9 @@ void BinaryCacheStore::init()
throw Error(format("binary cache '%s' is for Nix stores with prefix '%s', not '%s'")
% getUri() % value % storeDir);
} else if (name == "WantMassQuery") {
- wantMassQuery_ = value == "1";
+ wantMassQuery.setDefault(value == "1" ? "true" : "false");
} else if (name == "Priority") {
- string2Int(value, priority);
+ priority.setDefault(fmt("%d", std::stoi(value)));
}
}
}
diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh
index fa2200ad8..aa13c1cb4 100644
--- a/src/libstore/binary-cache-store.hh
+++ b/src/libstore/binary-cache-store.hh
@@ -52,11 +52,6 @@ public:
std::shared_ptr<std::string> getFile(const std::string & path);
-protected:
-
- bool wantMassQuery_ = false;
- int priority = 50;
-
public:
virtual void init();
@@ -79,8 +74,6 @@ public:
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
{ unsupported("queryPathFromHashPart"); }
- bool wantMassQuery() override { return wantMassQuery_; }
-
void addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
RepairFlag repair, CheckSigsFlag checkSigs,
std::shared_ptr<FSAccessor> accessor) override;
@@ -107,8 +100,6 @@ public:
std::shared_ptr<std::string> getBuildLog(const StorePath & path) override;
- int getPriority() override { return priority; }
-
};
MakeError(NoSuchBinaryCacheFile, Error);
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index c53dfdd56..8e9f9d71b 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -424,7 +424,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopBuildPaths: {
std::vector<StorePathWithOutputs> drvs;
for (auto & s : readStrings<Strings>(from))
- drvs.push_back(store->parseDrvPathWithOutputs(s));
+ drvs.push_back(store->parsePathWithOutputs(s));
BuildMode mode = bmNormal;
if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
mode = (BuildMode) readInt(from);
@@ -721,7 +721,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopQueryMissing: {
std::vector<StorePathWithOutputs> targets;
for (auto & s : readStrings<Strings>(from))
- targets.push_back(store->parseDrvPathWithOutputs(s));
+ targets.push_back(store->parsePathWithOutputs(s));
logger->startWork();
StorePathSet willBuild, willSubstitute, unknown;
unsigned long long downloadSize, narSize;
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 726e34479..1a061149a 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -375,16 +375,6 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput
}
-StorePathWithOutputs Store::parseDrvPathWithOutputs(const std::string & s)
-{
- size_t n = s.find("!");
- return n == s.npos
- ? StorePathWithOutputs{parseStorePath(s), std::set<string>()}
- : StorePathWithOutputs{parseStorePath(std::string_view(s.data(), n)),
- tokenizeString<std::set<string>>(string(s, n + 1), ",")};
-}
-
-
std::string StorePathWithOutputs::to_string(const Store & store) const
{
return outputs.empty()
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 6fedf3d56..cec85edca 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -127,7 +127,7 @@ template<> void BaseSetting<SandboxMode>::set(const std::string & str)
else throw UsageError("option '%s' has invalid value '%s'", name, str);
}
-template<> std::string BaseSetting<SandboxMode>::to_string()
+template<> std::string BaseSetting<SandboxMode>::to_string() const
{
if (value == smEnabled) return "true";
else if (value == smRelaxed) return "relaxed";
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index c8a00a949..011794c62 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -42,13 +42,16 @@ public:
void init() override
{
// FIXME: do this lazily?
- if (!diskCache->cacheExists(cacheUri, wantMassQuery_, priority)) {
+ if (auto cacheInfo = diskCache->cacheExists(cacheUri)) {
+ wantMassQuery.setDefault(cacheInfo->wantMassQuery ? "true" : "false");
+ priority.setDefault(fmt("%d", cacheInfo->priority));
+ } else {
try {
BinaryCacheStore::init();
} catch (UploadToHTTP &) {
throw Error("'%s' does not appear to be a binary cache", cacheUri);
}
- diskCache->createCache(cacheUri, storeDir, wantMassQuery_, priority);
+ diskCache->createCache(cacheUri, storeDir, wantMassQuery, priority);
}
}
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 47b055bc1..e214f0659 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -833,7 +833,7 @@ StorePathSet LocalStore::querySubstitutablePaths(const StorePathSet & paths)
for (auto & sub : getDefaultSubstituters()) {
if (remaining.empty()) break;
if (sub->storeDir != storeDir) continue;
- if (!sub->wantMassQuery()) continue;
+ if (!sub->wantMassQuery) continue;
auto valid = sub->queryValidPaths(remaining);
diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc
index 2bd515536..442541330 100644
--- a/src/libstore/nar-info-disk-cache.cc
+++ b/src/libstore/nar-info-disk-cache.cc
@@ -142,26 +142,26 @@ public:
});
}
- bool cacheExists(const std::string & uri,
- bool & wantMassQuery, int & priority) override
+ std::optional<CacheInfo> cacheExists(const std::string & uri) override
{
- return retrySQLite<bool>([&]() {
+ return retrySQLite<std::optional<CacheInfo>>([&]() -> std::optional<CacheInfo> {
auto state(_state.lock());
auto i = state->caches.find(uri);
if (i == state->caches.end()) {
auto queryCache(state->queryCache.use()(uri));
- if (!queryCache.next()) return false;
+ if (!queryCache.next())
+ return std::nullopt;
state->caches.emplace(uri,
Cache{(int) queryCache.getInt(0), queryCache.getStr(1), queryCache.getInt(2) != 0, (int) queryCache.getInt(3)});
}
auto & cache(getCache(*state, uri));
- wantMassQuery = cache.wantMassQuery;
- priority = cache.priority;
-
- return true;
+ return CacheInfo {
+ .wantMassQuery = cache.wantMassQuery,
+ .priority = cache.priority
+ };
});
}
diff --git a/src/libstore/nar-info-disk-cache.hh b/src/libstore/nar-info-disk-cache.hh
index fb34f8c93..04de2c5eb 100644
--- a/src/libstore/nar-info-disk-cache.hh
+++ b/src/libstore/nar-info-disk-cache.hh
@@ -15,8 +15,13 @@ public:
virtual void createCache(const std::string & uri, const Path & storeDir,
bool wantMassQuery, int priority) = 0;
- virtual bool cacheExists(const std::string & uri,
- bool & wantMassQuery, int & priority) = 0;
+ struct CacheInfo
+ {
+ bool wantMassQuery;
+ int priority;
+ };
+
+ virtual std::optional<CacheInfo> cacheExists(const std::string & uri) = 0;
virtual std::pair<Outcome, std::shared_ptr<NarInfo>> lookupNarInfo(
const std::string & uri, const std::string & hashPart) = 0;
diff --git a/src/libstore/path.cc b/src/libstore/path.cc
index 81ae495a1..cda5f9968 100644
--- a/src/libstore/path.cc
+++ b/src/libstore/path.cc
@@ -96,4 +96,19 @@ StorePathSet singleton(const StorePath & path)
return res;
}
+std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s)
+{
+ size_t n = s.find("!");
+ return n == s.npos
+ ? std::make_pair(s, std::set<string>())
+ : std::make_pair(((std::string_view) s).substr(0, n),
+ tokenizeString<std::set<string>>(((std::string_view) s).substr(n + 1), ","));
+}
+
+StorePathWithOutputs Store::parsePathWithOutputs(const std::string & s)
+{
+ auto [path, outputs] = nix::parsePathWithOutputs(s);
+ return {parseStorePath(path), std::move(outputs)};
+}
+
}
diff --git a/src/libstore/path.hh b/src/libstore/path.hh
index 273808f02..5ebb57480 100644
--- a/src/libstore/path.hh
+++ b/src/libstore/path.hh
@@ -7,6 +7,8 @@ namespace nix {
/* See path.rs. */
struct StorePath;
+struct Store;
+
extern "C" {
void ffi_StorePath_drop(void *);
bool ffi_StorePath_less_than(const StorePath & a, const StorePath & b);
@@ -67,6 +69,28 @@ const size_t storePathHashLen = 32; // i.e. 160 bits
/* Extension of derivations in the Nix store. */
const std::string drvExtension = ".drv";
+struct StorePathWithOutputs
+{
+ StorePath path;
+ std::set<std::string> outputs;
+
+ StorePathWithOutputs(const StorePath & path, const std::set<std::string> & outputs = {})
+ : path(path.clone()), outputs(outputs)
+ { }
+
+ StorePathWithOutputs(StorePath && path, std::set<std::string> && outputs)
+ : path(std::move(path)), outputs(std::move(outputs))
+ { }
+
+ StorePathWithOutputs(const StorePathWithOutputs & other)
+ : path(other.path.clone()), outputs(other.outputs)
+ { }
+
+ std::string to_string(const Store & store) const;
+};
+
+std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s);
+
}
namespace std {
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index 58966a5b7..f2e4b63e0 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -205,11 +205,12 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
void init() override
{
- if (!diskCache->cacheExists(getUri(), wantMassQuery_, priority)) {
-
+ if (auto cacheInfo = diskCache->cacheExists(getUri())) {
+ wantMassQuery.setDefault(cacheInfo->wantMassQuery ? "true" : "false");
+ priority.setDefault(fmt("%d", cacheInfo->priority));
+ } else {
BinaryCacheStore::init();
-
- diskCache->createCache(getUri(), storeDir, wantMassQuery_, priority);
+ diskCache->createCache(getUri(), storeDir, wantMassQuery, priority);
}
}
diff --git a/src/libstore/sqlite.hh b/src/libstore/sqlite.hh
index 0f46f6a07..fd04c9b07 100644
--- a/src/libstore/sqlite.hh
+++ b/src/libstore/sqlite.hh
@@ -103,8 +103,8 @@ void handleSQLiteBusy(const SQLiteBusy & e);
/* Convenience function for retrying a SQLite transaction when the
database is busy. */
-template<typename T>
-T retrySQLite(std::function<T()> fun)
+template<typename T, typename F>
+T retrySQLite(F && fun)
{
while (true) {
try {
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 0411db517..c29ca5a12 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -39,9 +39,9 @@ Path Store::toStorePath(const Path & path) const
}
-Path Store::followLinksToStore(const Path & _path) const
+Path Store::followLinksToStore(std::string_view _path) const
{
- Path path = absPath(_path);
+ Path path = absPath(std::string(_path));
while (!isInStore(path)) {
if (!isLink(path)) break;
string target = readLink(path);
@@ -53,12 +53,19 @@ Path Store::followLinksToStore(const Path & _path) const
}
-StorePath Store::followLinksToStorePath(const Path & path) const
+StorePath Store::followLinksToStorePath(std::string_view path) const
{
return parseStorePath(toStorePath(followLinksToStore(path)));
}
+StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view path) const
+{
+ auto [path2, outputs] = nix::parsePathWithOutputs(path);
+ return StorePathWithOutputs(followLinksToStorePath(path2), std::move(outputs));
+}
+
+
string storePathToHash(const Path & path)
{
auto base = baseNameOf(path);
@@ -963,7 +970,7 @@ std::list<ref<Store>> getDefaultSubstituters()
addStore(uri);
stores.sort([](ref<Store> & a, ref<Store> & b) {
- return a->getPriority() < b->getPriority();
+ return a->priority < b->priority;
});
return stores;
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 13ca3fef2..284e201de 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -242,23 +242,6 @@ struct BuildResult
};
-struct StorePathWithOutputs
-{
- StorePath path;
- std::set<std::string> outputs;
-
- StorePathWithOutputs(const StorePath & path, const std::set<std::string> & outputs = {})
- : path(path.clone()), outputs(outputs)
- { }
-
- StorePathWithOutputs(const StorePathWithOutputs & other)
- : path(other.path.clone()), outputs(other.outputs)
- { }
-
- std::string to_string(const Store & store) const;
-};
-
-
class Store : public std::enable_shared_from_this<Store>, public Config
{
public:
@@ -273,6 +256,10 @@ public:
const Setting<bool> isTrusted{this, false, "trusted", "whether paths from this store can be used as substitutes even when they lack trusted signatures"};
+ Setting<int> priority{this, 0, "priority", "priority of this substituter (lower value means higher priority)"};
+
+ Setting<bool> wantMassQuery{this, false, "want-mass-query", "whether this substituter can be queried efficiently for path validity"};
+
protected:
struct State
@@ -305,7 +292,7 @@ public:
/* Split a string specifying a derivation and a set of outputs
(/nix/store/hash-foo!out1,out2,...) into the derivation path
and the outputs. */
- StorePathWithOutputs parseDrvPathWithOutputs(const string & s);
+ StorePathWithOutputs parsePathWithOutputs(const string & s);
/* Display a set of paths in human-readable form (i.e., between quotes
and separated by commas). */
@@ -324,11 +311,13 @@ public:
Path toStorePath(const Path & path) const;
/* Follow symlinks until we end up with a path in the Nix store. */
- Path followLinksToStore(const Path & path) const;
+ Path followLinksToStore(std::string_view path) const;
/* Same as followLinksToStore(), but apply toStorePath() to the
result. */
- StorePath followLinksToStorePath(const Path & path) const;
+ StorePath followLinksToStorePath(std::string_view path) const;
+
+ StorePathWithOutputs followLinksToStorePathWithOutputs(std::string_view path) const;
/* Constructs a unique store path name. */
StorePath makeStorePath(const string & type,
@@ -438,8 +427,6 @@ public:
virtual void querySubstitutablePathInfos(const StorePathSet & paths,
SubstitutablePathInfos & infos) { return; };
- virtual bool wantMassQuery() { return false; }
-
/* Import a path into the store. */
virtual void addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs,
@@ -664,11 +651,6 @@ public:
return 0;
};
- /* Get the priority of the store, used to order substituters. In
- particular, binary caches can specify a priority field in their
- "nix-cache-info" file. Lower value means higher priority. */
- virtual int getPriority() { return 0; }
-
virtual Path toRealPath(const Path & storePath)
{
return storePath;