Drifter-yh opened a new pull request, #11595: URL: https://github.com/apache/rocketmq/pull/11595
### Which Issue(s) This PR Fixes - Fixes #11047 ### Brief Description `TimerEnqueuePutService#fetchAndPutTimerRequest` retried the **whole** batch after any single request failed, so requests whose `doEnqueue` had already succeeded were enqueued again on every retry round. Each retry appended another `TimerLog` unit for the same message into the same timer-wheel slot, and every unit is converted and delivered independently on dequeue, so the scheduled message was delivered more than once. The retry bookkeeping also had the completion race described in [the review of #11048](https://github.com/apache/rocketmq/pull/11048#pullrequestreview-3310959617): `released` stayed `true` after the first attempt, so re-arming only the latch meant a successful retry never completed the new latch, while a late release from a previous dequeue owner could complete it and make `allSuccess` observe work the retry had not done yet. This patch makes completion state per attempt: - `TimerRequest.Attempt` now owns the latch, the `done` signal, `succ` and the "handed to the dequeue pipeline" flag. `fetchAndPutTimerRequest` starts a new attempt for each round and only reprocesses requests whose current attempt has not succeeded. - A request handed to `dequeuePutQueue` carries the attempt it was handed over with (`pipelineAttempt`). `TimerDequeuePutMessageService` captures that attempt when it takes the request and releases exactly that attempt in `finally`, so a retry that re-armed the request can never have its new attempt completed by the previous owner. - Before reusing a request whose previous attempt is still owned by the dequeue pipeline, the retry waits for that attempt to finish (`isDone()`). If the previous owner succeeded in the meantime, the message is not enqueued again; the retry only completes its own attempt bookkeeping. If the previous owner failed (for example because dequeue stopped running), the request is retried once through the normal path. - Round 1 is unchanged: no request has succeeded yet, so the candidate list is the whole batch. This keeps the commit-offset contract unchanged: `commitQueueOffset` is still advanced only after every request of the batch has a successful attempt. ### How Did You Test This Change? Three new deterministic tests in `TimerMessageStoreTest` (they do not need a real `TimerLog`, so they also run on Windows): 1. `testEnqueueRetryReprocessesOnlyFailedRequests` — two requests, one transient `doEnqueue` failure; the failed request is enqueued twice (first failure + retry), the already-succeeded one exactly once, and both rounds complete their own latch. 2. `testEnqueueRetryWaitsForPreviousDequeueOwner` — the first attempt hands a request to `dequeuePutQueue`; the test holds that owner, lets the retry re-arm completion, then releases the owner with `succ = true`. The retry must not enqueue the message again, must not commit early, and the late release must only complete the attempt it owned. 3. `testEnqueueRetryAfterPreviousDequeueOwnerFails` — the previous owner fails after dequeue stops running; the retry then enqueues the message exactly once through the direct path. Commands and results on Windows 11, Microsoft OpenJDK 17.0.14, Maven 3.9.2: ``` mvn -B -ntp -pl store -am -Dtest=TimerMessageStoreTest -DfailIfNoTests=false -Djacoco.skip=true -Dspotbugs.skip=true test Tests run: 14, Failures: 0, Errors: 0, Skipped: 2 (the two pre-existing Windows skips) BUILD SUCCESS mvn -B -ntp -pl store -am -DskipTests -Djacoco.skip=true -Dspotbugs.skip=true validate 0 Checkstyle violations mvn -B -ntp -pl store -DskipTests -Djacoco.skip=true spotbugs:check BugInstance size is 0 — BUILD SUCCESS ``` JaCoCo 0.8.5 cannot instrument the JDK 17 Mockito classes used by this test class, hence `jacoco.skip` for the local run; the test itself only relies on Java 8 APIs and the module still compiles with `-source 1.8`. AI assistance: the analysis, implementation and tests were produced with an AI coding agent and reviewed before submission. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
