Skip to content

[core][scheduler] Honor node label constraints when the local node is preferred - #68610

Open
RocMarshal wants to merge 1 commit into
ray-project:masterfrom
RocMarshal:newfix___
Open

RocMarshal wants to merge 1 commit into
ray-project:masterfrom
RocMarshal:newfix___

Conversation

@RocMarshal

Copy link
Copy Markdown
Contributor

Description

When the local node is preferred, the lease scheduler can select it without
evaluating NodeLabelSchedulingStrategy. For example, a lease requiring
region=us-west can be assigned to the local us-east node.

Skip both local preference shortcuts for leases using this strategy: immediate
placement on an available local node and fallback to waiting on the local node.
The regression test covers an available local node and the case where both nodes
are busy, with only the remote node matching the hard label in both cases.

Related issues

No issues.

Additional information

N.A

@RocMarshal
RocMarshal requested a review from a team as a code owner November 27, 2026 10:13

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that the local node preference shortcut in the cluster resource scheduler is bypassed when a node label scheduling strategy is present, and adds a corresponding unit test. The feedback suggests further expanding this bypass logic to also exclude other non-default scheduling strategies, such as NodeAffinitySchedulingStrategy and SpreadSchedulingStrategy, to prevent incorrect scheduling that violates affinity constraints or defeats spread behavior.

Comment on lines +273 to +275
const bool prefer_local_node =
preferred_node_id == local_node_id_.Binary() &&
!scheduling_strategy.has_node_label_scheduling_strategy();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The local preference shortcut bypasses the full scheduling policy to immediately schedule the lease on the local node if resources are available. While this is a great optimization for the default/hybrid policy, it should also be skipped for other non-default scheduling strategies like NodeAffinitySchedulingStrategy (especially with hard affinity constraints) and SpreadSchedulingStrategy.\n\nIf a lease has a hard node affinity to a remote node, but the local node is preferred (e.g., as a fallback or default preferred node), the shortcut would incorrectly schedule it on the local node, violating the affinity constraint. Similarly, for spread scheduling, always scheduling locally when the local node is preferred defeats the spread behavior.\n\nWe should expand prefer_local_node to exclude these strategies as well.

  const bool prefer_local_node =\n      preferred_node_id == local_node_id_.Binary() &&\n      !scheduling_strategy.has_node_label_scheduling_strategy() &&\n      !scheduling_strategy.has_node_affinity_scheduling_strategy() &&\n      scheduling_strategy.scheduling_strategy_case() !=\n          rpc::SchedulingStrategy::SchedulingStrategyCase::kSpreadSchedulingStrategy;

@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant