Repository navigation
[Fix][E2E] Retry and route-guard the remaining RocketMqIT offset reads - #12392
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
Hi @SEPURI-SAI-KRISHNA, thank you for the follow-up, and for keeping this scoped to the two items we recorded as non-blocking on #12323. The PR body is unusually honest about what is demonstrated and what is only latent, which made this much easier to review. I read the whole diff against the current dev, walked every offset read and every topic-creating call in RocketMqIT at the head commit, and cross-checked the two sibling PRs. I found no blocking issue. I do have a few precision points that I think are worth fixing while you are in here, mostly about comments that claim slightly more than the code delivers.
What Problem Does This PR Solve?
Two small robustness gaps in RocketMqIT (test-only, one file):
- In
getRocketMqConsumerData, theoffsetTopicslookup is wrapped inRetryUtils.retryWithExceptionbut thecurrentOffsetscall right below it is not. checkOffsetNoDiffreads broker metadata under a 30 second Awaitility window, the tightest window in the file, with no route confirmation first.
Before: an unwrapped currentOffsets call fails the test on the first RocketMqConnectorException, and checkOffsetNoDiff starts its 30 second clock without knowing whether the topic route is visible.
After: currentOffsets gets the same RetryMaterial as its neighbour, and checkOffsetNoDiff calls the existing waitForTopicRoute(topicName) before entering the window.
1. Code Change Review
1.1 Core Logic Analysis
Two hunks, both in seatunnel-e2e/seatunnel-connector-v2-e2e/connector-rocketmq-e2e/src/test/java/org/apache/seatunnel/e2e/connector/rocketmq/RocketMqIT.java:
Hunk 1, getRocketMqConsumerData (lines 536-550 at head):
// before
Map<MessageQueue, Long> currentOffsets =
RocketMqAdminUtil.currentOffsets(newConfiguration(), Lists.newArrayList(topicName), queueOffsets.keySet());
// after
Map<MessageQueue, Long> currentOffsets =
RetryUtils.retryWithException(
() -> RocketMqAdminUtil.currentOffsets(newConfiguration(), Lists.newArrayList(topicName), queueOffsets.keySet()),
new RetryUtils.RetryMaterial(Constant.OPERATION_RETRY_TIME, false,
exception -> exception instanceof RocketMqConnectorException, Constant.OPERATION_RETRY_SLEEP));Hunk 2, checkOffsetNoDiff (line 638): one added waitForTopicRoute(topicName); before the Awaitility.await() block. The 30 second window itself is unchanged.
Key findings:
- The retry is bounded:
Constant.OPERATION_RETRY_TIME = 30andOPERATION_RETRY_SLEEP = 2000(seatunnel-engine/seatunnel-engine-common/src/main/java/org/apache/seatunnel/engine/common/Constant.java:40-42), so at most 30 attempts with a fixed 2 second backoff, roughly 60 seconds of sleep plus per-call time. No unbounded loop, no hardThread.sleepin test code. - The retry predicate is narrow (
RocketMqConnectorExceptiononly), which is the right exception forRocketMqAdminUtil.currentOffsets(seatunnel-connectors-v2/connector-rocketmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rocketmq/common/RocketMqAdminUtil.java:298-312). - The route guard reuses the existing helper and is idempotent for an already-created topic.
waitForTopicRouteis already used after jobs stop in the restore test (RocketMqIT.java:775,:795-796), so calling it after the job incheckOffsetNoDifffollows an established pattern and does not touch consumer offsets. - On the normal user path: this is test-only, so no production path is touched. Within the test, both hunks run on the mainline path of
testSinkRocketMq,testTextFormatSinkRocketMq,testSinkRocketMqMessageTagandtestSourceRocketMqTextToConsoleWithOffsetCheck, not only on a recovery path. - Correctness caveats are in Issues 1 to 3 below: what happens when the retry is exhausted, what the retry can actually catch on today's
dev, and which route the new guard really confirms.
Runtime path (retry hunk), as it behaves on the reviewed base:
getRocketMqConsumerData(topic)
-> offsetTopics(...) [retry, RocketMqConnectorException only]
-> currentOffsets(...) [now the same retry]
RocketMqAdminUtil.currentOffsets -> examineConsumeStats(group, topic)
MQClientException TOPIC_NOT_EXIST -> returns emptyMap (NOT retried, RocketMqAdminUtil.java:302-305)
other MQClientException/Remoting/Broker/Interrupted -> RocketMqConnectorException -> retried
-> retries exhausted with shouldThrowException=false -> RetryUtils returns null (RetryUtils.java:74-79)
-> currentOffsets.containsKey(mq) NPE (RocketMqIT.java:553) -> catch (Exception) -> RuntimeException(NPE) (RocketMqIT.java:582-583)
1.2 Compatibility Impact
Fully compatible. Test-only change in one E2E class; no production code, options, defaults, SPI or docs are touched. I checked the merge with the two sibling PRs (see 3.2): no textual conflict.
1.3 Performance / Side-Effect Analysis
- Worst-case added test time is bounded: retry at most about 60 seconds of backoff plus call time, and the route guard at most 1 minute (
RocketMqIT.java:487). Neither fires on a healthy broker. - Each retry attempt starts and shuts down its own admin client inside
RocketMqAdminUtil.currentOffsets(finallyatRocketMqAdminUtil.java:313-317), so no client leaks across attempts. waitForTopicRouteissuesproducer.createTopic(...)on an existing topic with the same queue count it was created with. That is idempotent and does not reset committed offsets; it is the same call the restore test already makes after the job stops.
1.4 Error Handling and Logging
Issue 1: Retry exhaustion turns the real failure into a bare NullPointerException
- Location:
RocketMqIT.java:539-550(new), same pattern already at:524-534and:873-883; behaviour defined inseatunnel-common/src/main/java/org/apache/seatunnel/common/utils/RetryUtils.java:51-56and:74-79 - Problem description: the new call passes
shouldThrowException = false. InRetryUtils.retryWithException, when all attempts fail and that flag is false, the method returnsnulland drops the last exception. Here thatnullis dereferenced atRocketMqIT.java:553(currentOffsets.containsKey(mq)), and the surroundingcatch (Exception ex)at:582-583rethrows it asRuntimeException(NullPointerException). The diagnostic that would have told a maintainer what actually failed (theRocketMqConnectorExceptionand its cause) is discarded. The same flag also means a non-retriable exception (predicate false) is not rethrown;RetryUtils.java:51-55simply falls through and the loop re-executes it immediately, up to 30 times with no sleep, before returning null. - Potential risk: this cannot turn a real failure into a pass, so it is not a correctness hole. But it converts an immediately readable failure into a roughly 60 second stall followed by an opaque NPE, which is exactly what makes a flaky E2E expensive to triage in CI logs.
- Best improvement: for the new call, pass
trueforshouldThrowException.RetryUtils.java:52-54then rethrows a non-retriable exception at once and:74-78throws with the last exception as the cause after exhaustion. Ideally apply the same one-word change to the neighbouringoffsetTopicsretry at:530-534(and:879-883) so the three copies stay consistent, or leave those two untouched and mention it in the description. - Severity: Medium
- Raised by another reviewer: No
Issue 2: The comment and PR text state as fact a behaviour that is not on dev yet
- Location:
RocketMqIT.java:536-538; PR description ("This matters more since #12349") - Problem description: the new comment says
currentOffsets"now surfaces such a failure as RocketMqConnectorException rather than an empty map". On the reviewed base that is not true.RocketMqAdminUtil.java:302-305still returnsCollections.emptyMap()forResponseCode.TOPIC_NOT_EXIST, and #12349, which changes that, is still open and unmerged. The route-gap error you are worried about (the name server has no route, code 17) therefore comes back as an empty map today, is not an exception, and is not retried by this wrapper. The retry as written can only catch the other failure classes (broker, remoting, timeout, interrupted) until #12349 lands. - Potential risk: a future reader trusts the comment, believes route gaps are covered by this retry, and either removes a needed guard or misdiagnoses a failure. It also means the practical benefit of hunk 1 depends on merge order, which the description does not state precisely.
- Best improvement: reword the comment to what is true on
dev, for example "retried on the same terms as the offsetTopics lookup above; a lookup failure that surfaces as RocketMqConnectorException is retried", and avoid citing a PR number in code. In the PR description, state that the retry only covers route gaps once #12349 is merged, and note the merge-order dependency (merging this first is harmless, it is just a partial no-op for that case). - Severity: Medium
- Raised by another reviewer: No
Issue 3: The new route guard confirms the wrong route for currentOffsets, and its ceiling is shorter than the gap it cites
- Location:
RocketMqIT.java:635-638(new comment and call),waitForTopicRouteat:484-513(ceiling at:487),currentOffsetsread at:650-652 - Problem description: two related points.
- (a)
waitForTopicRoute(topicName)proves the route oftopicNameis visible, which is whatRocketMqAdminUtil.offsetTopicsneeds (examineTopicStats(topic)resolvestopic). ButRocketMqAdminUtil.currentOffsetscallsexamineConsumeStats(groupId, topic), and in rocketmq-tools 4.9.4 that method resolves its route from the group's retry topic, not from the requested topic:DefaultMQAdminExtImpl.examineConsumeStatsdoesMixAll.getRetryTopic(consumerGroup)thenexamineTopicRouteInfo(retryTopic)(I read this in the 4.9.4 sources jar; I did not run it). So forcheckOffsetNoDiff's group (SeaTunnel-Consumer-Group) the guard does not confirm the%RETRY%SeaTunnel-Consumer-Grouproute. As I readRocketMqAdminUtil.java:302-305, a missing retry-topic route ondev(code 17) yields an empty map, soconsumeOffsetis null and the assertion inside the 30 second window fails repeatedly until it times out, which is the same tight window as before. The comment "Both reads below need a resolvable topic route" is therefore only accurate for the first read. - (b) The stated motivation is a 4 minute 24 second route gap.
waitForTopicRouteitself has a 1 minute ceiling (:487), so for a gap of that size the guard times out after 60 seconds instead of the assertion timing out after 30. It helps gaps between 30 and 60 seconds and leaves the cited case failing, just later. The PR body correctly says this window is "latent rather than demonstrated", so I do not think this is worth blocking, but the comment and description should not imply the 4m24s case is now handled.
- (a)
- Potential risk: residual flakiness in
testSourceRocketMqTextToConsoleWithOffsetCheckthat looks fixed but is only partly mitigated, and a guard that reads as more protective than it is. - Best improvement: pick one of these. (1) Keep the guard but make the comment precise: it confirms the topic route for the
offsetTopicsread only. (2) Widen thecheckOffsetNoDiffwindow from 30 to 60 seconds, consistent withwaitConsumedOffsetsSyncedat:604-606, whose comment at:598-603records exactly this kind of CI-load overrun; the description argued against widening to keep a genuine mismatch failing fast, but a mismatch fails identically at 60 seconds, only later. (3) Additionally wait until the group's retry-topic route resolves before asserting. Option 1 alone is acceptable for this PR. - Severity: Medium
- Raised by another reviewer: No
Issue 4: One sink test that reads through getRocketMqConsumerData still has no route guard
- Location:
RocketMqIT.java:413-429(testSinkRocketMqMessageTag); compare:192and:211 - Problem description:
testSinkRocketMqandtestTextFormatSinkRocketMqcallwaitForTopicRoutefor their sink topic before the job runs.testSinkRocketMqMessageTagsinks totest_topic_message_tag(rocketmq-sink_fake_to_rocketmq_message_tag.conf,topic = "test_topic_message_tag") and then reads it back through the samegetRocketMqConsumerData, which the PR description explicitly lists as an exercised path, but it has no guard. This gap is pre-existing ondevand outside this diff, and I have no CI evidence that it fails today. It is included because the PR title is "the remaining ... offset reads", so this is one of the remaining sites. The same applies, more weakly, tosinkTopicin the restore test: onlysourceTopicis warmed before the first job starts (:706vs the job launch at:715);sinkTopicis only warmed later at:796. - Potential risk: the same "No topic route info in name server" class that #12115 and #12323 addressed for the other sink tests.
- Best improvement: add
waitForTopicRoute("test_topic_message_tag");at the top oftestSinkRocketMqMessageTag, matching its two siblings. Optional and small; feel free to defer the restore-test observation. - Severity: Medium
- Raised by another reviewer: No
Coverage matrix I checked at head (every topic-creating or route-sensitive site in RocketMqIT):
| Site | Guard |
|---|---|
startUp -> generateTestData("test_topic_source") |
guarded inside generateTestData (:453) |
All generateTestData callers (text tag, error tag, text, offset check, json, multi-table A and B, start config) |
guarded via :453 |
testSinkRocketMq, testTextFormatSinkRocketMq |
:192, :211 |
testSinkRocketMqMessageTag |
none (Issue 4) |
| latest / earliest / specific offsets / timestamp source tests | :358, :368, :378, :388 |
testSourceRocketMqRestore source topic (initial, additional, restore sends) and restore |
:706, :736, :775, :795; sink topic before restore :796; sink topic before first job: none |
getRocketMqConsumerData offset reads |
retry-wrapped (:524-550); no explicit route guard |
waitConsumedOffsetsSynced |
Awaitility 60s with ignoreExceptions (:604-606) |
checkOffsetNoDiff |
Awaitility 30s plus new guard (:638-641), see Issue 3 |
pollMessagesFromOffset, getTopicMaxOffset |
retry-wrapped (:873-883, :939-947) |
2. Code Quality Assessment
2.1 Coding Standards
- The added comments explain why, not what, and the changes are minimal and focused. No wildcard imports, no unrelated edits.
- Comment accuracy is the only problem: see Issue 2 and Issue 3(a). No new non-trivial methods or fields are introduced, so no missing-comment issue.
2.2 Test Coverage and Test Stability
Stability rating: Risk present.
Evidence:
- Positive: no hard
Thread.sleepin test code; both new waits are condition-based (waitForTopicRouteuses Awaitility with a 1 second poll,RocketMqIT.java:485-489; the retry has a bounded attempt count). No new fixed ports, static state or unreleased resources; the container and producer lifecycle is untouched (:143-188). - Residual risk: the
checkOffsetNoDiffwindow is still 30 seconds (:641) and the new guard does not confirm the retry-topic route thatcurrentOffsetsresolves (Issue 3). The retry wrapper will fail with an opaque NPE after exhaustion (Issue 1). Neither can make a real failure pass. - Not-a-masking check: the retry predicate catches only
RocketMqConnectorException, and the loop cannot convert a failure into a pass, so a genuine offset mismatch still fails. The assertions incheckOffsetNoDiffandwaitConsumedOffsetsSyncedare unchanged, so test strictness is not weakened. - Test-convention: no new test class, and the change is to
RocketMqITitself, so extending the existing IT is the right call.
What I could and could not verify: I read the code at the head commit, the local 4.9.4 client sources, and the fork's CI results for this exact head. I did not run the tests, and I cannot verify from source alone whether a name-server route gap actually reaches currentOffsets on the retry-topic path in CI; the 4m24s figure comes from the description and I have not independently confirmed it.
2.3 Documentation Updates
Not applicable: no user-visible change, no docs impact (docs/en and docs/zh unaffected).
3. Architectural Soundness
3.1 Elegance of the Solution
Temporary workaround, in the good sense for an E2E hardening: it reuses RetryMaterial and waitForTopicRoute already established in this class rather than adding a new mechanism. It is not a root-cause fix of route-propagation latency, which is not fixable from the test side. The root-cause-side change belongs to #12349 (production behaviour of currentOffsets), and this PR's retry benefit is contingent on it (Issue 2).
3.2 Maintainability
Good, with one caveat: a fourth near-identical RetryMaterial block now exists (:530-534, :546-550, :879-883, and :943-947, which differs only in using true and an always-true predicate). A tiny private helper would remove the duplication, but that is optional and I would not ask for it in this PR.
Sibling PR overlap check (read-only):
- #12393 ("Make RocketMqIT.deleteTopicIfExist actually delete the topic", open, same author): its hunks are the
QueueDatatoBrokerDataimport (:54) anddeleteTopicIfExist(:961-1001). This PR touches:533-550and:632-640only. I ran a three-way merge of the two heads against the shared base and got zero conflict markers, so there is no merge-conflict and no double-fix. They are independent. - Interaction worth knowing: once #12393 makes
deleteTopicIfExistreally delete, the delete-then-generateTestDataflow in the tag tests relies onwaitForTopicRouteinsidegenerateTestData(:453) to recreate the route; that guard already exists ondev, so nothing in this PR needs to change. - #12323 (merged 2026-09-19): this PR builds directly on it and does not undo any of it;
waitForTopicRouteand all its earlier call sites are untouched. - #12349 (open, unmerged): the semantic dependency described in Issue 2.
3.3 Extensibility
Neutral. Adding a route guard to testSinkRocketMqMessageTag (Issue 4) would make the class uniformly "guard before any topic use", which is easier to keep true as new tests are added.
3.4 Historical-Version Compatibility
Fully compatible. Test-only, no serialized state, checkpoint, configuration or option changes. The 2.6-release to 3.0-test upgrade path is not touched (this is an upstream apache/seatunnel PR against dev).
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| 1 | Retry exhaustion with shouldThrowException=false returns null and surfaces as a bare NPE, discarding the real cause |
RocketMqIT.java:539-550, RetryUtils.java:51-56, :74-79 |
Medium |
| 2 | Comment and description say currentOffsets already surfaces failures as exceptions; on dev it still returns an empty map for route gaps (RocketMqAdminUtil.java:302-305), so the retry depends on unmerged #12349 |
RocketMqIT.java:536-538 |
Medium |
| 3 | New guard confirms the topic route, not the retry-topic route currentOffsets resolves; its 1 minute ceiling is also shorter than the 4m24s gap cited |
RocketMqIT.java:635-638, :484-487, :650-652 |
Medium |
| 4 | testSinkRocketMqMessageTag (and restore sinkTopic before the first job) still has no route guard, unlike sibling sink tests |
RocketMqIT.java:413-429, :706-715 |
Medium |
5. Merge Recommendation
Conclusion: Ready to merge
Blockers - must be fixed
- None. No High issue and no compatibility concern.
Recommended fixes - non-blocking
- Issue 1: pass
trueforshouldThrowExceptionon the newcurrentOffsetsretry so a genuine failure keeps its cause. - Issue 2: correct the comment at
RocketMqIT.java:536-538and the PR description so they only claim what is true ondev, and state the merge-order relationship with #12349. - Issue 3: make the guard comment precise (it confirms the topic route for the
offsetTopicsread), and consider widening thecheckOffsetNoDiffwindow to 60 seconds for parity withwaitConsumedOffsetsSynced. - Issue 4: add
waitForTopicRoute("test_topic_message_tag");totestSinkRocketMqMessageTag.
Overall assessment: a small, well-scoped, well-described hardening. The change is safe (bounded retries, narrow predicate, no weakened assertions, no production code), and the description's candour about the evidence is exactly the right habit. My recommendations are about making the comments match what the code does and closing the last unguarded sink test. Better-alternative note: the durable fix for the retry-topic route question is the production change in #12349, which this test change only complements.
CI: for head 42e8fa6, the apache-side Build check is completed / success, and it points at the fork's Build workflow run, which I read: status completed, conclusion success, event push, head SHA equal to this PR's head. In that run both rocketmq-connector-it (8, ubuntu-latest) and rocketmq-connector-it (11, ubuntu-latest) are success; the remaining jobs are success or skipped (for example the website and UI jobs), with no failures. Notify test workflow and labeler are also success. Note that a green run shows the change compiles and these paths passed at least once; it does not by itself demonstrate the latent route-gap scenarios discussed above. GitHub reports the merge state as blocked; I read that as the pending approving review (this is my inference, I did not check the branch-protection rules).
🤖 Generated with Claude Code
Follow-up to apache#12323 for the two gaps flagged there but deliberately left out of that PR's scope. getRocketMqConsumerData retry-wrapped its offsetTopics lookup but not the currentOffsets call immediately below it, although both read broker metadata that can be briefly unavailable. The two now use the same RetryMaterial. checkOffsetNoDiff reads offsetTopics and currentOffsets under the tightest Awaitility window in the file, 30 seconds, against a route gap measured at 4m24s in CI. It now confirms the topic route before entering that window rather than widening it, which is the approach apache#12323 established.
42e8fa6 to
1b522ac
Compare
|
All four addressed. Thank you for these, particularly Issue 3, which is my own finding from #12332 applied back to my own change and I did not spot it. Issue 1. I have deliberately not changed the Issue 2. Corrected. The comment claimed Issue 3. Corrected, though I have reached a different conclusion on the second half and want to explain rather than quietly diverge. You are right that the guard confirms this topic's route while On widening Issue 4. Verified locally: |
|
@nzw921rx heads up on an overlap: this PR and your #12350 both edit This one is +30/-5 on that file, approved, CI green. #12350 is +51/-59 and currently conflicts with #12349 is the same area and in the same state, approved and green, open since 09-16. It is the production fix behind #12332, and SEZ9 confirmed on 09-20 that nothing further is needed there. |
Thanks for the heads-up. Please go ahead with this PR. I’ll rebase #12350 onto the latest dev afterward |
Purpose of this pull request
This is the follow-up I committed to on #12323, which fixes the two remaining gaps I found while sweeping that file and deliberately kept out of that PR to keep its scope tight. Both were listed there as points 2 and 3, and @DanielLeens recorded them as non-blocking in his review.
currentOffsetswas not retry-wrapped while its neighbour was. IngetRocketMqConsumerData, theoffsetTopicslookup is wrapped inRetryUtils.retryWithException, and thecurrentOffsetscall immediately below it was not, although both read broker metadata that can be briefly unavailable. They now use the sameRetryMaterial.This matters more since #12349. There,
RocketMqAdminUtil.currentOffsetsstops reporting a failed lookup as an empty map and surfaces it asRocketMqConnectorExceptioninstead. That is the right behaviour for the production caller, but it means an unwrapped call here fails the test where the wrapped neighbour one line up would have retried. TheRetryMaterialalready in place retries exactlyexception instanceof RocketMqConnectorException, so this is the consistent spelling rather than a new policy.checkOffsetNoDiffhas the tightest window in the file. It readsoffsetTopicsand thencurrentOffsetsunderAwaitilitywith a 30 second ceiling. Every other window in this file is 60 seconds or longer, up to 5 minutes, and while working on #12322 I measured a name server route gap that lasted 4 minutes 24 seconds. A gap of that size fails this check.The fix confirms the route before entering the window rather than widening it, using the
waitForTopicRoutehelper already in the file. That follows the approach #12323 established, and keeps the assertion window itself tight so a genuine offset mismatch still fails fast.I want to be precise about the evidence for each, as I was on #12323.
The
checkOffsetNoDiffwindow is latent rather than demonstrated:testSourceRocketMqTextToConsoleWithOffsetCheckdid not fail once across the 12 dailySchedule Backendruns I sampled for #12322. That is why it was not folded into #12323.The
currentOffsetscall has been seen failing tests, but I do not want to claim it as evidence for a retry, because it is not. On the first commit of #12349, before that PR was corrected,testSinkRocketMqfailed 7 of 7 atgetRocketMqConsumerDatawithROCKETMQ-09. The cause there was the never-created%RETRY%topic, which is a standing condition rather than a transient one, so a retry would only have delayed the same failure. #12349 fixes that cause directly. What this change covers is the genuinely transient case, and that has not been separately demonstrated on this call. It is a consistency fix with a plausible benefit, not a fix for an observed failure.Does this PR introduce any user-facing change?
No. Test-only, in a single E2E class. No production code, config option, or documented behaviour is touched.
How was this patch tested?
./mvnw -q -DskipTests verify -pl seatunnel-e2e/seatunnel-connector-v2-e2e/connector-rocketmq-e2eon JDK 11 passes, which covers the enforcer checks,spotless:checkand compilation.spotless:checkwas also run separately with up-to-date caching disabled.No new test is added, and this is the case the test-class convention is about: the change is to
RocketMqITitself, so the IT is both the thing being changed and the coverage. Therocketmq-connector-itlegs on this PR's own CI exercise both paths:getRocketMqConsumerDatais reached fromtestSinkRocketMq,testTextFormatSinkRocketMqandtestSinkRocketMqMessageTag, andcheckOffsetNoDifffromtestSourceRocketMqTextToConsoleWithOffsetCheck.