Repository navigation
Add aof_cmd_duration estimate for AOF reload RTO visibility - #15665
Conversation
Port Enterprise tracking of estimated command execution time in the AOF, exposed via INFO persistence, including PROP_DURATION_UNKNOWN handling for self-propagating commands (SPOP/HEXPIRE/XCLAIM) and module replication.
|
This change touches performance-sensitive code paths. Adding the |
The default test list covers tests/unit/moduleapi, so the External Server Tests workflow picked up the new suite and tried to apply its loadmodule override via CONFIG SET against the already-running server, aborting the whole run. Tag it external:skip like every other module API test.
|
@cursor review |
Accumulate multi-part AOF load time, credit blocked-module background duration only when AOF is writing, and do not let REPL-only unknown-duration ops steal the enclosing call duration. Also drop the ineffective assignment inside rewriteAppendOnlyFile (BGREWRITE child / parent already resets to 0).
Reset aof_cmd_duration when the rewrite child starts (new empty INCR AOF), not when the child finishes, so commands appended during rewrite are kept. Unknown-duration ops take only leftover enclosing time after known AOF ops.
…te fail Stamp nested UNKNOWN AOF ops so EVAL does not dump Lua time onto rewrites, credit blocked RM_Replicate once via GIL leftover, and restore the estimate when BGREWRITEAOF fails while the old AOF is still in use.
An outer RM_Replicate must not receive an inner RM_Call's time, which double-counted the write and dropped leftover sleep onto nowhere.
… duration HEXPIRE/HGETDEL/HGETEX were bypassing call() gates via a manual alsoPropagate, which leaked into AOF and replicas. Credit unaccounted blocked-module time only when there are ops to attach it to, including reply-callback RM_Replicate.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #15665 +/- ##
============================================
- Coverage 77.09% 76.96% -0.13%
============================================
Files 145 145
Lines 87693 87753 +60
============================================
- Hits 67608 67542 -66
- Misses 20085 20211 +126
🚀 New features to boost your workflow:
|
Lazy-expire DEL and other alsoPropagate() callers were still queued with duration 0, so their enclosing command time was not credited on AOF replay.
Avoid crashing production on a clock glitch, and drop the rewrite-duration snapshot in one place after success or failure.
Keep the leftover-assignment note; drop the long section write-up.
CE Performance Automation : step 1 of 2 (build) DONE.This comment was automatically generated given a benchmark was triggered.
You can check a comparison in detail via the grafana link |
CE Performance Automation : step 2 of 2 (benchmark) RUNNING...This comment was automatically generated given a benchmark was triggered. Started benchmark suite at 2026-09-10 16:51:04.883918 and took 131.394455 seconds up until now. In total will run 5 benchmarks. |
assignLeftoverDurationToUnknownOps only feeds aof_cmd_duration via feedAppendOnlyFile. Walking also_propagate on every command with AOF disabled was paid on the write path with no observability benefit. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit a0a7e05. Configure here.
| if (bc->background_duration <= bc->background_duration_accounted) return 0; | ||
| long d = (long)(bc->background_duration - bc->background_duration_accounted); | ||
| bc->background_duration_accounted = bc->background_duration; | ||
| return d; |
There was a problem hiding this comment.
Background leftover claimed too early
Medium Severity
moduleTakeUnaccountedBackgroundDuration keeps unaccounted background time only when also_propagate is empty. A GIL section that already queued known ops (for example RM_Call !) still claims the slice, assignLeftoverDurationToUnknownOps then discards the remainder because those ops are not PROP_DURATION_UNKNOWN, and a later reply-callback RM_Replicate sees nothing left. aof_cmd_duration undercounts that replicated write even though this path is meant to credit measured blocked-client time once.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit a0a7e05. Configure here.
## Issue `stopAppendOnly()` unconditionally called `fsync()` and `close()` on `server.aof_fd`. When AOF was in `AOF_WAIT_REWRITE`, the initial rewrite could be scheduled but not started because another background operation was still running. In that state, no AOF file had been opened and `server.aof_fd` was `-1`. Failed daily CI: https://github.com/redis/redis/actions/runs/35547037033/job/106174688222 The unconditional `close(server.aof_fd)` was not introduced by PR #15665. [#15665](#15665) introduced the `aof_cmd_duration` feature and its test, which exercised this AOF lifecycle state. The CI failure occurred when the test disabled AOF before the scheduled rewrite had actually started. The test helper waited only for `aof_rewrite_in_progress` and returned while the rewrite was still scheduled, exposing the existing `close(-1)` bug during cleanup. ## Change 1. Check server.aof_fd before flushing, fsyncing, and closing the AOF file. 2. Update `waitForBgrewriteaof` to wait until both `aof_rewrite_in_progress` and `aof_rewrite_scheduled` are cleared, preventing the test from disabling AOF while a rewrite is still pending. 3. Add a test for the close(-1) case. --------- Co-authored-by: Yuan Wang <[email protected]>


tracking of estimated command execution time in the AOF, exposed via INFO persistence, including PROP_DURATION_UNKNOWN handling for self-propagating commands (SPOP/HEXPIRE/XCLAIM) and module replication.
Note
Medium Risk
Touches core command propagation, AOF feeding, and module GIL/unblock paths; behavior is covered by new tests but miscounted duration could mislead RTO estimates.
Overview
Adds a best-effort AOF replay time estimate (
aof_cmd_duration, microseconds) that grows as commands are written to the AOF and is exposed in INFO persistence when AOF is enabled.Propagation now carries per-op duration: measured time for the main command path (
alsoPropagateEx/call()),PROP_DURATION_UNKNOWNfor syntheticalsoPropagate()/ moduleRM_Replicate*ops, with leftovercall()time assigned beforefeedAppendOnlyFileso rewrites (SPOP→SREM, HEXPIRE/HGETDEL, XCLAIM, HIMPORT SET, etc.) are credited without double-counting when mixed with known-duration ops. Nested calls and blocked-module background time (GIL unlock / context free) feed the same leftover logic; duration is not accumulated when AOF is off.AOF lifecycle: load rebuilds the counter from per-file wall time; BGREWRITEAOF resets it for the new INCR stream and restores the pre-rewrite value if rewrite fails. Stopping AOF clears the estimate.
Adds the
aofdurationmodule API test suite,assert_range_excludehelper, and a scripting test that hash commands honorredis.set_repl(REPL_NONE)for effect propagation.Reviewed by Cursor Bugbot for commit a0a7e05. Bugbot is set up for automated code reviews on this repo. Configure here.