Skip to content

Commit

Permalink
Make ValidPathInfo have plain StorePathSet references like before
Browse files Browse the repository at this point in the history
This change can wait for another PR.
  • Loading branch information
Ericson2314 committed Jan 14, 2023
1 parent 056cc1c commit b3d9123
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 166 deletions.
4 changes: 2 additions & 2 deletions perl/lib/Nix/Store.xs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int isValidPath(char * path)
SV * queryReferences(char * path)
PPCODE:
try {
for (auto & i : store()->queryPathInfo(store()->parseStorePath(path))->referencesPossiblyToSelf())
for (auto & i : store()->queryPathInfo(store()->parseStorePath(path))->references)
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(i).c_str(), 0)));
} catch (Error & e) {
croak("%s", e.what());
Expand Down Expand Up @@ -110,7 +110,7 @@ SV * queryPathInfo(char * path, int base32)
mXPUSHi(info->registrationTime);
mXPUSHi(info->narSize);
AV * refs = newAV();
for (auto & i : info->referencesPossiblyToSelf())
for (auto & i : info->references)
av_push(refs, newSVpv(store()->printStorePath(i).c_str(), 0));
XPUSHs(sv_2mortal(newRV((SV *) refs)));
AV * sigs = newAV();
Expand Down
5 changes: 2 additions & 3 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1544,8 +1544,7 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, V
StorePathSet refs;
if (state.store->isInStore(path)) {
try {
// FIXME: Are self references becoming non-self references OK?
refs = state.store->queryPathInfo(state.store->toStorePath(path).first)->referencesPossiblyToSelf();
refs = state.store->queryPathInfo(state.store->toStorePath(path).first)->references;
} catch (Error &) { // FIXME: should be InvalidPathError
}
// Re-scan references to filter down to just the ones that actually occur in the file.
Expand Down Expand Up @@ -1980,7 +1979,7 @@ static void addPath(
try {
auto [storePath, subPath] = state.store->toStorePath(path);
// FIXME: we should scanForReferences on the path before adding it
refs = state.store->queryPathInfo(storePath)->referencesPossiblyToSelf();
refs = state.store->queryPathInfo(storePath)->references;
path = state.store->toRealPath(storePath) + subPath;
} catch (Error &) { // FIXME: should be InvalidPathError
}
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
duration);

/* Verify that all references are valid. This may do some .narinfo
reads, but typically they'll already be cached. Note that
self-references are always valid. */
for (auto & ref : info.references.others)
reads, but typically they'll already be cached. */
for (auto & ref : info.references)
try {
queryPathInfo(ref);
if (ref != info.path)
queryPathInfo(ref);
} catch (InvalidPath &) {
throw Error("cannot add '%s' to the binary cache because the reference '%s' is not valid",
printStorePath(info.path), printStorePath(ref));
Expand Down
11 changes: 7 additions & 4 deletions src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,10 @@ DrvOutputs LocalDerivationGoal::registerOutputs()
auto narHashAndSize = hashPath(htSHA256, actualPath);
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
newInfo0.narSize = narHashAndSize.second;
newInfo0.references = rewriteRefs();
auto refs = rewriteRefs();
newInfo0.references = std::move(refs.others);
if (refs.self)
newInfo0.references.insert(newInfo0.path);
return newInfo0;
},

Expand Down Expand Up @@ -2774,12 +2777,12 @@ void LocalDerivationGoal::checkOutputs(const std::map<std::string, ValidPathInfo
auto i = outputsByPath.find(worker.store.printStorePath(path));
if (i != outputsByPath.end()) {
closureSize += i->second.narSize;
for (auto & ref : i->second.referencesPossiblyToSelf())
for (auto & ref : i->second.references)
pathsLeft.push(ref);
} else {
auto info = worker.store.queryPathInfo(path);
closureSize += info->narSize;
for (auto & ref : info->referencesPossiblyToSelf())
for (auto & ref : info->references)
pathsLeft.push(ref);
}
}
Expand Down Expand Up @@ -2819,7 +2822,7 @@ void LocalDerivationGoal::checkOutputs(const std::map<std::string, ValidPathInfo

auto used = recursive
? getClosure(info.path).first
: info.referencesPossiblyToSelf();
: info.references;

if (recursive && checks.ignoreSelfRefs)
used.erase(info.path);
Expand Down
10 changes: 6 additions & 4 deletions src/libstore/build/substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ void PathSubstitutionGoal::tryNext()

/* To maintain the closure invariant, we first have to realise the
paths referenced by this one. */
for (auto & i : info->references.others)
addWaitee(worker.makePathSubstitutionGoal(i));
for (auto & i : info->references)
if (i != storePath) /* ignore self-references */
addWaitee(worker.makePathSubstitutionGoal(i));

if (waitees.empty()) /* to prevent hang (no wake-up event) */
referencesValid();
Expand All @@ -187,8 +188,9 @@ void PathSubstitutionGoal::referencesValid()
return;
}

for (auto & i : info->references.others)
assert(worker.store.isValidPath(i));
for (auto & i : info->references)
if (i != storePath) /* ignore self-references */
assert(worker.store.isValidPath(i));

state = &PathSubstitutionGoal::tryToRun;
worker.wakeUp(shared_from_this());
Expand Down
10 changes: 10 additions & 0 deletions src/libstore/content-address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ Hash getContentAddressHash(const ContentAddress & ca)
}, ca);
}

