lizhimins commented on code in PR #11534:
URL: https://github.com/apache/rocketmq/pull/11534#discussion_r4661528144
##########
store/src/main/java/org/apache/rocketmq/store/timer/TimerMessageStore.java:
##########
@@ -1852,14 +1869,40 @@ public void run() {
long lastSnapshotTime = System.currentTimeMillis();
public void flush() throws IOException {
- if (storeConfig.isTimerWheelSnapshotFlush()) {
- synchronized (lockWhenFlush) {
- prepareTimerCheckPoint();
- timerLog.getMappedFileQueue().flush(0);
- if (System.currentTimeMillis() - lastSnapshotTime >
storeConfig.getTimerWheelSnapshotIntervalMs()) {
- lastSnapshotTime = System.currentTimeMillis();
-
timerWheel.backup(timerLog.getMappedFileQueue().getFlushedWhere());
+ if (timerWheelSnapshotMode) {
+ MappedFileQueue logQueue = timerLog.getMappedFileQueue();
+ prepareTimerCheckPoint();
+ long snapshotPos = -1;
+ if (System.currentTimeMillis() - lastSnapshotTime >
storeConfig.getTimerWheelSnapshotIntervalMs()) {
+ synchronized (lockWhenFlush) {
+ timerWheel.copyForSnapshot();
+ snapshotPos = logQueue.getMaxWrotePosition();
+ }
+ }
+ logQueue.flush(0);
+ if (snapshotPos >= 0) {
+ while (logQueue.getFlushedWhere() < snapshotPos) {
+ long flushedWhere = logQueue.getFlushedWhere();
+ logQueue.flush(0);
+ if (logQueue.getFlushedWhere() == flushedWhere) {
+ LOGGER.error("Timer snapshot skipped, timerlog
flush stalled at {} behind {}",
+ flushedWhere, snapshotPos);
+ snapshotPos = -1;
+ break;
+ }
}
+ }
+ if (snapshotPos >= 0) {
+ lastSnapshotTime = System.currentTimeMillis();
+ timerWheel.backup(snapshotPos);
+ // CP before promote keeps the swapped base end
recoverable; pending snapshot covers pre-promote crashes.
+ timerCheckpoint.setLastTimerLogFlushPos(snapshotPos);
+ timerCheckpoint.flush();
Review Comment:
Thanks @qianye1001 — this is exactly the gap the rework (532b28a) closes.
The CP-before-promote ordering is gone:
- `flush()` now runs `backup → promoteToBase (ATOMIC_MOVE | REPLACE_EXISTING
+ directory fsync) → setLastTimerLogFlushPos(snapshotPos) →
checkpoint.flush()`, so the persisted log watermark only advances after the
replacement and parent-directory fsync succeed. Between snapshots it stays at
the base end: `prepareTimerCheckPoint` no longer advances it in snapshot mode
(the flush service is its only advancer), while read/queue progress is still
checkpointed every cycle — the separation you suggested.
- The interrupted-at-promote rollback case is covered with your repro shape
(512-byte timerlog files, 50 records in distinct future slots):
`snapshotPromotionFailureRollbackTest` injects an IOException at
`promoteToBase`, reopens with `timerWheelSnapshotFlush=false` and asserts 50/50
slots + queue offset 50; `pendingSnapshotImmediateRollbackDeliveryTest` /
`pendingSnapshotOrdinaryFlushRollbackTest` freeze a pending snapshot without
promoting, recover, roll back to false, and the immediate variant verifies
actual delivery of all 50 unique messages across multiple timerlog files.
- Recovery is additionally fail-closed: `load()` verifies timerlog coverage
of the snapshot replay range and refuses to start on a gap, and commits the
recovered wheel into base before serving.
The literal interruption point you flagged (CP flush before promote) no
longer exists; the equivalent window is now injected at promote itself.
--
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]