ywx-sss commented on issue #11651:
URL: https://github.com/apache/rocketmq/issues/11651#issuecomment-7277788027
I traced the batching path on `develop` and the clock-step-back description
matches the code. In `TransactionalMessageServiceImpl.batchSendOpMessage()`:
``java
long startTime = System.currentTimeMillis();
long interval = ...getTransactionOpBatchInterval();
...
if (mqContext.getTotalSize().get() < maxSize &&
startTime - mqContext.getLastWriteTimestamp() < interval) {
firstTimestamp = Math.min(firstTimestamp,
mqContext.getLastWriteTimestamp());
continue;
}
``
`lastWriteTimestamp` is set from `System.currentTimeMillis()` when the op
message is built. If the wall clock steps back after a write, `startTime -
lastWriteTimestamp` becomes negative, so the `< interval` branch is always
taken and the queued commit/rollback records are never flushed until the clock
passes the old write time again. The same value is returned as
`firstTimestamp`, so `TransactionalOpBatchService` can also schedule the next
wakeup in the past and spin without making progress.
Two code-level directions:
- Use a monotonic clock for the batching interval and wakeup calculation
(`System.nanoTime()`) and keep wall-clock time only for logs; or
- Detect `startTime < lastWriteTimestamp` and treat the elapsed time as the
full interval (or reset `lastWriteTimestamp` to `startTime` after the queue is
flushed), which preserves the existing wall-clock field but makes the
comparison clock-jump-safe.
A regression test would use a controllable clock rather than a real NTP
step: start with a write at T, move the clock back by 5 s / 30 s / 45 s / 60 s
around the 3 s batch interval, run the batch service, and assert the queued op
records are written exactly once and the same transaction is not committed
again on the next check. The boundary cases are `elapsed == interval - 1 ms`
(defer), `elapsed == interval` (flush), and `elapsed < 0` after a step back
(flush or reset, never starve).
I did not run a broker with a stepped clock here; this is a code-path
confirmation, not a live reproduction.
--
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]