qianye1001 commented on code in PR #11534:
URL: https://github.com/apache/rocketmq/pull/11534#discussion_r4625088347
##########
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:
A crash between this flush and `promoteToBase()` can cause a rollback broker
to skip pending timers. With `timerWheelSnapshotFlush=false`, recovery ignores
the numeric snapshot and opens the old base with the new checkpoint.
`recover()` rewinds only one timerlog file from that checkpoint, so it can miss
slots added early in the snapshot interval even when all timerlog files are
still on disk.
I reproduced the on-disk state at this boundary with 512-byte timerlog files
and 50 records in distinct future slots. With snapshot mode disabled, recovery
restored 14 of 50 slots and reported queue offset 50. With snapshot mode
enabled, the same files restored all 50.
Could we keep the persisted `lastTimerLogFlushPos` at the previous base
offset until the atomic replacement and parent-directory fsync succeed? Queue
and read progress can be checkpointed separately from advancing that field. A
regression test that interrupts at this line, reopens with snapshot mode
disabled, and checks delivery across multiple timerlog files would cover the
rollback case.
--
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]