Skip to content

Fix inverted cpuset assignment - #1863

Open
nix-oss wants to merge 1 commit into
apache:mainfrom
nix-oss:fix-cpuset-order
Open

Fix inverted cpuset assignment#1863
nix-oss wants to merge 1 commit into
apache:mainfrom
nix-oss:fix-cpuset-order

Conversation

@nix-oss

@nix-oss nix-oss commented Jul 26, 2026

Copy link
Copy Markdown

Fixes #1862

What does this PR do?

Fix inverted cpuset assignment in getCpuSetByRole(). The function returned the wrong cpuset for coordinator and segment roles when the cpuset string contains a semicolon separator (e.g., "0-7;0-15"). This caused incorrect CPU affinity settings on clusters.

Additionally, this PR addresses the suggestion from the @my-ship-it to return a palloc'd copy instead of a pointer into the caller's string.

A unit test for getCpuSetByRole() is also added to guard against future regressions.

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Test Plan

  • Unit tests added/updated

Impact

Performance:
This fix ensures that CPU cores are assigned to the coordinator and segments exactly as configured by the administrator. It prevents unintended usage of cores that may be reserved for other critical system tasks.

User-facing changes:
Users can now successfully set cpuset strings with a semicolon separator (e.g., ALTER RESOURCE GROUP ... SET CPUSET '4-7;9-17') without receiving a "cpu cores unavailable" error.

Checklist

  • Followed contribution guide
  • Added/updated documentation
  • Reviewed code for security implications
  • This PR contains AI-assisted code generation

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi, @nix-oss welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!

Comment thread src/backend/commands/test/resgroupcmds_test.c
@zhangwenchao-123

zhangwenchao-123 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LGTM, but it's better to squash to one commit and add more commit message. What's more, this change may influence compatibility for greenplum or older cloudberry versions which maybe should be token into consideration.

Previously, the function returned the wrong cpuset for coordinator and
segment roles when the cpuset string contained a semicolon separator
(e.g., "0-7;0-15").

- Coordinator now receives the first part (before ';')
- Segment now receives the second part (after ';')
- Added unit tests covering both branches with different values
- Added Apache license header to the new test file

Fixes apache#1862
@nix-oss
nix-oss force-pushed the fix-cpuset-order branch from 22a76dc to 732832c Compare July 29, 2026 10:56
@nix-oss

nix-oss commented Jul 29, 2026

Copy link
Copy Markdown
Author

Hi @zhangwenchao-123.
Thanks for the approval and the comments! I've squashed the commits into one.

Regarding compatibility — this is indeed an important point. It seems this CPU management mechanism is either not heavily used, or limited to homogeneous environments, which is why this issue went unnoticed for so long.

@zhangwenchao-123

Copy link
Copy Markdown
Contributor

Hi @zhangwenchao-123. Thanks for the approval and the comments! I've squashed the commits into one.

Regarding compatibility — this is indeed an important point. It seems this CPU management mechanism is either not heavily used, or limited to homogeneous environments, which is why this issue went unnoticed for so long.

Thanks for your contribution, LGTM.

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.

[Bug] Incorrect cpuset role assignment in getCpuSetByRole()

3 participants