Skip to content

Add aof_cmd_duration estimate for AOF reload RTO visibility - #15665

Merged
yinon-bit merged 14 commits into
redis:unstablefrom
yinon-bit:Add-Execution-Duration-Command
Sep 15, 2026
Merged

yinon-bit merged 14 commits into
redis:unstablefrom
yinon-bit:Add-Execution-Duration-Command

Conversation

@yinon-bit

@yinon-bit yinon-bit commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

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_UNKNOWN for synthetic alsoPropagate() / module RM_Replicate* ops, with leftover call() time assigned before feedAppendOnlyFile so 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 aofduration module API test suite, assert_range_exclude helper, and a scripting test that hash commands honor redis.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.

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.
@yinon-bit
yinon-bit requested review from ShooterIT and sundb August 17, 2026 08:49
Comment thread src/aof.c Resolved
Comment thread src/module.c Resolved
Comment thread src/server.c Resolved
@fcostaoliveira

Copy link
Copy Markdown
Collaborator

This change touches performance-sensitive code paths. Adding the action:run-benchmark label will trigger the CE Performance suite so we can see the impact before merge.

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.
@yinon-bit

Copy link
Copy Markdown
Contributor Author

@cursor review

@yinon-bit yinon-bit added the action:run-benchmark Triggers the benchmark suite for this Pull Request label Aug 17, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/aof.c Resolved
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).
Comment thread src/aof.c Resolved
Comment thread src/server.c Resolved
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.
Comment thread src/server.c Resolved
Comment thread src/aof.c Resolved
…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.
Comment thread src/server.c Resolved
An outer RM_Replicate must not receive an inner RM_Call's time, which
double-counted the write and dropped leftover sleep onto nowhere.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/t_hash.c Resolved
Comment thread src/t_hash.c Resolved
Comment thread src/module.c Resolved
Comment thread src/server.c Resolved
Comment thread src/server.c Resolved
Comment thread src/module.c Resolved
Comment thread src/server.h Resolved
Comment thread tests/modules/aofduration.c Resolved
Comment thread src/cluster_asm.c Resolved
… 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

codecov Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.96%. Comparing base (dce0c76) to head (a0a7e05).
⚠️ Report is 2 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/aof.c 83.02% <100.00%> (+0.10%) ⬆️
src/cluster_asm.c 91.90% <100.00%> (ø)
src/module.c 82.67% <100.00%> (-0.09%) ⬇️
src/server.c 89.62% <100.00%> (+0.09%) ⬆️
src/server.h 100.00% <ø> (ø)

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Lazy-expire DEL and other alsoPropagate() callers were still queued with duration 0, so their enclosing command time was not credited on AOF replay.
Comment thread src/aof.c Resolved
Comment thread src/server.c Resolved
Avoid crashing production on a clock glitch, and drop the rewrite-duration snapshot in one place after success or failure.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/server.c Resolved
@yinon-bit yinon-bit added action:run-benchmark Triggers the benchmark suite for this Pull Request and removed action:run-benchmark Triggers the benchmark suite for this Pull Request labels Sep 9, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/module.c Resolved
@fcostaoliveira

fcostaoliveira commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

CE Performance Automation : step 1 of 2 (build) DONE.

This comment was automatically generated given a benchmark was triggered.
Started building at 2026-09-10 11:54:05.127983 and took 92 seconds.
You can check each build/benchmark progress in grafana:

  • git hash: a0a7e05
  • git branch: Add-Execution-Duration-Command
  • commit date and time: 2026-09-10 13:57:28+03:00
  • commit summary: Skip leftover duration walks when AOF is off
  • test filters:
    • command priority lower limit: 0
    • command priority upper limit: 100000
    • test name regex: memtier_benchmark-1Mkeys-(load-string-with-10B-values-pipeline-100(-nokeyprefix)?|load-zset-with-10-elements-double-score|string-get-100B|load-string-with-1KiB-values)$
    • command group regex: .*

You can check a comparison in detail via the grafana link

@fcostaoliveira

fcostaoliveira commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

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.
Status: [################----------------------------------------------------------------] 20.0% completed.

In total will run 5 benchmarks.
- 4 pending.
- 1 completed:
- 1 successful.
- 0 failed.
You can check a the status in detail via the grafana link

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit a0a7e05. Configure here.

Comment thread src/module.c
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a0a7e05. Configure here.

@yinon-bit
yinon-bit merged commit 51913f6 into redis:unstable Sep 15, 2026
19 checks passed
@sundb sundb added release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository and removed action:run-benchmark Triggers the benchmark suite for this Pull Request labels Sep 18, 2026
ShooterIT added a commit that referenced this pull request Sep 24, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants