Skip to content

[core] Start channel should not be negative when partition.hashCode() equals to Integer.MIN_VALUE - #5623

Merged
JingsongLi merged 2 commits into
apache:masterfrom
tsreaper:abs
May 19, 2025
Merged

JingsongLi merged 2 commits into
apache:masterfrom
tsreaper:abs

Conversation

@tsreaper

Copy link
Copy Markdown
Contributor

Purpose

Currently in ChannelComputer, if partition.hashCode() equals to Integer.MIN_VALUE, the resulting channel will also be negative. This PR fixes the issue.

Tests

None.

API and Format

No format changes.

Documentation

No new feature.

// Math.abs will still return Integer.MIN_VALUE,
// and this formula will produce a negative integer.
// So we specially handle this case above.
return Math.abs(hashCode) % numChannels;

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.

Add a test for this.

@JingsongLi

Copy link
Copy Markdown
Contributor

+1

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.

2 participants