aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-06 17:45:20 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-06 17:45:20 +0100
commitbbc107ef1e850d73dbe9a21c567b34f5939570c6 (patch)
treea9ed9bc3394147b44e6bd7b5dc1d3b370b5732b4
parent3a95e1a17cd2755f00c26eb16ffd066bc6aa1a8d (diff)
Process binary caches in order of priority
Binary caches can now specify a priority in their nix-cache-info file. The binary cache substituter checks caches in order of priority. This is to ensure that fast, static caches like nixos.org/binary-cache are processed before slow, dynamic caches like hydra.nixos.org.
-rw-r--r--doc/manual/nix-push.xml11
-rw-r--r--scripts/download-from-binary-cache.pl.in21
2 files changed, 25 insertions, 7 deletions
diff --git a/doc/manual/nix-push.xml b/doc/manual/nix-push.xml
index 170b6f55a..ff0403834 100644
--- a/doc/manual/nix-push.xml
+++ b/doc/manual/nix-push.xml
@@ -210,6 +210,7 @@ properties. Here’s an example:
<screen>
StoreDir: /nix/store
WantMassQuery: 1
+Priority: 10
</screen>
The properties that are currently supported are:
@@ -246,6 +247,16 @@ The properties that are currently supported are:
</varlistentry>
+ <varlistentry><term><literal>Priority</literal></term>
+
+ <listitem><para>Each binary cache has a priority (defaulting to
+ 50). Binary caches are checked for binaries in order of ascending
+ priority; thus a higher number denotes a lower priority. The
+ binary cache <uri>http://nixos.org/binary-cache</uri> has priority
+ 40.</para></listitem>
+
+ </varlistentry>
+
</variablelist>
</para>
diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in
index a018b3b2a..a19f863d2 100644
--- a/scripts/download-from-binary-cache.pl.in
+++ b/scripts/download-from-binary-cache.pl.in
@@ -102,7 +102,9 @@ sub processRequests {
sub initCache {
- my $dbPath = "$Nix::Config::stateDir/binary-cache-v1.sqlite";
+ my $dbPath = "$Nix::Config::stateDir/binary-cache-v2.sqlite";
+
+ unlink "$Nix::Config::stateDir/binary-cache-v1.sqlite";
# Open/create the database.
$dbh = DBI->connect("dbi:SQLite:dbname=$dbPath", "", "")
@@ -120,7 +122,8 @@ sub initCache {
url text unique not null,
timestamp integer not null,
storeDir text not null,
- wantMassQuery integer not null
+ wantMassQuery integer not null,
+ priority integer not null
);
EOF
@@ -156,7 +159,7 @@ EOF
$dbh->do("create index if not exists NARExistenceByExistTimestamp on NARExistence (exist, timestamp)");
- $queryCache = $dbh->prepare("select id, storeDir, wantMassQuery from BinaryCaches where url = ?") or die;
+ $queryCache = $dbh->prepare("select id, storeDir, wantMassQuery, priority from BinaryCaches where url = ?") or die;
$insertNAR = $dbh->prepare(
"insert or replace into NARs(cache, storePath, url, compression, fileHash, fileSize, narHash, " .
@@ -220,7 +223,7 @@ sub getAvailableCaches {
my $res = $queryCache->fetchrow_hashref();
if (defined $res) {
next if $res->{storeDir} ne $Nix::Config::storeDir;
- push @caches, { id => $res->{id}, url => $url, wantMassQuery => $res->{wantMassQuery} };
+ push @caches, { id => $res->{id}, url => $url, wantMassQuery => $res->{wantMassQuery}, priority => $res->{priority} };
next;
}
@@ -236,6 +239,7 @@ sub getAvailableCaches {
my $storeDir = "/nix/store";
my $wantMassQuery = 0;
+ my $priority = 50;
foreach my $line (split "\n", $request->{content}) {
unless ($line =~ /^(.*): (.*)$/) {
print STDERR "bad cache info file ‘$request->{url}’\n";
@@ -243,15 +247,18 @@ sub getAvailableCaches {
}
if ($1 eq "StoreDir") { $storeDir = $2; }
elsif ($1 eq "WantMassQuery") { $wantMassQuery = int($2); }
+ elsif ($1 eq "Priority") { $priority = int($2); }
}
- $dbh->do("insert into BinaryCaches(url, timestamp, storeDir, wantMassQuery) values (?, ?, ?, ?)",
- {}, $url, time(), $storeDir, $wantMassQuery);
+ $dbh->do("insert into BinaryCaches(url, timestamp, storeDir, wantMassQuery, priority) values (?, ?, ?, ?, ?)",
+ {}, $url, time(), $storeDir, $wantMassQuery, $priority);
my $id = $dbh->last_insert_id("", "", "", "");
next if $storeDir ne $Nix::Config::storeDir;
- push @caches, { id => $id, url => $url, wantMassQuery => $wantMassQuery };
+ push @caches, { id => $id, url => $url, wantMassQuery => $wantMassQuery, priority => $priority };
}
+ @caches = sort { $a->{priority} <=> $b->{priority} } @caches;
+
expireNegative();
}