Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
1722ae6
Pull out PathReferences super class
Ericson2314 Jun 25, 2020
71e4c9c
WIP: store separate `hasValidPath` bool
Ericson2314 Jun 24, 2020
a9c0ea3
Backport fix from #3754 branch
Ericson2314 Jun 29, 2020
70ed47c
Fix some things in remote store
Ericson2314 Jun 29, 2020
6683406
Fix nar info parsing
Ericson2314 Jun 29, 2020
0e9e599
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Aug 1, 2020
36dd792
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Aug 4, 2020
e61061c
Remove stray tabs
Ericson2314 Aug 4, 2020
45ca7c3
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Sep 23, 2020
dae4409
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Oct 6, 2020
f8d562c
Use PathReferences more widely
Ericson2314 Oct 7, 2020
a0f369a
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Oct 12, 2020
39c11c5
Organize content-address.hh a bit better
Ericson2314 Oct 13, 2020
34b3bfa
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Oct 13, 2020
10e81bf
Fix conditions for ca-references
Ericson2314 Oct 15, 2020
ca09948
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Feb 25, 2021
f0ad29a
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Feb 27, 2021
e12308d
Merge branch 'master' into path-info
Ericson2314 Apr 5, 2021
d5cef6c
Merge commit '9dfb97c987d8b9d6a3d15f016e40f22f91deb764' into path-info
Ericson2314 Apr 5, 2021
1b6cf0d
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Apr 5, 2021
f4f3203
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Sep 30, 2021
13b6b64
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Oct 1, 2021
8ba0895
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Mar 10, 2022
0dc2974
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Mar 25, 2022
2c21cb6
Fill in missing comparison operators for content addresses
Ericson2314 Mar 25, 2022
13c6691
Slight cleanups
Ericson2314 Apr 19, 2022
55caef3
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Apr 19, 2022
e9fc1e4
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Jan 6, 2023
8623143
Make formatting consistent
Ericson2314 Jan 6, 2023
6a16825
Use named field initialization for references
Ericson2314 Jan 6, 2023
9cfa78e
Optimize `ValidPathInfo` construction a bit better
Ericson2314 Jan 6, 2023
46e942f
Do big rename to clean up code
Ericson2314 Jan 6, 2023
91617f8
Fix perl bindings
Ericson2314 Jan 6, 2023
2e7be46
Move new `ValidPathInfo` methods to path-info.cc
Ericson2314 Jan 13, 2023
056cc1c
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Jan 14, 2023
b3d9123
Make `ValidPathInfo` have plain `StorePathSet` references like before
Ericson2314 Jan 14, 2023
c67e0cc
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Jan 23, 2023
4540e7b
Don't add `StorePathDescriptor` for now
Ericson2314 Jan 23, 2023
adb3608
Merge branch 'small-storePath-cleanups' into path-info
Ericson2314 Jan 30, 2023
974a983
Shrink diff in two places
Ericson2314 Jan 30, 2023
79b078a
Merge branch 'small-storePath-cleanups' into path-info
Ericson2314 Jan 30, 2023
b6c9875
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Jan 30, 2023
4341473
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Feb 1, 2023
0983a0b
Shrink diff in one place
Ericson2314 Feb 1, 2023
db759b1
Undo style change
Ericson2314 Feb 1, 2023
59d3175
Put back TODO
Ericson2314 Feb 1, 2023
ee9eb83
Remove some designated initializers
Ericson2314 Feb 1, 2023
87ca462
Merge branch 'master' into path-info
Ericson2314 Feb 2, 2023
c36b584
Fix typo in the method name
Ericson2314 Feb 28, 2023
d12f57c
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Feb 28, 2023
123b11f
Clarify store path grammar and improve comment on `makeType`
Ericson2314 Feb 28, 2023
85bb865
Revert "Remove some designated initializers"
Ericson2314 Feb 28, 2023
d381248
No inheritance for `TextInfo` and `FixedOutputInfo`
Ericson2314 Feb 28, 2023
aa99005
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Mar 30, 2023
a6d00a7
Fix warning
Ericson2314 Mar 30, 2023
c51d554
Use "raw pattern" for content address types
Ericson2314 Mar 30, 2023
5d56e2d
Add comparison methods for content addresses
Ericson2314 Apr 1, 2023
fd21f9d
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Apr 8, 2023
537e871
Explain various `.self = false,`
Ericson2314 Apr 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions perl/lib/Nix/Store.xs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ SV * queryPathInfo(char * path, int base32)
mXPUSHi(info->registrationTime);
mXPUSHi(info->narSize);
AV * arr = newAV();
for (auto & i : info->references)
for (auto & i : info->referencesPossiblyToSelf())
av_push(arr, newSVpv(store()->printStorePath(i).c_str(), 0));
XPUSHs(sv_2mortal(newRV((SV *) arr)));
} catch (Error & e) {
Expand Down Expand Up @@ -287,7 +287,13 @@ SV * makeFixedOutputPath(int recursive, char * algo, char * hash, char * name)
try {
auto h = Hash::parseAny(hash, parseHashType(algo));
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
auto path = store()->makeFixedOutputPath(method, h, name);
auto path = store()->makeFixedOutputPath(name, FixedOutputInfo {
{
.method = method,
.hash = h,
},
{},
});
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(path).c_str(), 0)));
} catch (Error & e) {
croak("%s", e.what());
Expand Down
16 changes: 14 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,13 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo);
Hash h = newHashAllowEmpty(*outputHash, ht);

auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName);
auto outPath = state.store->makeFixedOutputPath(drvName, FixedOutputInfo {
{
.method = ingestionMethod,
.hash = h,
},
{},
});
drv.env["out"] = state.store->printStorePath(outPath);
drv.outputs.insert_or_assign("out", DerivationOutput {
.output = DerivationOutputCAFixed {
Expand Down Expand Up @@ -1764,7 +1770,13 @@ static void addPath(EvalState & state, const Pos & pos, const string & name, con

std::optional<StorePath> expectedStorePath;
if (expectedHash)
expectedStorePath = state.store->makeFixedOutputPath(method, *expectedHash, name);
expectedStorePath = state.store->makeFixedOutputPath(name, FixedOutputInfo {
{
.method = method,
.hash = *expectedHash,
},
{},
});
Path dstPath;
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
dstPath = state.store->printStorePath(settings.readOnlyMode
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/value-to-xml.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ namespace nix {

void printValueAsXML(EvalState & state, bool strict, bool location,
Value & v, std::ostream & out, PathSet & context);

}
8 changes: 7 additions & 1 deletion src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ StorePath Input::computeStorePath(Store & store) const
auto narHash = getNarHash();
if (!narHash)
throw Error("cannot compute store path for mutable input '%s'", to_string());
return store.makeFixedOutputPath(FileIngestionMethod::Recursive, *narHash, "source");
return store.makeFixedOutputPath("source", FixedOutputInfo {
{
.method = FileIngestionMethod::Recursive,
.hash = *narHash,
},
{},
});
}

std::string Input::getType() const
Expand Down
16 changes: 11 additions & 5 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ DownloadFileResult downloadFile(
dumpString(*res.data, sink);
auto hash = hashString(htSHA256, *res.data);
ValidPathInfo info {
store->makeFixedOutputPath(FileIngestionMethod::Flat, hash, name),
*store,
{
.name = name,
.info = FixedOutputInfo {
{
.method = FileIngestionMethod::Flat,
.hash = hash,
},
{},
},
},
hashString(htSHA256, *sink.s),
};
info.narSize = sink.s->size();
info.ca = FixedOutputHash {
.method = FileIngestionMethod::Flat,
.hash = hash,
};
auto source = StringSource { *sink.s };
store->addToStore(info, source, NoRepair, NoCheckSigs);
storePath = std::move(info.path);
Expand Down
46 changes: 35 additions & 11 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
reads, but typically they'll already be cached. */
for (auto & ref : info.references)
try {
if (ref != info.path)
queryPathInfo(ref);
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 Expand Up @@ -323,7 +322,17 @@ StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, const string & nam
unsupported("addToStoreFromDump");
return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info {
makeFixedOutputPath(method, nar.first, name),
*this,
{
.name = name,
.info = FixedOutputInfo {
{
.method = method,
.hash = nar.first,
},
{},
},
},
nar.first,
};
info.narSize = nar.second;
Expand Down Expand Up @@ -413,14 +422,20 @@ StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath
});
return addToStoreCommon(*source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info {
makeFixedOutputPath(method, h, name),
*this,
{
.name = name,
.info = FixedOutputInfo {
{
.method = method,
.hash = h,
},
{},
},
},
nar.first,
};
info.narSize = nar.second;
info.ca = FixedOutputHash {
.method = method,
.hash = h,
};
return info;
})->path;
}
Expand All @@ -429,17 +444,26 @@ StorePath BinaryCacheStore::addTextToStore(const string & name, const string & s
const StorePathSet & references, RepairFlag repair)
{
auto textHash = hashString(htSHA256, s);
auto path = makeTextPath(name, textHash, references);
auto path = makeTextPath(name, TextInfo { textHash, references });

if (!repair && isValidPath(path))
return path;

auto source = StringSource { s };
return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info { path, nar.first };
ValidPathInfo info {
*this,
{
.name = name,
.info = TextInfo {
{ .hash = textHash },
references,
},
},
nar.first,
};
info.narSize = nar.second;
info.ca = TextHash { textHash };
info.references = references;
return info;
})->path;
}
Expand Down
62 changes: 28 additions & 34 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4008,27 +4008,26 @@ void DerivationGoal::registerOutputs()
}
};

