Drifter-yh opened a new pull request, #11647: URL: https://github.com/apache/rocketmq/pull/11647
## Summary Follow-up to #11534 for #11521. #11534 moved the timerlog flush and snapshot write out of `lockWhenFlush`, but the freeze itself still memcpy'd the full wheel under that lock: 604800 slots x 2 x 32 B = 36.9 MiB with the default 7-day wheel. Timer enqueue (`TimerMessageStore#doEnqueue`) takes the same lock per request, so every snapshot interval blocked enqueue for the whole copy. This change: - tracks the slots written since the previous freeze (`putSlot` and `reviseSlot` mark them; snapshot-mode enqueue already serializes wheel writes with `copyForSnapshot` under `lockWhenFlush`); - copies the whole wheel on the first freeze, then refreshes only the dirty slots; - falls back to the sequential full-wheel copy when more than a quarter of the slots are dirty, where one memcpy is faster than per-slot copies. No on-disk format, recovery, or snapshot-ordering change: the frozen buffer is complete at every freeze, only the bytes copied under the lock differ. Fixes #11521. ## Benchmark `TimerWheel.copyForSnapshot()`, 604800 slots (36.9 MiB), JDK 17/Windows, 20 iterations after warm-up: | dirty slots | copied | median | p90 | | --- | --- | --- | --- | | all (first freeze / dense fallback) | 36.9 MiB | 4.00 ms | 4.69 ms | | 50,000 | 1.6 MiB | 0.41 ms | 0.57 ms | | 10,000 | 320 KiB | 0.19 ms | 0.38 ms | | 1,000 | 32 KiB | 0.11 ms | 0.25 ms | At 1k timer TPS and a 10s snapshot interval, ~10k distinct slots are written between snapshots, so the enqueue pause from the freeze goes from ~4 ms to ~0.2 ms. These are microbenchmark numbers, not a broker run. ## Test plan - [x] `mvn -pl store -Dtest='TimerWheelTest,TimerMessageStoreTest,TimerCheckPointTest,TimerLogTest,TimerMetricsTest' -Djacoco.skip=true test`: 51 passed, 0 failed, 2 skipped. - [x] Checkstyle: 0 violations. SpotBugs: 0 bugs. - [x] New `TimerWheelTest.dirtySlotSnapshotCopyTest`: full first freeze; zero-slot freeze when nothing changed; one-slot refresh with both snapshot files round-tripped; dense fallback to the full copy. -- 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]
