Skip to content

Track full sync completion time - #4197

Open
satheeshaGowda wants to merge 4 commits into
valkey-io:unstablefrom
satheeshaGowda:full-sync-time
Open

Track full sync completion time#4197
satheeshaGowda wants to merge 4 commits into
valkey-io:unstablefrom
satheeshaGowda:full-sync-time

Conversation

@satheeshaGowda

@satheeshaGowda satheeshaGowda commented Jul 17, 2026

Copy link
Copy Markdown
Member

The current approach of manually inspecting logs to determine how long a full sync took is highly cumbersome, hence introducing a new metric called primary_last_full_sync_duration_ms.

The new metric primary_last_full_sync_duration_ms, which measures the total time (in milliseconds) taken to complete the last full synchronization, will be reported by replicas in the INFO replication output.

127.0.0.1:6380> info replication
# Replication
role:slave
master_host:localhost
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
primary_last_full_sync_duration_ms:15537        <<<<<<<<<-------------===== I AM HERE!
master_sync_in_progress:0
slave_read_repl_offset:5345000149
slave_repl_offset:5345000149
replicas_repl_buffer_size:0
replicas_repl_buffer_peak:0
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
replicas_waiting_psync:0
master_failover_state:no-failover
master_replid:51005812f8730e42095a20c1fe9397c08abd608e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:5345000149
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:10485760
repl_backlog_first_byte_offset:5345000122
repl_backlog_histlen:28

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

The server records replica full-sync duration, clears timing state after completion or abort, exposes the latest duration through INFO, and tests standard, role-transition, and dual-channel replication scenarios.

Full sync duration reporting

Layer / File(s) Summary
Timing state and INFO output
src/server.h, src/server.c
Adds full-sync timing fields, initializes them, and reports primary_last_full_sync_duration_ms.
Sync timing lifecycle
src/replication.c
Starts timing after PSYNC_CONTINUE, records elapsed milliseconds after RDB loading, and clears active timing during cleanup and abort paths.
Replication metric integration tests
tests/integration/full-sync-time.tcl
Validates the metric across replication role changes and dual-channel full sync.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant syncWithPrimary
  participant replicaAfterLoadPrimaryRDB
  participant INFO
  syncWithPrimary->>syncWithPrimary: Accept +CONTINUE and start timer
  syncWithPrimary->>replicaAfterLoadPrimaryRDB: Load primary RDB
  replicaAfterLoadPrimaryRDB->>replicaAfterLoadPrimaryRDB: Update and clear duration
  INFO->>INFO: Report primary_last_full_sync_duration_ms
Loading

Suggested reviewers: sumitk163

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: tracking and exposing full sync completion time.
Description check ✅ Passed The description matches the change by introducing and exposing the primary_last_full_sync_duration_ms replication metric.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@valkey-review-bot valkey-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found one correctness issue in the new metric: on the dual-channel path it is finalized before the full synchronization actually reaches steady state.

Comment thread src/replication.c Outdated
if (server.repl_backlog == NULL) createReplicationBacklog();
serverLog(LL_NOTICE, "PRIMARY <-> REPLICA sync: Finished with success");
if (server.repl_full_sync_start_time) {
server.repl_full_sync_duration_ms = elapsedMs(server.repl_full_sync_start_time);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

replicaAfterLoadPrimaryRDB() is not the completion point for dual-channel syncs. When this runs on server.repl_rdb_transfer_s, it only hands off to dualChannelSyncHandleRdbLoadCompletion() (src/replication.c:2413-2415); that helper can return after just marking REPL_DUAL_CHANNEL_RDB_LOADED if the main PSYNC is not ready yet (src/replication.c:3504-3509), and even the success path still has to drain pending_repl_data before the replica reaches steady state (src/replication.c:3456-3476). Resetting the timer here undercounts master_last_full_sync_duration_ms for dual-channel replicas; update it where dualChannelSyncSuccess() actually finishes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should ensure both the single and dual channel end at comparable points, or it will look like dual channel is slower when it isn't.

I think this means that dual channel replication should mark full sync "done" before we drain the accumulated buffer. Since on single channel replication, the draining of the primary-side replication backlog would not be included in the metric.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thats a good suggestion, thank you.

I was interested in marking full sync "done" after we drain the accumulated buffer, but there is no good way to differentiate between the backlog draining phase and the steady-state (real-time) replication stream for single-channel replication.

So in favor of simplicity and reduced complexity, excluding the backlog draining time from full sync duration time. wdyt?

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.82%. Comparing base (6b006c9) to head (c3ec422).
⚠️ Report is 27 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4197      +/-   ##
============================================
+ Coverage     76.81%   76.82%   +0.01%     
============================================
  Files           162      162              
  Lines         81455    81466      +11     
============================================
+ Hits          62570    62589      +19     
+ Misses        18885    18877       -8     
Files with missing lines Coverage Δ
src/replication.c 85.93% <100.00%> (+0.15%) ⬆️
src/server.c 89.51% <100.00%> (+<0.01%) ⬆️
src/server.h 100.00% <ø> (ø)

... and 18 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.

@satheeshaGowda

Copy link
Copy Markdown
Member Author

Hey @murphyjacob4 @sumitk163 , please take a look at this, when you get a chance , thanks!

Comment thread src/server.c Outdated
Comment thread src/replication.c Outdated
if (server.repl_backlog == NULL) createReplicationBacklog();
serverLog(LL_NOTICE, "PRIMARY <-> REPLICA sync: Finished with success");
if (server.repl_full_sync_start_time) {
server.repl_full_sync_duration_ms = elapsedMs(server.repl_full_sync_start_time);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should ensure both the single and dual channel end at comparable points, or it will look like dual channel is slower when it isn't.

I think this means that dual channel replication should mark full sync "done" before we drain the accumulated buffer. Since on single channel replication, the draining of the primary-side replication backlog would not be included in the metric.

Signed-off-by: Satheesha Gowda <satheesha.balaji@gmail.com>
Signed-off-by: Satheesha Gowda <satheesha.balaji@gmail.com>
Signed-off-by: Satheesha Gowda <satheesha.balaji@gmail.com>
Signed-off-by: Satheesha Gowda <satheesha.balaji@gmail.com>
@murphyjacob4

Copy link
Copy Markdown
Contributor

New metric is API surface area, so we should get a major decision.

@valkey-io/core-team please vote on whether to add the new metric primary_last_full_sync_duration_ms to track the most recent full sync duration: 👍/👎

@enjoy-binbin enjoy-binbin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

New info fields LGTM, did not review the code yet.

@PingXie

PingXie commented Jul 27, 2026

Copy link
Copy Markdown
Member

primary_last_full_sync_duration_ms

From a quick look, this would be the first INFO field to use the primary terminology. The prefix also gives the impression that the duration is measured on the primary, whereas it is measured locally on the replica. Furthermore, with chained replication in standalone mode, the upstream sync source may itself be a replica. Can we simply call it last_full_sync_duration_ms?

@soloestoy

Copy link
Copy Markdown
Member

Overall LGTM, though I haven't reviewed the code in detail.

Just to confirm — this is an observability metric from the replica's perspective, covering the entire duration from receiving the FULLRESYNC response to finishing RDB loading, right?

@satheeshaGowda

Copy link
Copy Markdown
Member Author

Overall LGTM, though I haven't reviewed the code in detail.

Just to confirm — this is an observability metric from the replica's perspective, covering the entire duration from receiving the FULLRESYNC response to finishing RDB loading, right?

Yes, except post RDB loading delta streaming time.

@madolson madolson added the needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. label Aug 3, 2026
@madolson

madolson commented Aug 3, 2026

Copy link
Copy Markdown
Member

Ran suggested last_successful_sync_duration_ms. @satheeshaGowda Write down the use cases to make sure we're solving it. Maybe also write out the docs here, that will help us inform the specific name and what it shows.

@github-actions github-actions Bot added major-decision-approved Major decision approved by TSC team and removed major-decision-pending Major decision pending by TSC team labels Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-decision-approved Major decision approved by TSC team needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

7 participants