auto rewriteRefs = [&]() -> std::pair<bool, StorePathSet> {
auto rewriteRefs = [&]() -> PathReferences<StorePath> {
/* In the CA case, we need the rewritten refs to calculate the
final path, therefore we look for a *non-rewritten
self-reference, and use a bool rather try to solve the
computationally intractable fixed point. */
std::pair<bool, StorePathSet> res {
false,
{},
PathReferences<StorePath> res {
.hasSelfReference = false,
};
for (auto & r : references) {
auto name = r.name();
auto origHash = std::string { r.hashPart() };
if (r == scratchPath)
res.first = true;
res.hasSelfReference = true;
else if (outputRewrites.count(origHash) == 0)
res.second.insert(r);
res.references.insert(r);
else {
std::string newRef = outputRewrites.at(origHash);
newRef += '-';
newRef += name;
res.second.insert(StorePath { newRef });
res.references.insert(StorePath { newRef });
}
}
return res;
Expand Down Expand Up @@ -4057,27 +4056,24 @@ void DerivationGoal::registerOutputs()
break;
}
auto got = caSink.finish().first;
auto refs = rewriteRefs();
HashModuloSink narSink { htSHA256, oldHashPart };
dumpPath(actualPath, narSink);
auto narHashAndSize = narSink.finish();
ValidPathInfo newInfo0 {
worker.store.makeFixedOutputPath(
outputHash.method,
got,
outputPathName(drv->name, outputName),
refs.second,
refs.first),
worker.store,
{
.name = outputPathName(drv->name, outputName),
.info = FixedOutputInfo {
{
.method = outputHash.method,
.hash = got,
},
rewriteRefs(),
},
},
narHashAndSize.first,
};
newInfo0.narSize = narHashAndSize.second;
newInfo0.ca = FixedOutputHash {
.method = outputHash.method,
.hash = got,
};
newInfo0.references = refs.second;
if (refs.first)
newInfo0.references.insert(newInfo0.path);

assert(newInfo0.ca);
return newInfo0;
Expand All @@ -4097,10 +4093,7 @@ void DerivationGoal::registerOutputs()
auto narHashAndSize = hashPath(htSHA256, actualPath);
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
newInfo0.narSize = narHashAndSize.second;
auto refs = rewriteRefs();
newInfo0.references = refs.second;
if (refs.first)
newInfo0.references.insert(newInfo0.path);
static_cast<PathReferences<StorePath> &>(newInfo0) = rewriteRefs();
return newInfo0;
},
[&](DerivationOutputCAFixed dof) {
Expand Down Expand Up @@ -4366,12 +4359,12 @@ void DerivationGoal::checkOutputs(const std::map<Path, ValidPathInfo> & outputs)
auto i = outputsByPath.find(worker.store.printStorePath(path));
if (i != outputsByPath.end()) {
closureSize += i->second.narSize;
for (auto & ref : i->second.references)
for (auto & ref : i->second.referencesPossiblyToSelf())
pathsLeft.push(ref);
} else {
auto info = worker.store.queryPathInfo(path);
closureSize += info->narSize;
for (auto & ref : info->references)
for (auto & ref : info->referencesPossiblyToSelf())
pathsLeft.push(ref);
}
}
Expand Down Expand Up @@ -4410,7 +4403,7 @@ void DerivationGoal::checkOutputs(const std::map<Path, ValidPathInfo> & outputs)

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

if (recursive && checks.ignoreSelfRefs)
used.erase(info.path);
Expand Down Expand Up @@ -4867,7 +4860,10 @@ void SubstitutionGoal::tryNext()
subs.pop_front();

if (ca) {
subPath = sub->makeFixedOutputPathFromCA(storePath.name(), *ca);
subPath = sub->makeFixedOutputPathFromCA({
.name = std::string { storePath.name() },
.info = caWithoutRefs(*ca),
});
if (sub->storeDir == worker.store.storeDir)
assert(subPath == storePath);
} else if (sub->storeDir != worker.store.storeDir) {
Expand Down Expand Up @@ -4897,7 +4893,7 @@ void SubstitutionGoal::tryNext()
}

if (info->path != storePath) {
if (info->isContentAddressed(*sub) && info->references.empty()) {
if (info->isContentAddressed(*sub) && info->references.empty() && !info->hasSelfReference) {
auto info2 = std::make_shared<ValidPathInfo>(*info);
info2->path = storePath;
info = info2;
Expand Down Expand Up @@ -4940,8 +4936,7 @@ void SubstitutionGoal::tryNext()
/* To maintain the closure invariant, we first have to realise the
paths referenced by this one. */
for (auto & i : info->references)
if (i != storePath) /* ignore self-references */
addWaitee(worker.makeSubstitutionGoal(i));
addWaitee(worker.makeSubstitutionGoal(i));

if (waitees.empty()) /* to prevent hang (no wake-up event) */
referencesValid();
Expand All @@ -4961,8 +4956,7 @@ void SubstitutionGoal::referencesValid()
}

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

state = &SubstitutionGoal::tryToRun;
worker.wakeUp(shared_from_this());
Expand Down
24 changes: 19 additions & 5 deletions src/libstore/content-address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ std::string FixedOutputHash::printMethodAlgo() const
return makeFileIngestionPrefix(method) + printHashType(hash.type);
}


std::string makeFileIngestionPrefix(const FileIngestionMethod m)
{
switch (m) {
case FileIngestionMethod::Flat:
return "";
case FileIngestionMethod::Recursive:
return "r:";
default:
throw Error("impossible, caught both cases");
}
assert(false);
}

std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash)
Expand All @@ -32,10 +32,13 @@ std::string renderContentAddress(ContentAddress ca)
{
return std::visit(overloaded {
[](TextHash th) {
return "text:" + th.hash.to_string(Base32, true);
return "text:"
+ th.hash.to_string(Base32, true);
},
[](FixedOutputHash fsh) {
return makeFixedOutputCA(fsh.method, fsh.hash);
return "fixed:"
+ makeFileIngestionPrefix(fsh.method)
+ fsh.hash.to_string(Base32, true);
}
}, ca);
}
Expand Down Expand Up @@ -142,7 +145,18 @@ Hash getContentAddressHash(const ContentAddress & ca)
},
[](FixedOutputHash fsh) {
return fsh.hash;
}
},
}, ca);
}

ContentAddressWithReferences caWithoutRefs(const ContentAddress & ca) {
return std::visit(overloaded {
[&](TextHash h) -> ContentAddressWithReferences {
return TextInfo { h, {}};
},
[&](FixedOutputHash h) -> ContentAddressWithReferences {
return FixedOutputInfo { h, {}};
},
}, ca);
}

Expand Down
Loading