Skip to content

[SPARK-57498][CORE] Fix ResourceProfile ID collision when custom profile is created before default - #57566

Open
ybapat wants to merge 1 commit into
apache:masterfrom
ybapat:issue-57498-rp-id-collision
Open

[SPARK-57498][CORE] Fix ResourceProfile ID collision when custom profile is created before default#57566
ybapat wants to merge 1 commit into
apache:masterfrom
ybapat:issue-57498-rp-id-collision

Conversation

@ybapat

@ybapat ybapat commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

ResourceProfile.nextProfileId was initialized to new AtomicInteger(0), so the first call to getNextProfileId() returned 0 — which is identical to DEFAULT_RESOURCE_PROFILE_ID. Any custom ResourceProfile created before the default profile was initialized would receive ID 0, colliding with the default profile.

This PR fixes the counter to start at 1, so ID 0 remains exclusively reserved for the default profile.

Changes:

  • Start nextProfileId at 1 instead of 0 in ResourceProfile companion object.
  • Add resetNextProfileIdForTesting() (private[spark]) to enable test isolation without exposing the reset in production code paths.
  • Add afterEach reset call in ResourceProfileSuite to prevent test-order-dependent failures.
  • Add a regression test that creates a custom profile before the default and asserts no ID collision.

Why are the changes needed?

Without this fix, new ResourceProfileBuilder().build() called before ResourceProfile.getOrCreateDefaultProfile() produces a profile with id == 0 == DEFAULT_RESOURCE_PROFILE_ID, which can lead to incorrect resource allocation or scheduling decisions.

Does this PR introduce any user-facing change?

No. The fix only affects internal ID assignment. The default profile always receives ID 0 and custom profiles now always start at ID 1.

How was this patch tested?

  • Existing ResourceProfileSuite passes.
  • New test "custom ResourceProfile id must not collide with DEFAULT_RESOURCE_PROFILE_ID" covers the regression case.

Closes #57498

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

…ile is created before default

Start nextProfileId at 1 instead of 0 to avoid colliding with
DEFAULT_RESOURCE_PROFILE_ID (0). Previously a custom ResourceProfile
created before getOrCreateDefaultProfile() was called would receive
ID 0, indistinguishable from the default profile.

Also reset nextProfileId in clearDefaultProfile() for clean test isolation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CORE] bug report: collision of resource profile id

1 participant