Skip to content

Commit e6bf62e

Browse files
committed
WL#7318 Delayed Replication: GTID based and relative to immediate master commit
Delayed replication is now applied per transaction (instead of per event) and is computed relative to the immediate_commit_timestamp (introduced in WL#7319) if both the immediate master and current server (slave) support immediate_commit_timestamp. If at least one of the servers does not support this timestamp, the delay will be computed using the old implementation.
1 parent 5c231a3 commit e6bf62e

25 files changed

+1536
-36
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
### Purpose ###
2+
#
3+
# This test file is invoked from rpl_sql_delay.
4+
#
5+
# After sleeping for $slave_sleep seconds (less that $delay), we check that the
6+
# slave is still waiting for MASTER_DELAY.
7+
# After synchronizing with the master, we check that the slave is no longer
8+
# waiting for the delay.
9+
# Then, we verify that the slave's only starts applying the transaction after
10+
# the delay is observed, through its immediate_commit_timestamp.
11+
#
12+
#
13+
### Parameters ###
14+
#
15+
# $slave_sleep number of seconds the slave sleeps before checking if it is
16+
# still waiting for the delay
17+
# $delay number of seconds configured for slave delay
18+
# $trx_num the gno of the transaction's gtid
19+
20+
21+
--source include/rpl_connection_slave.inc
22+
23+
--sleep $slave_sleep
24+
25+
--let $remaining_delay= query_get_value(SELECT REMAINING_DELAY FROM performance_schema.replication_applier_status, REMAINING_DELAY, 1)
26+
--let $sql_remaining_delay= query_get_value(SHOW SLAVE STATUS, SQL_Remaining_Delay, 1)
27+
28+
# Assert that the remaining delay value shown by both show slave status
29+
# and replication_applier_status table of performance schema is same.
30+
# using '>=' since $remaining_delay is obtained before $sql_remaining_delay.
31+
32+
--let $assert_text= Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.
33+
--let $assert_cond= "$remaining_delay" >= "$sql_remaining_delay"
34+
--source include/assert.inc
35+
36+
--source include/rpl_connection_master.inc
37+
--source include/sync_slave_sql_with_master.inc
38+
39+
--let $assert_text= Status should not be 'Waiting until MASTER_DELAY seconds after master executed event'
40+
--let $assert_cond= NOT("[SHOW SLAVE STATUS, Slave_SQL_Running_State, 1]" LIKE "Waiting until % seconds after master executed event")
41+
--source include/assert.inc
42+
43+
--source include/rpl_connection_master.inc
44+
--let $server_uuid= query_get_value(SELECT @@global.server_uuid, @@global.server_uuid, 1)
45+
--let $gtid= $server_uuid:$trx_num
46+
--source include/get_immediate_commit_timestamp.inc
47+
--let $master_immediate_commit_timestamp= $immediate_commit_timestamp
48+
49+
--source include/rpl_connection_slave.inc
50+
--let $gtid= $server_uuid:$trx_num
51+
--source include/get_immediate_commit_timestamp.inc
52+
--let $slave_immediate_commit_timestamp= $immediate_commit_timestamp
53+
--let $sql_delay= query_get_value("SHOW SLAVE STATUS", SQL_Delay, 1)
54+
# Ceiling is also used when computing the delay in the code
55+
--let $timestamp_diff_ms= `SELECT $slave_immediate_commit_timestamp-$master_immediate_commit_timestamp`
56+
--let $timestamp_diff_sec= `SELECT CEILING($timestamp_diff_ms / 1000000)`
57+
58+
--let $assert_text= The difference between the immediate_commit_timestamp should be at least the SQL_Delay
59+
--let $assert_cond= $timestamp_diff_sec >= $sql_delay
60+
--source include/assert.inc
61+
62+
--source include/rpl_connection_master.inc
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
### Purpose ###
2+
#
3+
# This test file is invoked from rpl_sql_delay_line_topology.
4+
#
5+
# After synchronizing the servers' sql threads, we check that the delay was
6+
# observed between server_1 and server_2 and then between server_2 and
7+
# server_3 by comparing their immediate_commit_timestamps
8+
#
9+
#
10+
### Parameters ###
11+
#
12+
# $slave_sleep number of seconds the slave sleeps before checking if it is
13+
# still waiting for the delay
14+
# $delay number of seconds configured for slave delay
15+
# $trx_num the gno of the transaction's gtid
16+
17+
18+
19+
--let $rpl_connection_name= server_1
20+
--source include/rpl_connection.inc
21+
--source include/rpl_sync.inc
22+
23+
--let $rpl_connection_name= server_2
24+
--source include/rpl_connection.inc
25+
--source include/rpl_sync.inc
26+
27+
--let $rpl_connection_name= server_1
28+
--source include/rpl_connection.inc
29+
--let $server_uuid= query_get_value(select @@global.server_uuid, @@global.server_uuid, 1)
30+
--let $gtid= $server_uuid:$trx_num
31+
--source include/get_immediate_commit_timestamp.inc
32+
--let $server_1_ICT= `SELECT $immediate_commit_timestamp`
33+
34+
--let $rpl_connection_name= server_2
35+
--source include/rpl_connection.inc
36+
--source include/get_immediate_commit_timestamp.inc
37+
--let $server_2_ICT= `SELECT $immediate_commit_timestamp`
38+
39+
--let $rpl_connection_name= server_3
40+
--source include/rpl_connection.inc
41+
--source include/get_immediate_commit_timestamp.inc
42+
--let $server_3_ICT= `SELECT $immediate_commit_timestamp`
43+
44+
#ceiling is also used when computing the delay in the code
45+
--let $ts_diff_server_2_1= `SELECT CEILING(($server_2_ICT-$server_1_ICT)/1000000)`
46+
--let $ts_diff_server_3_2= `SELECT CEILING(($server_3_ICT-$server_2_ICT)/1000000)`
47+
48+
--let $assert_text= The difference between the immediate_commit_timestamp of servers 1 and 2 should be at least the SQL_Delay
49+
--let $assert_cond= $ts_diff_server_2_1 >= $delay
50+
--source include/assert.inc
51+
52+
--let $assert_text= The difference between the immediate_commit_timestamp of servers 2 and 3 should be at least the SQL_Delay
53+
--let $assert_cond= $ts_diff_server_3_2 >= $delay
54+
--source include/assert.inc
55+
56+
--let $rpl_connection_name= server_1
57+
--source include/rpl_connection.inc
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
### Purpose ###
2+
#
3+
# This test file is invoked from rpl_sql_delay_multi_source.
4+
#
5+
# After synchronizing with the master, we check that the slave is no longer
6+
# waiting for the delay.
7+
# Then, we verify that the slave's only starts applying the transaction after
8+
# the delay is observed, through its immediate_commit_timestamp.
9+
#
10+
#
11+
### Parameters ###
12+
#
13+
# $trx_num the gno of the transaction's gtid
14+
# $slave slaves connection
15+
# $master masters connection
16+
17+
--let $sync_slave_connection= $slave
18+
--source include/sync_slave_sql_with_master.inc
19+
20+
--let $assert_text= Status should not be 'Waiting until MASTER_DELAY seconds after master executed event'
21+
--let $assert_cond= NOT("[SHOW SLAVE STATUS, Slave_SQL_Running_State, 1]" LIKE "Waiting until % seconds after master executed event")
22+
--source include/assert.inc
23+
24+
--let $rpl_connection_name= $master
25+
--source include/rpl_connection.inc
26+
27+
--let $server_uuid= query_get_value(SELECT @@global.server_uuid, @@global.server_uuid, 1)
28+
--let $gtid= $server_uuid:$trx_num
29+
--source include/get_immediate_commit_timestamp.inc
30+
--let $master_immediate_commit_timestamp= `SELECT $immediate_commit_timestamp`
31+
32+
--let $rpl_connection_name= $slave
33+
--source include/rpl_connection.inc
34+
35+
--let $gtid= $server_uuid:$trx_num
36+
--source include/get_immediate_commit_timestamp.inc
37+
--let $slave_immediate_commit_timestamp= `SELECT $immediate_commit_timestamp`
38+
--let $sql_delay= query_get_value("SHOW SLAVE STATUS", SQL_Delay, 1)
39+
#ceiling is also used when computing the delay in the code
40+
--let $timestamp_diff= `SELECT CEILING(($slave_immediate_commit_timestamp-$master_immediate_commit_timestamp)/1000000)`
41+
42+
--let $assert_text= The difference between the immediate_commit_timestamp should be at least the SQL_Delay
43+
--let $assert_cond= $timestamp_diff >= $sql_delay
44+
--source include/assert.inc
45+
46+
--let $rpl_connection_name= $master
47+
--source include/rpl_connection.inc
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
### Purpose ###
2+
#
3+
# This test file is invoked from rpl_sql_delay_multiple.
4+
#
5+
# After synchronizing both slaves with the master, we check that the slave is no longer
6+
# waiting for the delay.
7+
# Then, we verify that the slave's only starts applying the transaction after
8+
# the delay is observed, through its immediate_commit_timestamp.
9+
#
10+
### Parameters ###
11+
#
12+
# $trx_num
13+
14+
--let $sync_slave_connection= server_2
15+
--source include/sync_slave_sql_with_master.inc
16+
17+
--let $rpl_connection_name= server_1
18+
--source include/rpl_connection.inc
19+
20+
--let $sync_slave_connection= server_3
21+
--source include/sync_slave_sql_with_master.inc
22+
23+
--let $rpl_connection_name= server_1
24+
--source include/rpl_connection.inc
25+
26+
--let $server_uuid= query_get_value(SELECT @@global.server_uuid, @@global.server_uuid, 1)
27+
--let $gtid= $server_uuid:$trx_num
28+
--source include/get_immediate_commit_timestamp.inc
29+
--let $master_immediate_commit_timestamp= `SELECT $immediate_commit_timestamp`
30+
31+
--let $rpl_connection_name= server_2
32+
--source include/rpl_connection.inc
33+
34+
--source include/get_immediate_commit_timestamp.inc
35+
--let $slave1_immediate_commit_timestamp= `SELECT $immediate_commit_timestamp`
36+
--let $sql_delay_1= query_get_value("SHOW SLAVE STATUS", SQL_Delay, 1)
37+
#ceiling is also used when computing the delay in the code
38+
--let $timestamp_1_diff= `SELECT CEILING(($slave1_immediate_commit_timestamp-$master_immediate_commit_timestamp)/ 1000000)`
39+
40+
--let $rpl_connection_name= server_3
41+
--source include/rpl_connection.inc
42+
43+
--source include/get_immediate_commit_timestamp.inc
44+
--let $slave2_immediate_commit_timestamp= `SELECT $immediate_commit_timestamp`
45+
--let $sql_delay_2= query_get_value("SHOW SLAVE STATUS", SQL_Delay, 1)
46+
#ceiling is also used when computing the delay in the code
47+
--let $timestamp_2_diff= `SELECT CEILING(($slave2_immediate_commit_timestamp-$master_immediate_commit_timestamp)/ 1000000)`
48+
49+
--let $assert_text= The difference between the immediate_commit_timestamp should be at least the SQL_Delay
50+
--let $assert_cond= $timestamp_1_diff >= $sql_delay_1
51+
--source include/assert.inc
52+
53+
--let $assert_text= The difference between the immediate_commit_timestamp should be at least the SQL_Delay
54+
--let $assert_cond= $timestamp_2_diff >= $sql_delay_2
55+
--source include/assert.inc
56+
57+
--let $rpl_connection_name=server_1
58+
--source include/rpl_connection.inc
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
### Purpose ###
2+
#
3+
# This test file is invoked from rpl_sql_delay_old.
4+
#
5+
# After sleeping for $slave_sleep seconds (less that $delay), we check that the
6+
# slave is still waiting for MASTER_DELAY.
7+
# After synchronizing with the master, we check that the slave is no longer
8+
# waiting for the delay.
9+
# Then, we check that the delay was applied.
10+
#
11+
#
12+
### Parameters ###
13+
#
14+
# $slave_sleep number of seconds the slave sleeps before checking if it is
15+
# still waiting for the delay
16+
# $delay number of seconds configured for slave delay
17+
18+
19+
--source include/rpl_connection_slave.inc
20+
21+
--sleep $slave_sleep
22+
23+
--let $remaining_delay=query_get_value(Select *from performance_schema.replication_applier_status,REMAINING_DELAY,1)
24+
--let $sql_remaining_delay=query_get_value(show slave status,SQL_Remaining_Delay,1)
25+
26+
# Assert that the remaining delay value shown by both show slave status
27+
# and replication_applier_status table of performance schema is same.
28+
# using '>=' since $remaining_delay is obtained before $sql_remaining_delay.
29+
30+
--let $assert_text= Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.
31+
--let $assert_cond= "$remaining_delay" >= "$sql_remaining_delay"
32+
--source include/assert.inc
33+
34+
--source include/rpl_connection_master.inc
35+
--source include/sync_slave_sql_with_master.inc
36+
37+
--source include/rpl_connection_master.inc
38+
--let $time_2= `SELECT SYSDATE(6)`
39+
40+
--source include/rpl_connection_slave.inc
41+
--let $ms_diff= `SELECT TIMESTAMPDIFF(MICROSECOND,'$time_1','$time_2')`
42+
# Ceiling is also used when computing the delay in the code
43+
--let $time_diff= `SELECT CEILING($ms_diff / 1000000)`
44+
--let $assert_text= In the old infrastructure, the execution time of the transaction in the slave must be at least the delay
45+
--let $assert_cond= $time_diff >= $delay
46+
--source include/assert.inc
47+
48+
--let $assert_text= Status should not be 'Waiting until MASTER_DELAY seconds after master executed event'
49+
--let $assert_cond= NOT("[SHOW SLAVE STATUS, Slave_SQL_Running_State, 1]" LIKE "Waiting until % seconds after master executed event")
50+
--source include/assert.inc
51+
52+
--source include/rpl_connection_master.inc
53+
# $time_1 is collected in the same server as $time_2
54+
--let $time_1= `SELECT SYSDATE(6)`
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
[connection slave]
7+
CHANGE MASTER TO MASTER_DELAY= 7;
8+
include/start_slave.inc
9+
include/assert.inc [Assert that the desired delay from performance_schema is same as set in the Change master to command.]
10+
include/assert.inc [Assert that the sql_delay in show slave status is same as set in the Change master to command.]
11+
# Adding debug point 'sql_delay_without_timestamps' to @@GLOBAL.debug
12+
[connection master]
13+
CREATE TABLE t1 (a INT);
14+
[connection slave]
15+
include/assert.inc [Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.]
16+
[connection master]
17+
include/sync_slave_sql_with_master.inc
18+
[connection master]
19+
[connection slave]
20+
include/assert.inc [In the old infrastructure, the execution time of the transaction in the slave must be at least the delay]
21+
include/assert.inc [Status should not be 'Waiting until MASTER_DELAY seconds after master executed event']
22+
[connection master]
23+
INSERT INTO t1 VALUES (1);
24+
[connection slave]
25+
include/assert.inc [Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.]
26+
[connection master]
27+
include/sync_slave_sql_with_master.inc
28+
[connection master]
29+
[connection slave]
30+
include/assert.inc [In the old infrastructure, the execution time of the transaction in the slave must be at least the delay]
31+
include/assert.inc [Status should not be 'Waiting until MASTER_DELAY seconds after master executed event']
32+
[connection master]
33+
UPDATE t1 SET a=2;
34+
[connection slave]
35+
include/assert.inc [Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.]
36+
[connection master]
37+
include/sync_slave_sql_with_master.inc
38+
[connection master]
39+
[connection slave]
40+
include/assert.inc [In the old infrastructure, the execution time of the transaction in the slave must be at least the delay]
41+
include/assert.inc [Status should not be 'Waiting until MASTER_DELAY seconds after master executed event']
42+
[connection master]
43+
DELETE FROM t1 WHERE a=2;
44+
[connection slave]
45+
include/assert.inc [Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.]
46+
[connection master]
47+
include/sync_slave_sql_with_master.inc
48+
[connection master]
49+
[connection slave]
50+
include/assert.inc [In the old infrastructure, the execution time of the transaction in the slave must be at least the delay]
51+
include/assert.inc [Status should not be 'Waiting until MASTER_DELAY seconds after master executed event']
52+
[connection master]
53+
START TRANSACTION;
54+
INSERT INTO t1 VALUES (1);
55+
INSERT INTO t1 VALUES (2);
56+
INSERT INTO t1 VALUES (3);
57+
COMMIT;
58+
[connection slave]
59+
include/assert.inc [Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.]
60+
[connection master]
61+
include/sync_slave_sql_with_master.inc
62+
[connection master]
63+
[connection slave]
64+
include/assert.inc [In the old infrastructure, the execution time of the transaction in the slave must be at least the delay]
65+
include/assert.inc [Status should not be 'Waiting until MASTER_DELAY seconds after master executed event']
66+
[connection master]
67+
DROP TABLE t1;
68+
[connection slave]
69+
include/assert.inc [Assert that the REMAINING_DELAY from performance_schema is same as SQL_Remaining_Delay in the output of show slave status.]
70+
[connection master]
71+
include/sync_slave_sql_with_master.inc
72+
[connection master]
73+
[connection slave]
74+
include/assert.inc [In the old infrastructure, the execution time of the transaction in the slave must be at least the delay]
75+
include/assert.inc [Status should not be 'Waiting until MASTER_DELAY seconds after master executed event']
76+
[connection master]
77+
[connection slave]
78+
# Removing debug point 'sql_delay_without_timestamps' from @@GLOBAL.debug
79+
include/stop_slave_sql.inc
80+
CHANGE MASTER TO MASTER_DELAY= 0;
81+
include/start_slave_sql.inc
82+
[connection master]
83+
include/rpl_end.inc

0 commit comments

Comments
 (0)