Skip to content

[ISSUE #10582] Fix POP revive offset comparator overflow#10583

Open
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/pop-revive-offset-comparator
Open

[ISSUE #10582] Fix POP revive offset comparator overflow#10583
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/pop-revive-offset-comparator

Conversation

@Aias00

@Aias00 Aias00 commented Jul 2, 2026

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Brief Description

This PR fixes the POP revive checkpoint ordering comparator in PopReviveService.ConsumeReviveObj#genSortList().

The previous implementation subtracted two long reviveOffset values and cast the result to int:

sortList.sort((o1, o2) -> (int) (o1.getReviveOffset() - o2.getReviveOffset()));

When the offset gap is larger than Integer.MAX_VALUE, the cast can overflow and return the wrong ordering. Since the sorted checkpoint list is consumed by mergeAndRevive(), this can cause POP revive checkpoints to be processed out of order.

The comparator now uses Comparator.comparingLong(PopCheckPoint::getReviveOffset) so the full long value is compared safely. A regression test covers two checkpoints whose revive offsets differ by more than Integer.MAX_VALUE.

How Did You Test This Change?

  • mvn -pl broker -Dtest=PopReviveServiceTest test -Dspotbugs.skip=true -Dcheckstyle.skip=true
  • git diff --check

POP revive checkpoints are ordered by reviveOffset before mergeAndRevive advances through the pending checkpoints. The previous comparator subtracted two long offsets and cast the result to int, so large offset gaps could reverse the intended ordering.

Use Comparator.comparingLong to preserve the full long ordering and add a regression test covering offsets separated by more than Integer.MAX_VALUE.

Constraint: reviveOffset is a long queue offset and can exceed int comparison range

Rejected: Keep subtraction with a wider cast | Comparator APIs express the ordering directly and avoid overflow

Confidence: high

Scope-risk: narrow

Directive: Do not compare long queue offsets by subtraction in POP revive ordering

Tested: mvn -pl broker -Dtest=PopReviveServiceTest test -Dspotbugs.skip=true -Dcheckstyle.skip=true

Tested: git diff --check
Copilot AI review requested due to automatic review settings July 2, 2026 15:20

Copilot AI 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.

Pull request overview

Fixes incorrect POP revive checkpoint ordering caused by an overflow-prone comparator in PopReviveService.ConsumeReviveObj#genSortList(), ensuring revive offsets are always sorted by their full long value.

Changes:

  • Replaced (int) (o1.getReviveOffset() - o2.getReviveOffset()) comparator with Comparator.comparingLong(PopCheckPoint::getReviveOffset) to prevent overflow and wrong ordering.
  • Added a regression test covering revive offsets that differ by more than Integer.MAX_VALUE.

Reviewed changes

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

File Description
broker/src/main/java/org/apache/rocketmq/broker/processor/PopReviveService.java Uses a safe long comparator to sort revive checkpoints deterministically without overflow.
broker/src/test/java/org/apache/rocketmq/broker/processor/PopReviveServiceTest.java Adds a regression test that would fail with the old overflow-prone comparator.

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

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.17%. Comparing base (8242c1e) to head (6434cbd).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10583      +/-   ##
=============================================
- Coverage      48.26%   48.17%   -0.10%     
+ Complexity     13433    13411      -22     
=============================================
  Files           1378     1378              
  Lines         100817   100817              
  Branches       13040    13040              
=============================================
- Hits           48660    48564      -96     
- Misses         46211    46292      +81     
- Partials        5946     5961      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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] POP revive checkpoints may be processed out of order due to reviveOffset comparator overflow

3 participants