Repository navigation
[ISSUE #11047] Keep timer enqueue completion state per attempt to avoid duplicate delivery - #11595
Drifter-yh wants to merge 3 commits into
Conversation
46b0a6b to
258cf01
Compare
…empt TimerEnqueuePutService retried the whole batch whenever a single request failed, so requests whose doEnqueue had already succeeded were enqueued again. Every retry appended another TimerLog unit for the same message and the scheduled message was delivered once per redundant unit. Replace the shared latch/released/succ fields of TimerRequest with an Attempt object. Each retry round re-arms the request with a new attempt, and the dequeue pipeline releases the attempt it was handed, so a late release from a previous owner can never complete the attempt that replaced it. The retry round now only reprocesses requests whose current attempt has not succeeded, and waits for a previous attempt that is still owned by the dequeue pipeline before reusing the request. This prevents a concurrent second enqueue while the previous owner may still deliver the message.
258cf01 to
1682c78
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #11595 +/- ##
=============================================
+ Coverage 51.33% 51.39% +0.06%
- Complexity 15036 15057 +21
=============================================
Files 1391 1391
Lines 103942 104016 +74
Branches 13643 13661 +18
=============================================
+ Hits 53354 53455 +101
+ Misses 44329 44299 -30
- Partials 6259 6262 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| } else { | ||
| holdMomentForUnknownError(); | ||
| } | ||
| holdMomentForUnknownError(); |
There was a problem hiding this comment.
If the enqueue service stops during this backoff, the retry loop exits and commitQueueOffset still advances past requests that did not succeed. Could we only advance it once the entire batch has succeeded?
There was a problem hiding this comment.
Fixed in f926611. commitQueueOffset now advances only when every request in the batch has a successful attempt; a stop during the backoff leaves the offset where it was. A fully successful batch is still committed even if the stop lands before the next loop check.
testEnqueueStopDuringBackoffDoesNotAdvanceCommitOffset stops the service from holdMomentForUnknownError after the single failed attempt and asserts the offset stays unchanged. TimerMessageStoreTest: 15 tests, 0 failures, 2 pre-existing Windows skips; Checkstyle and SpotBugs clean.
…ssful batch If the enqueue service stops while backing off before a retry, the loop exits with requests that did not succeed. Do not acknowledge that batch: commitQueueOffset now moves only when every request of the batch has a successful attempt. A batch that did complete successfully is still committed even if the stop happens before the next loop condition runs. testEnqueueStopDuringBackoffDoesNotAdvanceCommitOffset stops the service from holdMomentForUnknownError and asserts the offset stays unchanged.
…tempt-scoped # Conflicts: # store/src/main/java/org/apache/rocketmq/store/timer/TimerMessageStore.java
Which Issue(s) This PR Fixes
Brief Description
TimerEnqueuePutService#fetchAndPutTimerRequestretried the whole batch after any single request failed, so requests whosedoEnqueuehad already succeeded were enqueued again on every retry round. Each retry appended anotherTimerLogunit 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:
releasedstayedtrueafter 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 makeallSuccessobserve work the retry had not done yet.This patch makes completion state per attempt:
TimerRequest.Attemptnow owns the latch, thedonesignal,succand the "handed to the dequeue pipeline" flag.fetchAndPutTimerRequeststarts a new attempt for each round and only reprocesses requests whose current attempt has not succeeded.dequeuePutQueuecarries the attempt it was handed over with (pipelineAttempt).TimerDequeuePutMessageServicecaptures that attempt when it takes the request and releases exactly that attempt infinally, so a retry that re-armed the request can never have its new attempt completed by the previous owner.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.This keeps the commit-offset contract unchanged:
commitQueueOffsetis 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 realTimerLog, so they also run on Windows):testEnqueueRetryReprocessesOnlyFailedRequests— two requests, one transientdoEnqueuefailure; the failed request is enqueued twice (first failure + retry), the already-succeeded one exactly once, and both rounds complete their own latch.testEnqueueRetryWaitsForPreviousDequeueOwner— the first attempt hands a request todequeuePutQueue; the test holds that owner, lets the retry re-arm completion, then releases the owner withsucc = true. The retry must not enqueue the message again, must not commit early, and the late release must only complete the attempt it owned.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:
JaCoCo 0.8.5 cannot instrument the JDK 17 Mockito classes used by this test class, hence
jacoco.skipfor 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.