Skip to content

Commit e1ef99c

Browse files
committed
MDEV-7145: Delayed replication
Merge feature into 10.2 from feature branch. Delayed replication adds an option CHANGE MASTER TO master_delay=<seconds> Replication will then delay applying events with that many seconds. This creates a replication slave that reflects the state of the master some time in the past. Feature is ported from MySQL source tree. Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2 parents 057c560 + fb13616 commit e1ef99c

31 files changed

+1677
-321
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# ==== Purpose ====
2+
#
3+
# Auxiliary file used by rpl_delayed_slave.test. This assumes that an
4+
# 'INSERT INTO t1...' query has been executed on the master. It does
5+
# this:
6+
#
7+
# - After half the delay, check the status. It should be delaying and
8+
# the query should not have executed.
9+
#
10+
# - After one and a half delay, check the status. It should not be
11+
# delaying and the query should be executed.
12+
#
13+
#
14+
# ==== Usage ====
15+
#
16+
# --let $query_number= 4
17+
# --source extra/rpl_tests/delayed_slave_wait_on_query.inc
18+
#
19+
# Parameters:
20+
# $query_number
21+
# The value of the 'b' column in t1 for the row inserted by the query
22+
# we are waiting for.
23+
24+
connection master;
25+
26+
--echo [on slave]
27+
--let $slave_timeout= $time1
28+
--source include/sync_slave_io_with_master.inc
29+
--echo # sleep 1*T
30+
--sleep $time1
31+
32+
--let $assert_text= Query $query_number should not be executed
33+
--let $assert_cond= MAX(b) < $query_number FROM t1
34+
--source include/rpl_assert.inc
35+
36+
--let $assert_text= Status should be 'Waiting until MASTER_DELAY...'
37+
--let $assert_cond= "[SHOW SLAVE STATUS, Slave_SQL_Running_State, 1]" LIKE "Waiting until MASTER_DELAY%"
38+
--source include/rpl_assert.inc
39+
40+
--echo # sleep 1*T
41+
--sleep $time1
42+
43+
--echo # sync with master (with timeout 1*T)
44+
--source include/sync_with_master.inc
45+
46+
--let $assert_text= Query $query_number should be executed
47+
--let $assert_cond= MAX(b) = $query_number FROM t1
48+
--source include/rpl_assert.inc
49+
50+
--let $assert_text= Status should be 'Has read all relay log...'
51+
--let $assert_cond= "[SHOW SLAVE STATUS, Slave_SQL_Running_State, 1]" LIKE "Slave has read all relay log%"
52+
--source include/rpl_assert.inc
53+
54+
55+
--source include/check_slave_is_running.inc

