[ISSUE #10849] Fix static topic epoch sort overflow - #11186
Open
beautyarbutin wants to merge 1 commit into
Open
beautyarbutin wants to merge 1 commit into
beautyarbutin wants to merge 1 commit into
Conversation
RockteMQ-AI
reviewed
Sep 21, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Summary
Fixes integer overflow in epoch comparators used for static topic routing. The old (int)(o2.getEpoch() - o1.getEpoch()) pattern silently reverses sort order when the epoch delta exceeds Integer.MAX_VALUE. Replaced with Long.compare() in both TopicQueueMappingUtils and ClientMetadata.
Findings
- [Critical] This is a correctness bug — in long-running clusters, epoch values can diverge enough to cause the comparator to return wrong ordering, potentially routing messages to stale brokers. Good fix.
- [Info] Tests use
Long.MAX_VALUEvs0as the extreme case, which correctly reproduces the overflow. Both test classes cover the respective comparator paths.
Overall
Minimal, correct fix with proper regression tests. LGTM.
Automated review by RockteMQ-AI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
Brief Description
Static-topic epoch comparators in
TopicQueueMappingUtilsandClientMetadatasubtracted twolongvalues and narrowed the result toint. Epoch deltas larger thanInteger.MAX_VALUEcould therefore reverse the intended newest-first order.This change uses
Long.comparein both ordering paths. It adds regression coverage for replacement mode selecting the latest broker mapping across the full positivelongrange and for client endpoint construction retaining the latest broker.How Did You Test This Change?
latestbut receivedstale.mvn -pl remoting -am -DskipITs -Dtest=TopicQueueMappingUtilsTest,ClientMetadataTest -Dsurefire.failIfNoSpecifiedTests=false test.