mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
Re-implement the WantMassQuery property of binary caches
This commit is contained in:
parent
b66ab6cdbc
commit
e222484401
8 changed files with 40 additions and 8 deletions
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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’")
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
|
|||
|
||||
BinaryCacheStore::init();
|
||||
|
||||
diskCache->createCache(getUri());
|
||||
diskCache->createCache(getUri(), wantMassQuery, priority);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue