Skip to content

Comments

Can build single CA derivations#3883

Merged
edolstra merged 31 commits intoNixOS:masterfrom
obsidiansystems:single-ca-drv-build
Sep 16, 2020
Merged

Can build single CA derivations#3883
edolstra merged 31 commits intoNixOS:masterfrom
obsidiansystems:single-ca-drv-build

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jul 31, 2020

Featurewise, we're testing little more than what #3740 can do, but a behind the scenes there is a lot of infra changes in place to make this robust:

  • Via Mischellaneous changes to prepare for CA drvs -- contains #3807, #3424, and #3418 #3830 the legacy style build hashes are thoroughly excised from the floating CA derivation case--almost everywhere Nix now either handles the case where output paths are not known a priori, or throws an UnimplementedError saying it cannont. (I say "almost" because there is one more issue to sort out with src/libexpr/get-drvs.hh:getOutPath.)

  • DerivationGoal::registerOutputs has been almost completely rewritten. Before it would first calculate content hashes and then references, because we never had references in the CA case. Now, it calculates references and then hashes, so we can do both for CA derivations. This is also integrated with the existing rewriting/relocating we did for --check and --repair.

The new functionality is ready to go. WIP because of conflicts and because it depends on PRs which still have rough edges.

@Ericson2314 Ericson2314 changed the title Can build single CA derivations --- contains many other PRs WIP: Can build single CA derivations --- contains many other PRs Jul 31, 2020
@Ericson2314 Ericson2314 force-pushed the single-ca-drv-build branch from 5f1aa4b to 4e37ab5 Compare August 7, 2020 19:42
@Ericson2314 Ericson2314 force-pushed the single-ca-drv-build branch from 4e37ab5 to e913a29 Compare August 7, 2020 20:08
@Ericson2314 Ericson2314 changed the title WIP: Can build single CA derivations --- contains many other PRs WIP: Can build single CA derivations --- contains #3895 Aug 7, 2020
@Ericson2314
Copy link
Member Author

OK I now rebased away some PRs this PR previously contained that it doesn't actually needed. That means I can also remove the WIP!

