Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix-cache] Prevent checking cache twice per package #2055

Merged
merged 3 commits into from
May 16, 2024

Conversation

mikeland73
Copy link
Contributor

Summary

Fixes bug described here #2054

A better (but a bit more involved) solution is to parallelize by output. Currently we parallelize by meta-output (which includes __default_output__). This has two downsides:

  • __default_output__ can be multiple outputs, in which case we don't parallelize them at all.
  • We still do redundant work when __default_output__ is multiple outputs. (once as __default_output__ and once for each individual outout that forms part of defaults).

How was it tested?

@mikeland73 mikeland73 requested review from gcurtis and savil May 15, 2024 17:25
Copy link
Collaborator

@gcurtis gcurtis left a comment

Choose a reason for hiding this comment

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

I don't understand why fetchNarInfoStatus ended up calling twice. Did we end up getting different keys for the same installable?

sysInfo, err := p.sysInfoIfExists()
// let's be super safe to always avoid empty key.
if err == nil && sysInfo != nil && len(sysInfo.DefaultOutputs()) > 0 {
output = lo.Reduce(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do the default outputs needed to be sorted to make the key stable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The implementation of DefaultOutputs is pretty stable, but it doesn't hurt.

Comment on lines 122 to 128
output = lo.Reduce(
sysInfo.DefaultOutputs(),
func(acc string, o lock.Output, _ int) string {
return acc + o.Name
},
"",
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could the lo.Reduce be replaced by the following for easier-reading:

return strings.Join(sysInfo.DefaultOutputs(), ",")

?

It would also mean that the key matches the nix-installable-output format of <name>^<output>,<output>,...<output>. It doesn't really need to do this but is ... aesthetically pleasing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

outputs are not strings, but maybe if they have a String() method this will work? will try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't work.

@mikeland73
Copy link
Contributor Author

I don't understand why fetchNarInfoStatus ended up calling twice. Did we end up getting different keys for the same installable?

yeah, we call it once per output and once for __default_output__.

So for a given package with a single (default) output out, we call it twice, once cached under key with out and once with key __default_output__

@mikeland73 mikeland73 merged commit 2285a3e into main May 16, 2024
24 checks passed
@mikeland73 mikeland73 deleted the landau/prevent-double-fetch branch May 16, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants