lizhimins opened a new pull request, #11534:
URL: https://github.com/apache/rocketmq/pull/11534

   ## Summary
   
   Fixes #11533. Supersedes #11522 (segmented flush alone keeps the stale-base 
rollback trap).
   
   With `timerWheelSnapshotFlush=true` the base `timerwheel` file is never 
written once snapshots exist, so rolling back to `false` / an older image loads 
a stale wheel and requires a stop-the-world copy of the latest snapshot. This 
PR makes the base file always the latest complete wheel, with zero on-disk 
format change:
   
   - Snapshot cycle: freeze the wheel into a direct buffer under the enqueue 
lock (snapshot I/O runs unlocked afterwards); write `timerwheel.<offset>.tmp` 
in 1 MiB segments with `force` to bound the writeback burst; atomic rename to 
`timerwheel.<offset>`; persist checkpoint == offset **before** promoting; 
atomically replace the base with `ATOMIC_MOVE | REPLACE_EXISTING` (no delete, 
no base-absent window); fsync the directory; clean numeric snapshots.
   - Recovery prefers the newest numeric snapshot (file name carries the wheel 
content end, CP <- offset), otherwise base + CP; between snapshots CP is pinned 
to the base content end (`lastPromotedOffset`) so the pair never diverges.
   - Mode is captured at construction: snapshot mode never mmaps the base; 
switching modes requires a restart, so config hot-updates cannot mismatch the 
mmap topology.
   - `timerWheelSnapshotFlush` defaults to `true`.
   
   Result: `true -> false` rollback and new -> old image rollback degrade to a 
normal rolling restart; wheel persistence CPU drops from ~11.9% to ~0.7% of one 
core in our microbenchmark.
   
   ## Known boundary
   
   old -> new -> old -> new: a numeric snapshot left over from the first new 
period survives the old single-file period and is preferred by the second new 
upgrade over the fresher base; if timerlog expired with commitlog in between, 
the gap is unreplayable. Stale numeric snapshots must be deleted before the 
second upgrade starts (characterization test included); a follow-up can compare 
max snapshot offset against the checkpoint in recovery.
   
   ## Test plan
   
   - [x] `mvn -pl store test -Dtest='org.apache.rocketmq.store.timer.*Test'` — 
44/44 green, including:
     - snapshot flush + recover, pending-snapshot recovery, CP pinning between 
snapshots, promote round-trip / base replacement;
     - engine-switch (restart-only mode change) verification;
     - `oldNewOldNewStalePendingBoundaryTest` characterizing the rollback 
boundary and the delete-stale-snapshot workaround.
   - [ ] Crash-injection (SIGKILL per flush window) and cross-image round-trip 
on a test cluster.


-- 
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]

Reply via email to