bool StoreReferences::empty() const
{
return !self && others.empty();
}

size_t StoreReferences::size() const
{
return (self ? 1 : 0) + others.size();
}

ContentAddressWithReferences caWithoutRefs(const ContentAddress & ca) {
return std::visit(overloaded {
[&](const TextHash & h) -> ContentAddressWithReferences {
Expand Down
11 changes: 9 additions & 2 deletions src/libstore/content-address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "hash.hh"
#include "path.hh"
#include "comparator.hh"
#include "reference-set.hh"

namespace nix {

Expand Down Expand Up @@ -95,7 +94,15 @@ Hash getContentAddressHash(const ContentAddress & ca);
* References set
*/

typedef References<StorePath> StoreReferences;
struct StoreReferences {
StorePathSet others;
bool self = false;

bool empty() const;
size_t size() const;

GENERATE_CMP(StoreReferences, me->self, me->others);
};

/*
* Full content address
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
logger->startWork();
StorePathSet paths;
if (op == wopQueryReferences)
for (auto & i : store->queryPathInfo(path)->referencesPossiblyToSelf())
for (auto & i : store->queryPathInfo(path)->references)
paths.insert(i);
else if (op == wopQueryReferrers)
store->queryReferrers(path, paths);
Expand Down Expand Up @@ -758,7 +758,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
else {
to << 1
<< (i->second.deriver ? store->printStorePath(*i->second.deriver) : "");
worker_proto::write(*store, to, i->second.references.possiblyToSelf(path));
worker_proto::write(*store, to, i->second.references);
to << i->second.downloadSize
<< i->second.narSize;
}
Expand All @@ -781,7 +781,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
for (auto & i : infos) {
to << store->printStorePath(i.first)
<< (i.second.deriver ? store->printStorePath(*i.second.deriver) : "");
worker_proto::write(*store, to, i.second.references.possiblyToSelf(i.first));
worker_proto::write(*store, to, i.second.references);
to << i.second.downloadSize << i.second.narSize;
}
break;
Expand Down Expand Up @@ -863,7 +863,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
ValidPathInfo info { path, narHash };
if (deriver != "")
info.deriver = store->parseStorePath(deriver);
info.setReferencesPossiblyToSelf(worker_proto::read(*store, from, Phantom<StorePathSet> {}));
info.references = worker_proto::read(*store, from, Phantom<StorePathSet> {});
from >> info.registrationTime >> info.narSize >> info.ultimate;
info.sigs = readStrings<StringSet>(from);
info.ca = parseContentAddressOpt(readString(from));
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/export-import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Store::exportPath(const StorePath & path, Sink & sink)
teeSink
<< exportMagic
<< printStorePath(path);
worker_proto::write(*this, teeSink, info->referencesPossiblyToSelf());
worker_proto::write(*this, teeSink, info->references);
teeSink
<< (info->deriver ? printStorePath(*info->deriver) : "")
<< 0;
Expand Down Expand Up @@ -80,7 +80,7 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
ValidPathInfo info { path, narHash };
if (deriver != "")
info.deriver = parseStorePath(deriver);
info.setReferencesPossiblyToSelf(std::move(references));
info.references = references;
info.narSize = saved.s.size();

// Ignore optional legacy signature.
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
auto deriver = readString(conn->from);
if (deriver != "")
info->deriver = parseStorePath(deriver);
info->setReferencesPossiblyToSelf(worker_proto::read(*this, conn->from, Phantom<StorePathSet> {}));
info->references = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
readLongLong(conn->from); // download size
info->narSize = readLongLong(conn->from);

Expand Down Expand Up @@ -171,7 +171,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
<< printStorePath(info.path)
<< (info.deriver ? printStorePath(*info.deriver) : "")
<< info.narHash.to_string(Base16, false);
worker_proto::write(*this, conn->to, info.referencesPossiblyToSelf());
worker_proto::write(*this, conn->to, info.references);
conn->to
<< info.registrationTime
<< info.narSize
Expand Down Expand Up @@ -200,7 +200,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
conn->to
<< exportMagic
<< printStorePath(info.path);
worker_proto::write(*this, conn->to, info.referencesPossiblyToSelf());
worker_proto::write(*this, conn->to, info.references);
conn->to
<< (info.deriver ? printStorePath(*info.deriver) : "")
<< 0
Expand Down
10 changes: 4 additions & 6 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,7 @@ std::shared_ptr<const ValidPathInfo> LocalStore::queryPathInfoInternal(State & s
auto useQueryReferences(state.stmts->QueryReferences.use()(info->id));

while (useQueryReferences.next())
info->insertReferencePossiblyToSelf(
parseStorePath(useQueryReferences.getStr(0)));
info->references.insert(parseStorePath(useQueryReferences.getStr(0)));

return info;
}
Expand Down Expand Up @@ -1206,7 +1205,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)

for (auto & [_, i] : infos) {
auto referrer = queryValidPathId(*state, i.path);
for (auto & j : i.referencesPossiblyToSelf())
for (auto & j : i.references)
state->stmts->AddReference.use()(referrer)(queryValidPathId(*state, j)).exec();
}

Expand All @@ -1227,7 +1226,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
topoSort(paths,
{[&](const StorePath & path) {
auto i = infos.find(path);
return i == infos.end() ? StorePathSet() : i->second.references.others;
return i == infos.end() ? StorePathSet() : i->second.references;
}},
{[&](const StorePath & path, const StorePath & parent) {
return BuildError(
Expand Down Expand Up @@ -1525,8 +1524,7 @@ StorePath LocalStore::addTextToStore(

ValidPathInfo info { dstPath, narHash };
info.narSize = sink.s.size();
// No self reference allowed with text-hashing
info.references.others = references;
info.references = references;
info.ca = TextHash { .hash = hash };
registerValidPath(info);
}
Expand Down
5 changes: 3 additions & 2 deletions src/libstore/make-content-addressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ std::map<StorePath, StorePath> makeContentAddressed(
StringMap rewrites;

StoreReferences refs;
refs.self = oldInfo->references.self;
for (auto & ref : oldInfo->references.others) {
for (auto & ref : oldInfo->references) {
if (ref == path)
refs.self = true;
auto i = remappings.find(ref);
auto replacement = i != remappings.end() ? i->second : ref;
// FIXME: warn about unremapped paths?
Expand Down
11 changes: 6 additions & 5 deletions src/libstore/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ void Store::computeFSClosure(const StorePathSet & startPaths,
std::future<ref<const ValidPathInfo>> & fut) {
StorePathSet res;
auto info = fut.get();
for (auto & ref : info->references.others)
res.insert(ref);
for (auto & ref : info->references)
if (ref != path)
res.insert(ref);

if (includeOutputs && path.isDerivation())
for (auto & [_, maybeOutPath] : queryPartialDerivationOutputMap(path))
Expand Down Expand Up @@ -223,7 +224,7 @@ void Store::queryMissing(const std::vector<DerivedPath> & targets,
state->narSize += info->second.narSize;
}

for (auto & ref : info->second.references.others)
for (auto & ref : info->second.references)
pool.enqueue(std::bind(doPath, DerivedPath::Opaque { ref }));
},
}, req.raw());
Expand All @@ -241,7 +242,7 @@ StorePaths Store::topoSortPaths(const StorePathSet & paths)
return topoSort(paths,
{[&](const StorePath & path) {
try {
return queryPathInfo(path)->references.others;
return queryPathInfo(path)->references;
} catch (InvalidPath &) {
return StorePathSet();
}
Expand Down Expand Up @@ -297,7 +298,7 @@ std::map<DrvOutput, StorePath> drvOutputReferences(

auto info = store.queryPathInfo(outputPath);

return drvOutputReferences(Realisation::closure(store, inputRealisations), info->referencesPossiblyToSelf());
return drvOutputReferences(Realisation::closure(store, inputRealisations), info->references);
}

OutputPathMap resolveDerivedPath(Store & store, const DerivedPath::Built & bfd, Store * evalStore_)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
narInfo->fileSize = queryNAR.getInt(5);
narInfo->narSize = queryNAR.getInt(7);
for (auto & r : tokenizeString<Strings>(queryNAR.getStr(8), " "))
narInfo->insertReferencePossiblyToSelf(StorePath(r));
narInfo->references.insert(StorePath(r));
if (!queryNAR.isNull(9))
narInfo->deriver = StorePath(queryNAR.getStr(9));
for (auto & sig : tokenizeString<Strings>(queryNAR.getStr(10), " "))
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/nar-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
auto refs = tokenizeString<Strings>(value, " ");
if (!references.empty()) throw corrupt();
for (auto & r : refs)
insertReferencePossiblyToSelf(StorePath(r));
references.insert(StorePath(r));
}
else if (name == "Deriver") {
if (value != "unknown-deriver")
Expand Down
Loading

0 comments on commit b3d9123

Please sign in to comment.