1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-17 14:31:06 +01:00

Revert "Use the hash modulo in the derivation outputs"

Fix #11897

As described in the issue, this makes for a simpler and much more
intuitive notion of a realisation key. This is better for pedagogy, and
interoperability between more tools.

The way the issue was written was that we would switch to only having
shallow realisations first, and then do this. But going to only shallow
realisations is more complex change, and it turns out we weren't even
testing for the benefits that derivation hashes (modulo FODs) provided
in the deep realisation case, so I now just want to do this first.

Doing this gets the binary cache data structures in order, which will
unblock the Hydra fixed-output-derivation tracking work. I don't want to
delay that work while I figure out the changes needed for
shallow-realisations only.

This reverts commit bab1cda0e6.
This commit is contained in:
John Ericson 2025-02-12 23:54:24 -05:00
parent 15f3abb35e
commit 043eed85da
53 changed files with 918 additions and 698 deletions

View file

@ -44,10 +44,16 @@ create table if not exists NARs (
create table if not exists Realisations (
cache integer not null,
outputId text not null,
content blob, -- Json serialisation of the realisation, or null if the realisation is absent
drvPath text not null,
outputName text not null,
-- The following are null if the realisation is absent
outputPath text,
sigs text,
timestamp integer not null,
primary key (cache, outputId),
primary key (cache, drvPath, outputName),
foreign key (cache) references BinaryCaches(id) on delete cascade
);
@ -121,24 +127,24 @@ public:
state->insertRealisation.create(
state->db,
R"(
insert or replace into Realisations(cache, outputId, content, timestamp)
values (?, ?, ?, ?)
insert or replace into Realisations(cache, drvPath, outputName, outputPath, sigs, timestamp)
values (?, ?, ?, ?, ?, ?)
)");
state->insertMissingRealisation.create(
state->db,
R"(
insert or replace into Realisations(cache, outputId, timestamp)
values (?, ?, ?)
insert or replace into Realisations(cache, drvPath, outputName, timestamp)
values (?, ?, ?, ?)
)");
state->queryRealisation.create(
state->db,
R"(
select content from Realisations
where cache = ? and outputId = ? and
((content is null and timestamp > ?) or
(content is not null and timestamp > ?))
select outputPath, sigs from Realisations
where cache = ? and drvPath = ? and outputName = ? and
((outputPath is null and timestamp > ?) or
(outputPath is not null and timestamp > ?))
)");
/* Periodically purge expired entries from the database. */
@ -295,22 +301,27 @@ public:
auto now = time(0);
auto queryRealisation(state->queryRealisation.use()(cache.id)(id.to_string())(
auto queryRealisation(state->queryRealisation.use()(cache.id)(id.drvPath.to_string())(id.outputName)(
now - settings.ttlNegativeNarInfoCache)(now - settings.ttlPositiveNarInfoCache));
if (!queryRealisation.next())
return {oUnknown, 0};
return {oUnknown, nullptr};
if (queryRealisation.isNull(0))
return {oInvalid, 0};
return {oInvalid, nullptr};
try {
return {
oValid,
std::make_shared<Realisation>(nlohmann::json::parse(queryRealisation.getStr(0))),
std::make_shared<Realisation>(
UnkeyedRealisation{
.outPath = StorePath{queryRealisation.getStr(0)},
.signatures = nlohmann::json::parse(queryRealisation.getStr(1)),
},
id),
};
} catch (Error & e) {
e.addTrace({}, "while parsing the local disk cache");
e.addTrace({}, "reading build trace key-value from the local disk cache");
throw;
}
});
@ -355,7 +366,9 @@ public:
auto & cache(getCache(*state, uri));
state->insertRealisation
.use()(cache.id)(realisation.id.to_string())(static_cast<nlohmann::json>(realisation).dump())(time(0))
.use()(cache.id)(realisation.id.drvPath.to_string())(realisation.id.outputName)(
realisation.outPath.to_string())(static_cast<nlohmann::json>(realisation.signatures).dump())(
time(0))
.exec();
});
}
@ -366,7 +379,7 @@ public:
auto state(_state.lock());
auto & cache(getCache(*state, uri));
state->insertMissingRealisation.use()(cache.id)(id.to_string())(time(0)).exec();
state->insertMissingRealisation.use()(cache.id)(id.drvPath.to_string())(id.outputName)(time(0)).exec();
});
}
};