Skip to content

Proposal: feat(capacity) ancestor reclaim level#5115

Open
hajnalmt wants to merge 5 commits intovolcano-sh:masterfrom
hajnalmt:feat/capacity-ancestor-reclaim-level
Open

Proposal: feat(capacity) ancestor reclaim level#5115
hajnalmt wants to merge 5 commits intovolcano-sh:masterfrom
hajnalmt:feat/capacity-ancestor-reclaim-level

Conversation

@hajnalmt
Copy link
Contributor

@hajnalmt hajnalmt commented Mar 17, 2026

What type of PR is this?

/kind feature
/area scheduling

What this PR does / why we need it:

This PR mainly ports and adapts #5111 from parent-based reclaim semantics to ancestorReclaimLevel in the capacity plugin.

From design perspective only one shall be merged from:

This PR adds ancestorReclaimLevel configuration to support ancestor-based reclaim behavior in hierarchical queues, so child queues can reclaim borrowed resources through configured parent/grandparent ancestor constraints.

It also updates ReclaimableFn victim processing to use BuildVictimsPriorityQueue, aligning reclaim victim selection with scheduler victim-ordering semantics.

Additionally, it adapts hierarchical reclaim test scenarios to run with ancestorReclaimLevel=1, adds unbalanced level-2 regression coverage, and updates documentation for sibling/cousin/second-cousin reclaim interactions.

Which issue(s) this PR fixes:

Fixes #5107

