[ISSUE #10989] Fix transactional message escape retry backoff (2 ^ n computed with XOR) - #10993
[ISSUE #10989] Fix transactional message escape retry backoff (2 ^ n computed with XOR)#10993unbridled-41 wants to merge 1 commit into
Conversation
…2 ^ n computed with XOR)
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR fixes a bug in the transactional message escape retry backoff calculation. The original code used 2 ^ escapeFailCnt which is XOR operation in Java, not exponentiation. The fix correctly uses 1 << escapeFailCnt (bit shift) to compute 2^n, and extracts the calculation into a separate method for clarity. A test case is added to verify the exponential backoff behavior.
LGTM — good catch on the XOR vs exponentiation bug!
Automated review by github-manager-bot
Test evidence (before → after)The sleep-sequence claim was verified by directly evaluating both expressions for (The sequences in the description and in #10989 have been corrected accordingly — n=8/9/10 evaluate to 1000/1100/800, not 800/900/200.) Key point:
The production call site ( Side note on CI: the workflow runs for this PR are in |
Which Issue(s) This PR Fixes
Brief Description
In
TransactionalMessageServiceImpl#check, the retry delay between failed escape attempts (broker withenableSlaveActingMaster,escapeMessagefailing) was computed asIn Java
^is XOR, not exponentiation, so the actual sleep sequence forescapeFailCnt= 1..10 was300, 0, 100, 600, 700, 400, 500, 1000, 1100, 800ms — non-monotonic and including a 0 ms delay on the second failure, which defeats the backoff entirely and hammers the store with immediate re-puts.This PR extracts the computation into a package-private helper
escapeRetryBackoffMillis(int)that returns the intended exponential backoff100L * (1 << escapeFailCnt)(200, 400, 800, ... ms), and uses it at the call site. No behavior other than the delay values changes.How Did You Test This Change?
Added
TransactionalMessageServiceImplTest#testEscapeRetryBackoffMillisIsExponential, which assertsescapeRetryBackoffMillis(i) == 100L * (1L << i)for i = 1..10. It fails on the old code (XOR sequence) and passes with this change.mvn -pl broker test -Dtest=TransactionalMessageServiceImplTestpasses (9/9).