[Bug] ProcessQueue may return a stale next offset for out-of-order messages
- Dominant language
- Java
- Stars
- 22.6k
- Forks
- 12k
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 27
Description
### Before Creating the Bug Report
- [x] I found a bug, not just a question.
- [x] I searched open GitHub Issues and pull requests and found no duplicate.
- [x] I confirmed that this bug belongs to Apache RocketMQ.
### Runtime platform environment
macOS (Darwin), reproduced with an isolated local unit test.
### RocketMQ version
Branch: develop
Git commit: fd0c95920e0deac96ce2ae27442747cc5e65e930
### JDK Version
Zulu OpenJDK 8 (8.94.0.17)
### Describe the Bug
ProcessQueue.putMessage assigns queueOffsetMax from each newly inserted message. When a batch is not ordered by queue offset, a lower offset processed last overwrites the real maximum. After the queue is drained, removeMessage therefore returns a stale next offset.
### Steps to Reproduce
1. Create a ProcessQueue.
2. Insert two messages in one batch with queue offsets 10 and 5, in that order.
3. Remove both messages.
4. Observe that the returned next offset is 6.
### What Did You Expect to See?
The returned next offset should be 11, one greater than the highest offset ever inserted.
### What Did You See Instead?
The returned next offset is based on the last iterated message rather than the maximum queue offset.
### Additional Context
The issue is deterministic and is covered by ProcessQueueTest.
Contributor guide
Research direction
Start by reading ProcessQueue.putMessage and removeMessage, then run the isolated ProcessQueueTest mentioned in the report. Reproduce the batch with queue offsets 10 and 5, and confirm that draining it returns 11 rather than 6; the existing test should pass with the corrected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100