refactor: throw exception in registerConsumer + lock-free StoreStatsService - #10815
Open
juincen wants to merge 2 commits into
Open
refactor: throw exception in registerConsumer + lock-free StoreStatsService#10815juincen wants to merge 2 commits into
juincen wants to merge 2 commits into
Conversation
…of returning boolean Move the duplicate-group exception throwing from callers into MQClientInstance.registerConsumer() itself, removing redundant if (!registerOK) throw checks in all three consumer implementations.
- Replace volatile long + ReentrantLock for putMessageEntireTimeMax and getMessageEntireTimeMax with AtomicLong.accumulateAndGet, eliminating lock contention in the hot put/get message path. - Replace volatile long dispatchMaxBuffer with AtomicLong to fix a TOCTOU race condition where the max value could be lost under concurrent updates. - Replace string concatenation with chained StringBuilder.append() in toString() for better performance.
RockteMQ-AI
approved these changes
Aug 5, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Summary
Two clean improvements: (1) moves duplicate-group exception throwing into registerConsumer() itself, eliminating redundant throw-after-check patterns in all three consumer implementations; (2) replaces volatile long + ReentrantLock with AtomicLong.accumulateAndGet(Math::max) in StoreStatsService for lock-free max tracking.
Findings
- [Info]
DefaultMQPushConsumerImpl.java— The original code calledconsumeMessageService.shutdown()in the registration-failed error path before throwing. The refactored version removes this since the exception is now thrown insideregisterConsumer()before any service state changes. This is correct behavior (the service was never started), but worth confirming that no caller depends on the shutdown side-effect. - [Info]
StoreStatsService.java:73—AtomicLong.accumulateAndGetwithMath::maxis a good lock-free replacement. Note that under high contention this may spin, but for a stats counter the contention should be low.
LGTM.
Automated review by github-manager-bot
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.
Changes
1. registerConsumer: throw MQClientException instead of returning boolean
Move the duplicate-group exception throwing from callers into
MQClientInstance.registerConsumer()itself, removing redundantif (!registerOK) throwchecks in all three consumer implementations.MQClientInstance.java- throw exception instead of returning falseDefaultMQPushConsumerImpl.java- remove redundant checkDefaultMQPullConsumerImpl.java- remove redundant checkDefaultLitePullConsumerImpl.java- remove redundant check2. StoreStatsService: lock-free AtomicLong for max tracking
Replace
volatile long+ReentrantLockwithAtomicLong.accumulateAndGet()for thread-safe max-value tracking on the hot message path.putMessageEntireTimeMax/getMessageEntireTimeMax— eliminate lock contention in hot put/get pathdispatchMaxBuffer— fix TOCTOU race condition in volatile read-modify-writetoString()— chainedStringBuilder.append()instead of string concatenation