Special notes for your reviewer:

  • Prerequisite victim-selection commits (from enhancement(victim selection): improve same job-priority victim selection #5113) are required here for reliable test pass (reclaimee selection will be consistent with it):
    • 6200ee793 — enhancement(victim selection): add job ordering tie-break with task order
    • 9d98e3a21 — test(victim selection): add tie-break coverage in framework_test package
    • fdc34f9b3 — test(victim selection): strengthen tie-break proof and update docs
  • Commits are split by scope:
    • code/tests: 64b637277
    • docs: 216281582
  • AI usage disclosure:
    • This PR is heavily AI-written, then thoroughly hammered and refined for correctness and quality.
    • Rhyme:
      Volcano wakes where hot clouds swirl,
      Queues reclaim in a steady curl;
      Ancestors guide the fairness flow,
      So borrowed sparks return and glow.

Does this PR introduce a user-facing change?

feat(capacity): add ancestorReclaimLevel to control ancestor-based reclaim behavior in hierarchical queues

…rder

Apply plugin job CompareFn first in BuildVictimsPriorityQueue and use
TaskOrderFn as the tie-breaker when job ordering is equal, including
preemptor-missing paths, so creation timestamp does not dominate
same-priority victim selection.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Add BuildVictimsPriorityQueue unit coverage for job-order ties falling back
to task-order, including preemptor-found and preemptor-missing paths.

Place the test in package framework_test so it can use real plugin wiring
without creating an import cycle between framework and plugin packages.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Set deterministic PodGroup creation timestamps and assert
JobOrderCompareFn tie conditions so task-order fallback behavior is
validated consistently.

Update BuildVictimsPriorityQueue comments to match current ordering
paths, including orphaned jobs and queue-based handling.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Add ancestorReclaimLevel configuration to support ancestor-based reclaim scenarios across hierarchical queues.

Enable child queues to reclaim borrowed resources through configured ancestor levels and add hierarchical level-1 and unbalanced level-2 regression coverage.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Document ancestorReclaimLevel configuration and explain reclaim behavior across sibling, cousin, and deeper ancestor relationships in hierarchical queues.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Copilot AI review requested due to automatic review settings March 17, 2026 00:23
@volcano-sh-bot volcano-sh-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 17, 2026
@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign shinytang6 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 17, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the resource reclaim capabilities within the capacity plugin for hierarchical queues. It provides operators with finer-grained control over reclaim boundaries by introducing an ancestorReclaimLevel argument, which dictates how far up the queue hierarchy reclaim checks are performed. Concurrently, the underlying victim selection mechanism has been refined to ensure consistent and predictable behavior during preemption, improving the overall fairness and efficiency of resource allocation in complex queue structures.

Highlights

  • Ancestor-based Reclaim Control: Introduced ancestorReclaimLevel configuration in the capacity plugin to control the scope of resource reclaim in hierarchical queues, allowing child queues to reclaim borrowed resources based on parent/grandparent ancestor constraints.
  • Enhanced Victim Selection Logic: Updated ReclaimableFn victim processing to utilize BuildVictimsPriorityQueue, ensuring reclaim victim selection aligns with the scheduler's victim-ordering semantics, including job ordering tie-breaks.
  • Expanded Test Coverage and Documentation: Adapted existing hierarchical reclaim test scenarios to include ancestorReclaimLevel=1, added new regression coverage for unbalanced level-2 hierarchies, and updated documentation to explain sibling, cousin, and second-cousin reclaim interactions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • docs/design/hierarchical-queue-on-capacity-plugin.md
    • Added a new section detailing 'Reclaim scope control' with ancestorReclaimLevel and examples of its interaction with sibling, cousin, and second-cousin queues.
  • docs/user-guide/how_to_use_capacity_plugin.md
    • Updated the capacity plugin configuration example to include the ancestorReclaimLevel argument.
    • Added a new section explaining the behavior and impact of ancestorReclaimLevel for different values (0, 1, 2, N) on reclaim scope.
  • pkg/scheduler/framework/session_plugins.go
    • Refactored JobOrderFn into a new JobOrderCompareFn that returns an integer comparison result, allowing for more flexible job ordering.
    • Modified JobOrderFn to use the new JobOrderCompareFn for job comparison.
    • Updated BuildVictimsPriorityQueue to incorporate JobOrderCompareFn for victim sorting, including a jobThenTaskOrder helper function for tie-breaking.
  • pkg/scheduler/framework/session_plugins_victim_order_test.go
    • Added a new test file to include TestBuildVictimsPriorityQueueJobTieBreaksWithTaskOrder to verify job ordering tie-breaking logic in victim selection.
  • pkg/scheduler/plugins/capacity/capacity.go
    • Added ancestorReclaimLevelKey constant and ancestorReclaimLevel field to the capacityPlugin struct.
    • Initialized ancestorReclaimLevel to 0 in the New function.
    • Introduced parseArguments method to read and validate the ancestorReclaimLevel from plugin arguments.
    • Integrated parseArguments into OnSessionOpen to configure the reclaim level.
    • Modified the ReclaimableFn logic within OnSessionOpen to use ssn.BuildVictimsPriorityQueue for victim selection.
    • Implemented ancestor-based reclaim checks within ReclaimableFn, applying deserved checks at specified ancestor levels based on ancestorReclaimLevel.
    • Added helper functions getReclaimeeAncestorToCheck and queueAncestorAtDepth to facilitate hierarchical ancestor traversal and checks.
  • pkg/scheduler/plugins/capacity/capacity_test.go
    • Imported the priority plugin for enhanced testing scenarios.
    • Updated Test_capacityPlugin_OnSessionOpenWithHierarchy to include the priority.PluginName in the plugin builder map and added several new test cases (case13, case14, case15, case16) to cover ancestorReclaimLevel=1 scenarios.
    • Added Test_capacityPlugin_AncestorReclaimLevel to test reclaim behavior with different ancestorReclaimLevel values (0, 1, 2).
    • Added Test_capacityPlugin_AncestorReclaimLevel2UnbalancedHierarchy to specifically test reclaim behavior in unbalanced hierarchical queue structures at level 2.
Activity
  • The pull request ports and adapts existing parent-based reclaim semantics to ancestorReclaimLevel in the capacity plugin.
  • Prerequisite victim-selection commits (6200ee7, 9d98e3a, fdc34f9) from another PR (enhancement(victim selection): improve same job-priority victim selection #5113) are noted as required for reliable test passes.
  • Commits are split by scope, with code/tests in 64b637277 and docs in 216281582.
  • The author disclosed that the PR was heavily AI-written and then thoroughly refined for correctness and quality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds ancestorReclaimLevel configuration to the capacity plugin, enabling ancestor-based deserved checks during hierarchical queue reclaim. It also refactors victim selection to use BuildVictimsPriorityQueue and improves job-order tie-breaking with task order.

Changes:

  • Add ancestorReclaimLevel argument to capacity plugin controlling how many ancestor levels are checked before cross-hierarchy reclaim is allowed
  • Refactor BuildVictimsPriorityQueue to use JobOrderCompareFn with task-order tie-breaking, and use it in ReclaimableFn
  • Add tests for ancestor reclaim levels 0/1/2 and unbalanced hierarchy, plus documentation updates

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/scheduler/plugins/capacity/capacity.go Add ancestorReclaimLevel field, argument parsing, ancestor checks in ReclaimableFn and PreemptiveFn
pkg/scheduler/framework/session_plugins.go Extract JobOrderCompareFn, add task-order tie-break in BuildVictimsPriorityQueue
pkg/scheduler/framework/session_plugins_victim_order_test.go Test coverage for victim priority queue tie-breaking
pkg/scheduler/plugins/capacity/capacity_test.go Test cases for ancestor reclaim levels and unbalanced hierarchy
docs/user-guide/how_to_use_capacity_plugin.md Document ancestorReclaimLevel usage
docs/design/hierarchical-queue-on-capacity-plugin.md Document reclaim scope control design

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +51 to +52
# 1: only queues with the same parent
# 2: also allows same grandparent (and so on for larger values)

Interaction examples in a hierarchy:

- Siblings (same direct parent): reclaim is decided by leaf queue checks, and when `ancestorReclaimLevel >= 1`, parent-level deserved checks are also applied when siblings cross parent boundaries in deeper trees.
@hajnalmt hajnalmt changed the title proposal: feat(capacity) ancestor reclaim level Proposal: feat(capacity) ancestor reclaim level Mar 17, 2026
Copy link

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

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 introduces a significant and valuable feature, ancestorReclaimLevel, to provide more granular control over resource reclamation in hierarchical queues. The changes are well-structured, encompassing logic modifications in the capacity plugin, refactoring of core scheduler functions for better victim selection, comprehensive new test cases, and updated documentation. The implementation appears solid and the added tests provide good coverage for the new functionality. My feedback primarily focuses on improving the clarity and accuracy of the documentation to ensure users can correctly understand and utilize this new feature.


Interaction examples in a hierarchy:

- Siblings (same direct parent): reclaim is decided by leaf queue checks, and when `ancestorReclaimLevel >= 1`, parent-level deserved checks are also applied when siblings cross parent boundaries in deeper trees.

Choose a reason for hiding this comment

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

medium

The description for sibling reclaim could be clearer. By definition, siblings share the same direct parent, so they cannot "cross parent boundaries". The parent-level check is skipped for them because they have a common parent at level=1. The current phrasing might cause confusion.

Suggested change
- Siblings (same direct parent): reclaim is decided by leaf queue checks, and when `ancestorReclaimLevel >= 1`, parent-level deserved checks are also applied when siblings cross parent boundaries in deeper trees.
- Siblings (same direct parent): Reclaim is primarily decided by leaf-queue deserved checks. The ancestor check at `level=1` is skipped because they share the same parent.

arguments:
# Controls how far reclaim can cross queue hierarchy boundaries.
# 0: no ancestor restriction (default behavior)
# 1: only queues with the same parent

Choose a reason for hiding this comment

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

medium

The comment for ancestorReclaimLevel: 1 is misleading. It states it's for "only queues with the same parent", which implies it only affects siblings. However, this setting primarily controls cross-parent (e.g., cousin) reclaim by adding a parent-level deserved check.

Suggested change
# 1: only queues with the same parent
# 1: adds parent-level deserved checks for cross-parent reclaim (e.g., between cousins).

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

Labels

area/scheduling kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hierarchical Queue Reclaim logic lacks recursive parent-level deserved check in capacity plugin

3 participants