lizhimins opened a new issue, #11533: URL: https://github.com/apache/rocketmq/issues/11533
### Is your feature request related to a problem? Please describe. With `timerWheelSnapshotFlush=true`, the base `timerwheel` file is never written once snapshots exist: the authoritative wheel lives in `timerwheel.<flag>` files. Rolling the switch back to `false` (or rolling back to an older image) therefore loads a stale base wheel, and operators must stop the broker and copy the latest snapshot back into the base file before rollback (the "rollback trap"). The default per-second byte-diff flush also scans the whole 36.9 MiB wheel every second (~11.9% of one core in our microbenchmark, vs ~0.7% for the snapshot path). ### Describe the solution you'd like. Make the base file always the latest complete wheel, without changing the on-disk format: - Each snapshot cycle: freeze the wheel into a direct buffer under the enqueue lock (all snapshot I/O afterwards runs unlocked); write `timerwheel.<offset>.tmp` in 1 MiB segments with `force` to bound the writeback burst; atomic rename to `timerwheel.<offset>`; persist the checkpoint with `lastTimerLogFlushPos == offset`; atomically replace the base via `ATOMIC_MOVE | REPLACE_EXISTING` (no explicit delete, which would open a base-absent window); fsync the directory; clean numeric snapshots. - Recovery prefers the newest numeric snapshot (the file name carries the wheel content end, so CP <- offset), otherwise base + CP. Between snapshots the checkpoint is pinned to the base content end so base + CP never diverge. - Capture the mode at construction: snapshot mode never mmaps the base file, and switching modes requires a restart; runtime config hot-updates cannot mismatch the mmap topology. - Disk format unchanged (raw slots, 52 B timerlog records, 56 B checkpoint); old and new images can read each other's files, and `true -> false` rollback degrades to a normal rolling restart. ### Describe alternatives you've considered. Segmented flushing of the snapshot alone (see #11522, superseded by this proposal) smooths the writeback burst but keeps the stale-base rollback trap. ### Additional context. Known operational boundary: in an old -> new -> old -> new sequence, a numeric snapshot left over from the first new period survives the old single-file period (old code never cleans numeric snapshots) and is preferred by the second new upgrade over the fresher base; if the interval is long enough for timerlog to expire with commitlog, the gap is unreplayable. Stale numeric snapshots must be deleted before the second upgrade starts; a follow-up can make recovery compare the max snapshot offset against the checkpoint and prefer the newer. Covered by a characterization test. -- 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]
