Skip to content

scheduler: normalize node affinity by the larger of the pos/neg weight sums - #28500

Open
larrasket wants to merge 1 commit into
hashicorp:mainfrom
larrasket:fix-11130-affinity-range-squash
Open

scheduler: normalize node affinity by the larger of the pos/neg weight sums#28500
larrasket wants to merge 1 commit into
hashicorp:mainfrom
larrasket:fix-11130-affinity-range-squash

Conversation

@larrasket

@larrasket larrasket commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

NodeAffinityIterator normalized a node's affinity score by the sum of the absolute value of every affinity weight. When a job mixed positive and negative weights, an anti-affinity on one node inflated the denominator for an unrelated node that only matched a positive affinity (and vice versa), the score does not reached the [-1, 1] range.

For example a +100 affinity on node A plus a -100 anti-affinity on node B scored node A at 0.5 instead of 1.0.

This divides by the larger of the total positive weight and the total negative weight instead. This restores the range while still keeping scores within [-1, 1], since the matched total is bounded by the positive sum above and the negative sum below.

Testing & Reproduction steps

Links

Fixes #11130

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad product documentation, which is stored in the
    web-unified-docs repo. Refer to the web-unified-docs contributor guide for docs guidelines.
    Please also consider whether the change requires notes within the upgrade
    guide
    . If you would like help with the docs, tag the nomad-docs team in this PR.
  • LLM Usage If an LLM was used to generate any code, please ensure and confirm you have read
    and followed the AI usage guide.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.
  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

…t sums

NodeAffinityIterator normalized a node's affinity score by the sum of the
absolute value of every affinity weight. When a job mixed positive and
negative weights, an anti-affinity on one node inflated the denominator for
an unrelated node that only matched a positive affinity (and vice versa),
so the score never reached the full [-1, 1] range. For example a +100
affinity on node A plus a -100 anti-affinity on node B scored node A at
0.5 instead of 1.0.

Divide by the larger of the total positive weight and the total negative
weight instead. This restores the full range while still keeping every
score within [-1, 1], since the matched total is bounded by the positive
sum above and the negative sum below.

Fixes hashicorp#11130

Signed-off-by: Saleh <root@lr0.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Node affinity range is squashed when mixing positive and negative weights

2 participants