@Ericson2314 Ericson2314 changed the title WIP: Can build single CA derivations --- contains #3895 Can build single CA derivations --- contains #3895 Aug 7, 2020
@Ericson2314 Ericson2314 changed the title Can build single CA derivations --- contains #3895 Can build single CA derivations --- contains #3895 and #3914 Aug 10, 2020
@Ericson2314 Ericson2314 changed the title Can build single CA derivations --- contains #3895 and #3914 Can build single CA derivations --- contains #3895 & #3914 Aug 10, 2020
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review everything yet (that's a pretty big and dense diff), but looks pretty good overall

std::optional<StorePath> read(const Store & store, Source & from, Phantom<std::optional<StorePath>> _)
{
auto s = readString(from);
return s == "" ? std::optional<StorePath> {} : store.parseStorePath(s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add a fallback to the generic std::optional<T> implementation just in case we want to remove this special-casing in a future version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe....? The comparability considerations are numerous and it's hard to keep track of them all. I hope when we discuss in person we can try to get a grasp on those.

that's a pretty big and dense diff

If we can get a grasp on those, maybe we can merge #3895 first, and then this PR should be easier to review.

needsMove = false;
}
rewriteOutput();
/* FIXME optimize and deduplicate with addToStore */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More than just addToStore, this is morally a duplicate of CmdMakeContentAddressable::run (modulo a couple of details like the fact that the original path isn't a valid path)

Copy link
Member Author

@Ericson2314 Ericson2314 Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I just think those details, while conceptually insignificant, will make abstracting over this and CmdMakeContentAddressable::run harder. I am thinking start with making Store::addToStoreFromDump references-aware, maybe then merge with Store::addTextToStore, and only then re-compare with CmdMakeContentAddressable::run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep', makes sense. That's roughly what I'd done in b959bae (except that I don't use addToStoreFromDump because I wanted to keep the original pathInfo)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have found the C++ non-trivial to deduplicate too. I think it's better to land the features and then choose the abstractions to make sure we don't abstract the wrong way----the plethora of addToStore-like functions kindof implies we've already been abstracting suboptimally, so I think a rethink should be very broad and systematic.

ValidPathInfos infos2;
for (auto & i : infos) infos2.push_back(i.second);
for (auto & [outputName, newInfo] : infos) {
/* FIXME: we will want to track this mapping in the DB whether or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have forgotten something obvious, but is there anything preventing us from calling linkDeriverToPath without a derivation? (obviously we don't have the drvPath, but afaik we can recompute it since derivations are content-addressed)

Copy link
Member Author

@Ericson2314 Ericson2314 Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a BasicDerivation not Derivation in the general case. We don't currently have an unparse for those, so it's just a matter of bike-shdding whether we want to take the opportunity to switch to JSON or anything else while we're at it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3958 shows we don't need a new unparse, but there still is the question of whether to either:

  • relax foreign key constraint, so we can link without file
  • write drv file to store so we can link with current foreign key constraint

I have no string preference. My only concern is we might want to keep around any mapping in the build closure of other mappings, which changes GC semantics.

@Ericson2314 Ericson2314 changed the title Can build single CA derivations --- contains #3895 & #3914 Can build single CA derivations --- contains #3895 Aug 11, 2020
Thanks @regnat for catching one of them. The other follows for many of
the same reasons. I'm find fixing others on a need-to-fix basis,
provided their are no regressions.
It might have changed, and in any event this is how the cod used to work
so let's just keep it.
@Ericson2314 Ericson2314 changed the title Can build single CA derivations --- contains #3895 Can build single CA derivations --- contains #3859 Aug 20, 2020
 - `queryDerivationOutputMapAssumeTotal` -> `queryPartialDerivationOutputMap`
 - `queryDerivationOutputMapAssumeTotal` -> `queryDerivationOutputMap
Insead they should be opaque `/<hash>` like the placeholders we already
have.
@Ericson2314 Ericson2314 changed the title Can build single CA derivations --- contains #3859 Can build single CA derivations Aug 28, 2020
Ericson2314 and others added 5 commits September 4, 2020 10:29
Co-authored-by: Théophane Hufschmitt <[email protected]>
Thanks!

Co-authored-by: Eelco Dolstra <[email protected]>
 - More and better comments

 - The easier renames
@Ericson2314
Copy link
Member Author

@regnat

* There's a store method called `getDerivation`, but that's not implemented for `RemoteStore`

Sorry, I must be doing something silly, but I really don't see it. Just ones defined elsewhere.

* There's also `Store::narFromPath` that's also not implemented for `RemoteStore`, **but** the worker protocol has already the logic to handle it (because it's used by `SSHStore`), so we just need to upstream `SSHStore::narFromPath` into `RemoteStore` and it should be good. That's a lot of hops for such a workaround, but hopefully that should work

I agree it should be part of RemoteStore, but this isn't a problem in practice: in the only other extant case, using a Unix domain socket, LocalFSStore is also mixed in as a superclass, and it provides narFromPath.

So I think we fix this right away!

@thufschmitt
Copy link
Member

  • There's a store method called getDerivation, but that's not implemented for RemoteStore
    Sorry, I must be doing something silly, but I really don't see it. Just ones defined elsewhere.

My double-bad, it's readDerivation and not getDerivation.

I agree it should be part of RemoteStore, but this isn't a problem in practice: in the only other extant case, using a Unix domain socket, LocalFSStore is also mixed in as a superclass, and it provides narFromPath.

So I think we fix this right away!

That's a fair point. Actually both SSHStore and LocalFSStore implement readDerivation (using the default implem that calls out to getFSAccessor), so I think we can directly resort to readDerivation
(and after a second look it's actually trivial to implement it for RemoteStore too without changing the protocol if we want)

@thufschmitt
Copy link
Member

So I think we fix this right away!

I've implemented it in 0b5f339 if you want to cherry-pick it

@Ericson2314
Copy link
Member Author

Ericson2314 commented Sep 7, 2020

@regnat What branch is that commit on? I'd love to cherry-pick it, but I'm having trouble fetching it! Alternatively, if you want to make a PR with it (since I don't think it depends on any of this?) I'll make this PR depend on that PR.

@Ericson2314
Copy link
Member Author

@regnat see my previous comment?

@thufschmitt
Copy link
Member

@regnat see my previous comment?

Uh sorry, totally missed it.

Here you are: #4014

Otherwise, we will associate fixed-output derivations with outputs that
they did indeed produce, but which had the wrong hash. That's no good.
@Ericson2314
Copy link
Member Author

@edolstra it looks like this was accidentally closed because GitHub got excited about the word "fix". Can you repopen it?

@edolstra edolstra reopened this Sep 15, 2020
@edolstra edolstra merged commit 609a6d6 into NixOS:master Sep 16, 2020
@edolstra
Copy link
Member

Thanks, merged!

@Ericson2314 Ericson2314 deleted the single-ca-drv-build branch September 16, 2020 14:05
Ma27 added a commit to Ma27/hydra that referenced this pull request Sep 26, 2020
Recently a few internal APIs have changed[1]. The `outputPaths` function
has been removed and a lot of data structures are modeled with
`std::optional` which broke compilation.

This patch updates the code in `hydra-queue-runner` accordingly to make
sure that Hydra compiles again.

[1] NixOS/nix#3883
@thufschmitt thufschmitt added the ca-derivations Derivations with content addressed outputs label Nov 16, 2020
@thufschmitt thufschmitt added this to the ca-derivations-mvp milestone Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ca-derivations Derivations with content addressed outputs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants