Repository navigation
Fix/preemption resource copy - #28683
sforster-meteomatics wants to merge 4 commits into
Conversation
| } | ||
| newR := new(ComparableResources) | ||
| *newR = *c | ||
| newR.Flattened = *c.Flattened.Copy() |
There was a problem hiding this comment.
We probably also want to copy shared via c.Shared.Copy().
There was a problem hiding this comment.
I looked at that as well, but it could affect how AllocatedSharedResources.Subtract() works. Since after the deep copy, it wouldn't match the Networks that are actually the same anymore.
https://github.com/hashicorp/nomad/blob/main/nomad/structs/structs.go#L4008-L4025
I'm not sure if anything currently relies on that behaviour, but in any case I didn't want to affect it and keep this change minimal. And the current change with only copying Flattened is enough to fix the bug that I found.
|
Thanks for this contribution! It's worth noting that this |
I can try and measure the performance impact. If it's not too high, it might anyway be worth it to include this fix in an upcoming release, since the long-term fix you shared might take longer to be finished? Of course that's up to the Nomad team though. |
Description
When preemption is enabled for at least one scheduler, the network state can inflate dramatically as available ports are duplicated over and over again, on each evaluation that checks if preempting a lower priority allocation can make a higher priorioity allocation fit.
This happens here since there is no deduplication of the ports:
https://github.com/hashicorp/nomad/blob/main/nomad/structs/structs.go#L2957-L2963
This PR fixes that bug by performing a deep copy on the
Flattenedobject inComparableResources.Let me know if I should change anything about the tests I added. I tried to keep the change itself as minimal as possible, to avoid any unnecessary side effects.
Testing & Reproduction steps
I created a repo with the aid of Codex to reproduce the issue in a docker compose environment.
https://github.com/sforster-meteomatics/nomad-preemption-lab
Links
https://github.com/hashicorp/nomad/blob/main/nomad/structs/structs.go#L2957-L2963
Contributor Checklist
changelog entry using the
make clcommand.ensure regressions will be caught.
and followed the AI usage guide.
Reviewer Checklist
backporting document.
in the majority of situations. The main exceptions are long-lived feature branches or merges where
history should be preserved.
within the public repository.
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
No changes to security controls were performed.