mysql-test/include/check-testcase.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ if ($tmp)
6767
--echo Replicate_Do_Domain_Ids
6868
--echo Replicate_Ignore_Domain_Ids
6969
--echo Parallel_Mode conservative
70+
--echo SQL_Delay 0
71+
--echo SQL_Remaining_Delay NULL
72+
--echo Slave_SQL_Running_State
7073
}
7174
if (!$tmp) {
7275
# Note: after WL#5177, fields 13-18 shall not be filtered-out.

mysql-test/include/relocate_binlogs.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ if ($relocate_index_file)
101101
--eval LOAD DATA INFILE '$relocate_fix_relay_log_info' INTO TABLE tmp (entry)
102102
--let $count= `SELECT count(*) FROM tmp`
103103

104-
--let $_curr_entry= `SELECT entry FROM tmp WHERE id=1`
104+
--let $_curr_entry= `SELECT entry FROM tmp WHERE id=2`
105105
--let $_curr_entry_basename= `SELECT RIGHT(RTRIM("$_curr_entry"), LOCATE("$_path_separator",REVERSE(RTRIM("$_curr_entry"))) -1)`
106106

107107
if ($relocate_is_windows)
108108
{
109-
--eval UPDATE tmp SET entry='$_to\$_curr_entry_basename' WHERE id=1
109+
--eval UPDATE tmp SET entry='$_to\$_curr_entry_basename' WHERE id=2
110110
}
111111
if (!$relocate_is_windows)
112112
{
113-
--eval UPDATE tmp SET entry='$_to/$_curr_entry_basename' WHERE id=1
113+
--eval UPDATE tmp SET entry='$_to/$_curr_entry_basename' WHERE id=2
114114
}
115115

116116
--remove_file $relocate_fix_relay_log_info

mysql-test/include/rpl_assert.inc

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# ==== Purpose ====
2+
#
3+
# Check if a condition holds, fail with debug info if not.
4+
#
5+
# The condition is parsed before executed. The following constructs
6+
# are supported:
7+
#
8+
# [SQL STATEMENT, COLUMN, ROW]
9+
# The square bracket is replaced by the result from SQL STATEMENT,
10+
# in the given COLUMN and ROW.
11+
#
12+
# <1>
13+
# This is a shorthand for the result of the first executed square
14+
# bracket. <2> is a shorthand for the second executed square
15+
# bracket, and so on.
16+
#
17+
# ==== Usage ====
18+
#
19+
# --let $assert_text= Relay_Log_Pos must be smaller than pos.
20+
# --let $assert_cond= [SHOW SLAVE STATUS, Relay_Log_Pos, 1] >= $min_pos AND <1> <= $max_pos
21+
# [--let $assert_quiet= 1]
22+
# [--let $rpl_debug= 1]
23+
# --source include/rpl_assert.inc
24+
#
25+
# Parameters:
26+
#
27+
# $assert_text
28+
# Text that describes what is being checked. By default, this text
29+
# is written to the query log.
30+
#
31+
# $assert_cond
32+
# Condition to check. See above for details about the format. The
33+
# condition will be executed as `SELECT $assert_cond`. Note: this
34+
# condition is parsed using SQL statements, quoted inside single
35+
# quotes, so it must not contain single quotes itself (use double
36+
# quotes for strings).
37+
#
38+
# $assert_quiet
39+
# Do not print $assert_text to the query log.
40+
#
41+
# $rpl_debug
42+
# Print extra debug info.
43+
44+
45+
if ($rpl_debug)
46+
{
47+
--echo # debug: assert_text='$assert_text' assert_cond='$assert_cond'
48+
}
49+
50+
# Sanity-check input
51+
if (`SELECT "$assert_text" = ""`)
52+
{
53+
--die ERROR IN TEST: the mysqltest variable rpl_test must be set
54+
}
55+
56+
# Evaluate square brackets in cond.
57+
--let $_rpl_assert_substmt_number= 1
58+
--let $_rpl_interpolated_cond= $assert_cond
59+
--let $_rpl_assert_lbracket= `SELECT LOCATE('[', '$_rpl_interpolated_cond')`
60+
while ($_rpl_assert_lbracket)
61+
{
62+
# Get position of right bracket
63+
--let $_rpl_assert_rbracket= `SELECT LOCATE(']', '$_rpl_interpolated_cond')`
64+
if (!$_rpl_assert_rbracket)
65+
{
66+
--echo BUG IN TEST: Mismatching square brackets in assert_cond: '$assert_cond'
67+
--die BUG IN TEST: Mismatching square brackets in $assert_cond
68+
}
69+
# Get sub-statement and result of it
70+
--let $_rpl_assert_substmt= `SELECT SUBSTRING('$_rpl_interpolated_cond', $_rpl_assert_lbracket + 1, $_rpl_assert_rbracket - $_rpl_assert_lbracket - 1)`
71+
--let $_rpl_assert_substmt_result= query_get_value($_rpl_assert_substmt)
72+
if ($rpl_debug)
73+
{
74+
--echo # debug: sub-statement='$_rpl_assert_substmt' result='$rpl_assert_result'
75+
}
76+
# Replace sub-statement by its result
77+
--let $_rpl_interpolated_cond= `SELECT REPLACE('$_rpl_interpolated_cond', '[$_rpl_assert_substmt]', '$_rpl_assert_substmt_result')`
78+
# Replace result references by result
79+
--let $_rpl_interpolated_cond= `SELECT REPLACE('$_rpl_interpolated_cond', '<$_rpl_assert_substmt_number>', '$_rpl_assert_substmt_result')`
80+
81+
--let $_rpl_assert_lbracket= `SELECT LOCATE('[', '$_rpl_interpolated_cond')`
82+
83+
--inc $_rpl_assert_substmt_number
84+
}
85+
86+
if ($rpl_debug)
87+
{
88+
--echo # debug: interpolated_cond='$_rpl_interpolated_cond'
89+
}
90+
91+
# Execute.
92+
--let $_rpl_assert_result= `SELECT $_rpl_interpolated_cond`
93+
94+
if ($rpl_debug)
95+
{
96+
--echo # debug: result='$_rpl_assert_result'
97+
}
98+
99+
# Check.
100+
if (!$_rpl_assert_result)
101+
{
102+
--echo ######## Test assertion failed: $assert_text ########
103+
--echo Dumping debug info:
104+
--source include/show_rpl_debug_info.inc
105+
--echo Assertion text: '$assert_text'
106+
--echo Assertion condition: '$assert_cond'
107+
--echo Assertion condition, interpolated: '$_rpl_interpolated_cond'
108+
--echo Assertion result: '$_rpl_assert_result'
109+
--die Test assertion failed in rpl_assertion.inc
110+
}
111+
112+
if (!$assert_quiet)
113+
{
114+
--echo # Asserted this: $assert_text
115+
}
116+
117+
--let $assert_text=
118+
--let $assert_cond=
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ==== Purpose ====
2+
#
3+
# Display the delay state of the SQL thread.
4+
#
5+
# ==== Usage ====
6+
#
7+
# --let $verbose_delayed_slave_state= [0|1]
8+
# --source extra/rpl_tests/show_delayed_slave_state.inc
9+
#
10+
# By default, the output is normalized so that it does not depend on
11+
# exact timing or exact binlog positions. If
12+
# $verbose_delayed_slave_state is set, then it outputs exact times and
13+
# binlog positions. This can be useful for debugging.
14+
15+
--let $_delayed_slave_status= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running_State, 1)
16+
17+
--let $_delayed_slave_remaining_delay= query_get_value(SHOW SLAVE STATUS, SQL_Remaining_Delay, 1)
18+
--let $_delayed_slave_qualitative_delay= `SELECT CASE WHEN "$_delayed_slave_remaining_delay" = "NULL" THEN "NULL" WHEN "$_delayed_slave_remaining_delay" = "0" THEN "0" ELSE "greater than zero" END`
19+
20+
--let $_delayed_slave_io_pos= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1)
21+
--let $_delayed_slave_sql_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1)
22+
--let $_delayed_slave_qualitative_log_pos= `SELECT IF($_delayed_slave_io_pos > $_delayed_slave_sql_pos, "behind", "in sync with")`
23+
24+
--echo Slave_SQL_Running_State='$_delayed_slave_status'; SQL_Remaining_Delay is $_delayed_slave_qualitative_delay; SQL thread is $_delayed_slave_qualitative_log_pos IO thread
25+
26+
if ($verbose_delayed_slave_state) {
27+
--echo SQL_Remaining_Delay='$_delayed_slave_remaining_delay'; Read_master_log_pos='$_delayed_slave_io_pos'; Exec_Master_Log_Pos='$_delayed_slave_sql_pos'
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ==== Purpose ====
2+
#
3+
# This file does the same as the built-in command sync_with_master,
4+
# but can be configured to use a custom timeout. This has the benefit
5+
# that it accepts the same $slave_timeout and $master_connection
6+
# parameters as wait_for_slave_param.inc
7+
#
8+
#
9+
# ==== Usage ====
10+
#
11+
# --connection master
12+
# --source include/save_master_pos.inc
13+
# --connection slave
14+
# --source include/sync_with_master.inc
15+
#
16+
# Parameters to this macro are $slave_timeout and
17+
# $master_connection. See wait_for_slave_param.inc for
18+
# descriptions.
19+
20+
--let $slave_param= Relay_Master_Log_File
21+
--let $slave_param_value= $_master_file
22+
--source include/wait_for_slave_param.inc
23+
24+
--let $slave_param= Exec_Master_Log_Pos
25+
--let $slave_param_value= $_master_pos
26+
--source include/wait_for_slave_param.inc

mysql-test/suite/multi_source/info_logs.result

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ MASTER 2.2
8989
# EOF
9090
#
9191
show all slaves status;
92-
Connection_name Slave_SQL_State Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert Last_IO_Errno Last_IO_Error Last_SQL_Errno Last_SQL_Error Replicate_Ignore_Server_Ids Master_Server_Id Master_SSL_Crl Master_SSL_Crlpath Using_Gtid Gtid_IO_Pos Replicate_Do_Domain_Ids Replicate_Ignore_Domain_Ids Parallel_Mode Retried_transactions Max_relay_log_size Executed_log_entries Slave_received_heartbeats Slave_heartbeat_period Gtid_Slave_Pos
93-
Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_1 60 master-bin.000001 <read_master_log_pos> relay.000002 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space1> None 0 No 0 No 0 0 1 No conservative 0 1073741824 7 0 60.000
94-
MASTER 2.2 Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_2 60 master-bin.000001 <read_master_log_pos> relay-master@00202@002e2.000002 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space2> None 0 No 0 No 0 0 2 No conservative 0 1073741824 7 0 60.000
92+
Connection_name Slave_SQL_State Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert Last_IO_Errno Last_IO_Error Last_SQL_Errno Last_SQL_Error Replicate_Ignore_Server_Ids Master_Server_Id Master_SSL_Crl Master_SSL_Crlpath Using_Gtid Gtid_IO_Pos Replicate_Do_Domain_Ids Replicate_Ignore_Domain_Ids Parallel_Mode SQL_Delay SQL_Remaining_Delay Slave_SQL_Running_State Retried_transactions Max_relay_log_size Executed_log_entries Slave_received_heartbeats Slave_heartbeat_period Gtid_Slave_Pos
93+
Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_1 60 master-bin.000001 <read_master_log_pos> relay.000002 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space1> None 0 No 0 No 0 0 1 No conservative 0 NULL Slave has read all relay log; waiting for the slave I/O thread to update it 0 1073741824 7 0 60.000
94+
MASTER 2.2 Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_2 60 master-bin.000001 <read_master_log_pos> relay-master@00202@002e2.000002 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space2> None 0 No 0 No 0 0 2 No conservative 0 NULL Slave has read all relay log; waiting for the slave I/O thread to update it 0 1073741824 7 0 60.000
9595
include/wait_for_slave_to_start.inc
9696
set default_master_connection = 'MASTER 2.2';
9797
include/wait_for_slave_to_start.inc
9898
set default_master_connection = '';
9999
show all slaves status;
100-
Connection_name Slave_SQL_State Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert Last_IO_Errno Last_IO_Error Last_SQL_Errno Last_SQL_Error Replicate_Ignore_Server_Ids Master_Server_Id Master_SSL_Crl Master_SSL_Crlpath Using_Gtid Gtid_IO_Pos Replicate_Do_Domain_Ids Replicate_Ignore_Domain_Ids Parallel_Mode Retried_transactions Max_relay_log_size Executed_log_entries Slave_received_heartbeats Slave_heartbeat_period Gtid_Slave_Pos
101-
Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_1 60 master-bin.000001 <read_master_log_pos> relay.000004 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space1> None 0 No 0 No 0 0 1 No conservative 0 1073741824 6 0 60.000
102-
MASTER 2.2 Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_2 60 master-bin.000001 <read_master_log_pos> relay-master@00202@002e2.000004 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space2> None 0 No 0 No 0 0 2 No conservative 0 1073741824 6 0 60.000
100+
Connection_name Slave_SQL_State Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert Last_IO_Errno Last_IO_Error Last_SQL_Errno Last_SQL_Error Replicate_Ignore_Server_Ids Master_Server_Id Master_SSL_Crl Master_SSL_Crlpath Using_Gtid Gtid_IO_Pos Replicate_Do_Domain_Ids Replicate_Ignore_Domain_Ids Parallel_Mode SQL_Delay SQL_Remaining_Delay Slave_SQL_Running_State Retried_transactions Max_relay_log_size Executed_log_entries Slave_received_heartbeats Slave_heartbeat_period Gtid_Slave_Pos
101+
Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_1 60 master-bin.000001 <read_master_log_pos> relay.000004 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space1> None 0 No 0 No 0 0 1 No conservative 0 NULL Slave has read all relay log; waiting for the slave I/O thread to update it 0 1073741824 6 0 60.000
102+
MASTER 2.2 Slave has read all relay log; waiting for the slave I/O thread to update it Waiting for master to send event 127.0.0.1 root MYPORT_2 60 master-bin.000001 <read_master_log_pos> relay-master@00202@002e2.000004 <relay_log_pos> master-bin.000001 Yes Yes 0 0 <read_master_log_pos> <relay_log_space2> None 0 No 0 No 0 0 2 No conservative 0 NULL Slave has read all relay log; waiting for the slave I/O thread to update it 0 1073741824 6 0 60.000
103103
#
104104
# List of files matching '*info*' pattern
105105
# after slave server restart

0 commit comments

Comments
 (0)