Skip to content

Stop TimeTaken when the data copy completes - #468

Merged
driv3r merged 2 commits into
mainfrom
fix-time-taken-after-copy
Oct 23, 2026
Merged

driv3r merged 2 commits into
mainfrom
fix-time-taken-after-copy

Conversation

@driv3r

@driv3r driv3r commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #314.

Problem

Ferry.Progress() computed TimeTaken as time.Now() - StartTime. It kept growing through wait-for-cutover, the cutover itself, and the final done report. The progress callback, /api/status, and the web UI's "Time Taken" all read this value.

Before the runtime fix:

  • Progress callbacks during a two-second cutover hold reported TimeTaken increasing from approximately 0.71 to 3.17 seconds.
  • With AutomaticCutover: false, /api/status went from 0s to 3s over three seconds of wait-for-cutover. With the fix it stayed at 0s because the copy itself took under a second.

Runtime fix

Run records when the data iterator finishes, immediately before publishing wait-for-cutover. Progress() measures TimeTaken up to that timestamp once it is set. The timestamp uses an unexported atomic.Pointer[time.Time] because progress readers and Run execute concurrently. DoneTime is unchanged.

Regression test and review correction

The original test commit held ROW_COPY_COMPLETED for two seconds and required at least three reports. That depended on callback scheduling rather than the behavior under test.

The test now holds cutover until a thread-safe queue has received three actual cutover progress callbacks. Each wait has a ten-second timeout. It then checks that all cutover and done reports have the same TimeTaken. There is no fixed sleep or timing-based sample-count assertion.

To reproduce the review finding, I temporarily changed the integration fixture's report interval from 500ms to 5000ms:

  • Original test: failed with Expected 2 to be >= 3, although the runtime duration was correctly frozen.
  • Updated test: passed, waiting for the required reports rather than ending the sampling window after two seconds.

The fixture interval was restored to 500ms; the temporary change is not included in the PR.

Verification

On local MySQL 8.0.32:

  • Updated timing test passes with the temporary five-second reporting interval.
  • Full test/integration/callbacks_test.rb: four tests pass in file/position mode and four pass in GTID mode at the normal reporting interval.
  • The original runtime fix was previously checked with the Go application suites and the /api/status before/after smoke described above.

Merged current main and resolved the changelog conflict while retaining both independent entries.

@driv3r
driv3r requested review from grodowski and mtaner October 19, 2026 16:54

@forge33 forge33 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.

yep makes sense

Progress.TimeTaken is always now - StartTime, so it keeps increasing
while Ghostferry waits for and performs the cutover.
Record when the data iterator finishes and compute Progress.TimeTaken up
to that point, so the progress callback and the control server no longer
count the wait for cutover and the cutover itself.

Fixes #314.
@driv3r
driv3r force-pushed the fix-time-taken-after-copy branch from 4868694 to 1b33faa Compare October 22, 2026 14:36
@driv3r
driv3r merged commit 6c4db33 into main Oct 23, 2026
19 checks passed
@driv3r
driv3r deleted the fix-time-taken-after-copy branch October 23, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ghostferry control server's webui shows the time taken as now - start

2 participants