fix(rpl): add clock_diff_with_master to sql_delay_event commit-timestamps path - #747
Open
jiyfhust wants to merge 3 commits into
Open
fix(rpl): add clock_diff_with_master to sql_delay_event commit-timestamps path#747jiyfhust wants to merge 3 commits into
jiyfhust wants to merge 3 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?
mysql-test/scripts/ci/mtr.shpasses locallyContributor checklist
scripts/ci/format.sh)AI assistance
If AI assistance was used, describe the tool(s) and extent of use:
Areas touched