mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
download-from-binary-cache: do negative NAR info caching
I.e. if a NAR info file does *not* exist, we record it in the cache DB so that we don't retry it later.
This commit is contained in:
parent
89380c03e9
commit
ae60643c15
1 changed files with 29 additions and 5 deletions
|
@ -9,7 +9,7 @@ use DBI;
|
||||||
|
|
||||||
my @binaryCacheUrls = map { s/\/+$//; $_ } split(/ /, ($ENV{"NIX_BINARY_CACHES"} || ""));
|
my @binaryCacheUrls = map { s/\/+$//; $_ } split(/ /, ($ENV{"NIX_BINARY_CACHES"} || ""));
|
||||||
|
|
||||||
my ($dbh, $insertNAR, $queryNAR);
|
my ($dbh, $insertNAR, $queryNAR, $insertNegativeNAR, $queryNegativeNAR);
|
||||||
my %cacheIds;
|
my %cacheIds;
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,24 +52,48 @@ EOF
|
||||||
);
|
);
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
$dbh->do(<<EOF);
|
||||||
|
create table if not exists NegativeNARs (
|
||||||
|
cache integer not null,
|
||||||
|
storePath text not null,
|
||||||
|
timestamp integer not null,
|
||||||
|
primary key (cache, storePath),
|
||||||
|
foreign key (cache) references BinaryCaches(id) on delete cascade
|
||||||
|
);
|
||||||
|
EOF
|
||||||
|
|
||||||
$insertNAR = $dbh->prepare(
|
$insertNAR = $dbh->prepare(
|
||||||
"insert or replace into NARs(cache, storePath, url, compression, fileHash, fileSize, narHash, " .
|
"insert or replace into NARs(cache, storePath, url, compression, fileHash, fileSize, narHash, " .
|
||||||
"narSize, refs, deriver, system, timestamp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") or die;
|
"narSize, refs, deriver, system, timestamp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") or die;
|
||||||
|
|
||||||
$queryNAR = $dbh->prepare("select * from NARs where cache = ? and storePath = ?") or die;
|
$queryNAR = $dbh->prepare("select * from NARs where cache = ? and storePath = ?") or die;
|
||||||
|
|
||||||
|
$insertNegativeNAR = $dbh->prepare(
|
||||||
|
"insert or replace into NegativeNARs(cache, storePath, timestamp) values (?, ?, ?)") or die;
|
||||||
|
|
||||||
|
$queryNegativeNAR = $dbh->prepare("select 1 from NegativeNARs where cache = ? and storePath = ?") or die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub getInfoFrom {
|
sub getInfoFrom {
|
||||||
my ($storePath, $pathHash, $binaryCacheUrl, $cacheId) = @_;
|
my ($storePath, $pathHash, $binaryCacheUrl) = @_;
|
||||||
|
|
||||||
|
my $cacheId = getCacheId($binaryCacheUrl);
|
||||||
|
|
||||||
|
# Bail out if there is a negative cache entry.
|
||||||
|
$queryNegativeNAR->execute($cacheId, basename($storePath));
|
||||||
|
return undef if @{$queryNegativeNAR->fetchall_arrayref()} != 0;
|
||||||
|
|
||||||
my $infoUrl = "$binaryCacheUrl/$pathHash.narinfo";
|
my $infoUrl = "$binaryCacheUrl/$pathHash.narinfo";
|
||||||
print STDERR "checking $infoUrl...\n";
|
print STDERR "checking $infoUrl...\n";
|
||||||
my $s = `$Nix::Config::curl --fail --silent --location $infoUrl`;
|
my $s = `$Nix::Config::curl --fail --silent --location $infoUrl`;
|
||||||
if ($? != 0) {
|
if ($? != 0) {
|
||||||
my $status = $? >> 8;
|
my $status = $? >> 8;
|
||||||
print STDERR "could not download ‘$infoUrl’ (curl returned status ", $? >> 8, ")\n"
|
if ($status != 22 && $status != 37) {
|
||||||
if $status != 22 && $status != 37;
|
print STDERR "could not download ‘$infoUrl’ (curl returned status ", $? >> 8, ")\n";
|
||||||
|
} else {
|
||||||
|
$insertNegativeNAR->execute($cacheId, basename($storePath), time());
|
||||||
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +121,7 @@ sub getInfoFrom {
|
||||||
|
|
||||||
# Cache the result.
|
# Cache the result.
|
||||||
$insertNAR->execute(
|
$insertNAR->execute(
|
||||||
getCacheId($binaryCacheUrl), basename($storePath), $url, $compression, $fileHash, $fileSize,
|
$cacheId, basename($storePath), $url, $compression, $fileHash, $fileSize,
|
||||||
$narHash, $narSize, join(" ", @refs), $deriver, $system, time());
|
$narHash, $narSize, join(" ", @refs), $deriver, $system, time());
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue