Skip to content

fix(rpl): add clock_diff_with_master to sql_delay_event commit-timestamps path - #747

Open
jiyfhust wants to merge 3 commits into
mysql:trunkfrom
jiyfhust:fix_sql_delay_clock_diff
Open

fix(rpl): add clock_diff_with_master to sql_delay_event commit-timestamps path#747
jiyfhust wants to merge 3 commits into
mysql:trunkfrom
jiyfhust:fix_sql_delay_clock_diff

Conversation

@jiyfhust

Copy link
Copy Markdown

fix(rpl): add clock_diff_with_master to sql_delay_event commit-timestamps path

PROBLEM

In sql_delay_event(), when immediate_commit_timestamp is available from the GTID event, the calculated sql_delay_end does not include clock_diff_with_master:

sql_delay_end = ceil(immediate_commit_timestamp / 1000000.00) + sql_delay;

However, the fallback path (when commit timestamps are unavailable) correctly adds clock_diff_with_master:

sql_delay_end = when.tv_sec + clock_diff_with_master + sql_delay;

Since immediate_commit_timestamp is in the master's clock domain but nap_time is computed against time(nullptr) (the replica's clock), the missing clock_diff_with_master causes the delay calculation to be off by the clock difference between master and replica. For example, if the master clock is 60 seconds ahead of the replica, the replica will wait 60 seconds less than the configured SOURCE_DELAY.

FIX

Add clock_diff_with_master to the commit-timestamps code path, making it consistent with the fallback path:

sql_delay_end = ceil(immediate_commit_timestamp / 1000000.00)
+ clock_diff_with_master + sql_delay;

This ensures correct delayed replication behavior when master and replica clocks are not synchronized.

The fix is backward compatible: when clock_diff_with_master is 0 (master and replica clocks are synchronized), behavior is unchanged.

What does this change do?

Why is it needed?

How was it tested?

  • Added/updated MTR tests under mysql-test/
  • scripts/ci/mtr.sh passes locally
  • Ran the relevant full suite (name it): ______

Contributor checklist

  • Code is formatted (scripts/ci/format.sh)
  • Commits are focused with descriptive messages

AI assistance

  • I did not use AI assistance for this contribution
  • I used AI assistance for this contribution

If AI assistance was used, describe the tool(s) and extent of use:

Areas touched

…amps path

PROBLEM
=======

In sql_delay_event(), when immediate_commit_timestamp is available
from the GTID event, the calculated sql_delay_end does not include
clock_diff_with_master:

  sql_delay_end = ceil(immediate_commit_timestamp / 1000000.00) + sql_delay;

However, the fallback path (when commit timestamps are unavailable)
correctly adds clock_diff_with_master:

  sql_delay_end = when.tv_sec + clock_diff_with_master + sql_delay;

Since immediate_commit_timestamp is in the master's clock domain but
nap_time is computed against time(nullptr) (the replica's clock), the
missing clock_diff_with_master causes the delay calculation to be
off by the clock difference between master and replica.  For example,
if the master clock is 60 seconds ahead of the replica, the replica
will wait 60 seconds less than the configured SOURCE_DELAY.

FIX
===

Add clock_diff_with_master to the commit-timestamps code path,
making it consistent with the fallback path:

  sql_delay_end = ceil(immediate_commit_timestamp / 1000000.00)
                  + clock_diff_with_master + sql_delay;

This ensures correct delayed replication behavior when master and
replica clocks are not synchronized.

The fix is backward compatible: when clock_diff_with_master is 0
(master and replica clocks are synchronized), behavior is unchanged.
@jiyfhust
jiyfhust requested a review from a team September 10, 2026 08:07
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 10, 2026
@github-actions github-actions Bot added Replication Changes touching replication or binlog code Tests Changes touching test code or test data Review Requested Review requested from code owners Build Passed PR build passed MTR Failed MTR suite failed and removed Build Passed PR build passed MTR Failed MTR suite failed labels Sep 10, 2026
@github-actions github-actions Bot added Build Passed PR build passed MTR Failed MTR suite failed labels Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Passed PR build passed MTR Failed MTR suite failed OCA Verified All contributors have signed the Oracle Contributor Agreement. Replication Changes touching replication or binlog code Review Requested Review requested from code owners Tests Changes touching test code or test data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant