[ISSUE #10688] Skip malformed ordered route items - #10689
Conversation
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Defensive fix for MessageQueueSelector.buildWrite: validates each ordered route fragment (broker:count format) before parsing, skips malformed entries with a warning. Also fixes a potential NPE in TopicRouteWrapper.getMasterAddr when brokerData is null. Includes tests.
Findings
-
[Info]
proxy/src/main/java/org/apache/rocketmq/proxy/service/route/MessageQueueSelector.java:118-120— The validation checksitem.length != 2and blank segments, which is good. Consider also logging thetopicRoute.getTopicName()in theNumberFormatExceptioncatch block (it is already included — confirmed). -
[Info]
proxy/src/main/java/org/apache/rocketmq/proxy/service/route/TopicRouteWrapper.java— The NPE guard ingetMasterAddr(if (brokerData == null) return null) is a good complementary fix. Without it, a malformed route entry could cause a NPE downstream even if the format check passes. -
[Info] Test coverage in
MessageQueueSelectorTestlooks solid — tests valid input, wrong segment count, blank broker name, blank queue count, and non-numeric queue count.
Overall
Well-structured defensive fix with two layers of protection (format validation + NumberFormatException catch). The NPE guard in TopicRouteWrapper is a good catch. LGTM.
Automated review by github-manager-bot
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #10689 +/- ##
=============================================
- Coverage 48.31% 48.25% -0.07%
+ Complexity 13511 13498 -13
=============================================
Files 1380 1380
Lines 101091 101116 +25
Branches 13101 13105 +4
=============================================
- Hits 48844 48795 -49
- Misses 46285 46337 +52
- Partials 5962 5984 +22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Suggestion: consider changing
The third point is important because Please also add regression tests asserting that an unknown broker produces |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review)
PR #10689: [ISSUE #10688] Skip malformed ordered route items
Re-review scope: New commits 31dd11b ("Make missing master broker address explicit") and 9c1a41e ("Trigger CI rerun")
Changes Since Last Review
TopicRouteWrapper.getMasterAddr()now returnsOptional<String>instead of rawString— this is a stronger API contract that makes the "broker not found" case explicit at the call siteClusterTopicRouteService.getBrokerAddr()updated to use.orElseThrow()with a descriptiveProxyException- Other callers updated to handle the
Optionalreturn properly
Assessment
Correctness — The Optional<String> return type is a clean improvement over the previous null-returning approach. Callers are forced to handle the missing-broker case explicitly.
Compatibility — TopicRouteWrapper.getMasterAddr() is an internal API (proxy module), so the signature change is contained.
Tests — Existing tests cover the route selection logic; the Optional migration is straightforward.
Overall: LGTM — Good evolution of the null-safety pattern.
Automated re-review by github-manager-bot
|
The validation direction looks useful, but I think a few compatibility and resource-safety cases should be addressed before merging.
Please add regression coverage for zero, negative, |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review)
PR #10689: [ISSUE #10688] Skip malformed ordered route items
Re-review trigger: New maintainer feedback from @fuyou001 (2026-07-30)
Maintainer Feedback Summary
@fuyou001 raised three concerns:
-
[Compatibility]
TopicRouteWrapper.getMasterAddrchanges its public return type fromStringtoOptional<String>. This is source- and binary-incompatible for external extensions compiled against the proxy module. -
[Correctness/Resource Safety] Queue count is only checked for integer syntax. A negative value silently produces no queues; a very large positive value can allocate many
AddressableMessageQueueobjects during route refresh. -
[Consistency] Partially accepting a damaged ordered-topic configuration changes the ordered queue set. Confirm whether partial acceptance is the desired policy; otherwise rejecting the whole configuration and retaining the last valid route would prevent different nodes from constructing different queue views during mixed-version operation.
Assessment
All three concerns are valid:
-
Binary compatibility: Changing
String→Optional<String>breaks any external code compiled against the old signature. UnlessTopicRouteWrapperis explicitly internal, consider retaining the existing method and adding a newOptional<String> getOptionalMasterAddr(...)or similar. -
Queue count bounds: The
parseQueueCountmethod validates integer syntax but not range. A negative count orInteger.MAX_VALUEcould cause silent data loss or OOM during route refresh. Suggest enforcing1 <= count <= reasonable_upper_bound(e.g., 512 or whatever RocketMQ's documented queue limit is). -
Partial acceptance policy: This is a design decision that the author should explicitly confirm. If partial acceptance is intentional, document it. If not, reject the entire configuration on any validation failure.
Additional Note
The ClusterTopicRouteService.getBrokerAddr change to throw ProxyException on missing broker is a positive improvement — it prevents null addresses from reaching the remoting client. However, as @fuyou001 noted, please verify that the exception is correctly mapped through all callers (ConsumerProcessor, ClusterMessageService, buildAddressableMessageQueue, background fault-strategy callback).
Status
No new commits since the maintainer feedback. Awaiting author response.
Automated review by github-manager-bot
|
Addressed the latest feedback in commit |
|
Added one more regression commit for the exceptional future propagation part of the review feedback. New coverage in
Both tests verify the propagated Local verification with JDK 8: Result: |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review after new commits)
PR #10689: [ISSUE #10688] Skip malformed ordered route items
Re-review trigger: New commits pushed on Jul 31 (after previous review on Jul 31 00:37)
Previous Concerns Resolution
The previous review raised three concerns:
1. Binary Compatibility (getMasterAddr → getOptionalMasterAddr)
✅ Resolved. getMasterAddr(String) is preserved and delegates to getOptionalMasterAddr. The new getOptionalMasterAddr returns Optional<String>. This is backward compatible — existing callers of getMasterAddr are unaffected.
2. Queue Count Bounds Validation
✅ Resolved. parseOrderTopicQueueCount now validates range [1, MAX_ORDER_TOPIC_WRITE_QUEUE_COUNT] where MAX_ORDER_TOPIC_WRITE_QUEUE_COUNT = 1024. Invalid values (0, negative, >1024, overflow) are rejected with a warning log.
3. Partial Acceptance Policy
✅ Resolved. Invalid ordered route items are skipped with log.warn and continue. Valid items are processed normally. This is the correct approach — malformed fragments no longer crash the entire route building.
Code Quality
- API design: Clean separation — old API preserved, new Optional-based API added ✓
- Error handling:
ClusterTopicRouteService.getBrokerAddrthrowsProxyException(INVALID_BROKER_NAME)for unknown brokers ✓ - Bounds validation: Queue count range is reasonable (1-1024) ✓
- Logging: Warning logs for skipped items aid diagnostics ✓
- Tests: Comprehensive coverage including malformed fragments, invalid queue counts, and Integer overflow ✓
Verdict
Approve. All three previous concerns are fully addressed with clean, backward-compatible changes.
Which Issue(s) This PR Fixes
Fixes #10688
Brief Description
MessageQueueSelector.buildWritepreviously assumed every ordered route fragment fromorderTopicConfused a validbrokerName:queueNumformat. Malformed fragments could throwArrayIndexOutOfBoundsExceptionorNumberFormatException, and unknown broker names could makeTopicRouteWrapper.getMasterAddrthrow before the selector's null check could skip them.This PR validates each ordered route fragment before using it, skips malformed entries with a warning, and makes
TopicRouteWrapper.getMasterAddrreturnnullfor unknown brokers so existing skip logic works as intended. Valid ordered route entries keep the existing behavior.How Did You Test This Change?
mvn -pl proxy -Dtest=MessageQueueSelectorTest -DfailIfNoTests=false testResult:
BUILD SUCCESS,Tests run: 3, Failures: 0, Errors: 0, Skipped: 0.