| 1 |
# |
| 2 |
# Purpose: |
| 3 |
# This test validates that a slave's relay log format description event is |
| 4 |
# not used to calculate the Seconds_Behind_Master time displayed by |
| 5 |
# SHOW SLAVE STATUS. |
| 6 |
# |
| 7 |
# Methodology: |
| 8 |
# Ensure that a slave's reported Seconds_Behind_Master does not point before |
| 9 |
# a time in which we can prove that it has progressed beyond. The slave's |
| 10 |
# relay log events are created using the timestamp at which the IO thread was |
| 11 |
# created. Therefore, after starting the slave's IO thread, we sleep so any |
| 12 |
# proceeding events are forced to have later timestamps. After sleeping, we run |
| 13 |
# MDL statements on the master and save the time at which they are binlogged. |
| 14 |
# Once the slave executes these MDL commands, we have proven that the slave has |
| 15 |
# caught up to this saved timestamp. At this point, if the value of |
| 16 |
# Seconds_Behind_Master points before the time in which the MDL events were |
| 17 |
# logged, it is invalid. |
| 18 |
# |
| 19 |
# References: |
| 20 |
# MDEV-16091: Seconds_Behind_Master spikes to millions of seconds |
| 21 |
# MDEV-25999: Unrealistic "Seconds behind master" value |
| 22 |
# MDEV-36840: Seconds_Behind_Master Spike at Log Rotation on Parallel Replica |
| 23 |
# |
| 24 |
--source include/have_debug.inc |
| 25 |
--source include/have_debug_sync.inc |
| 26 |
--source include/have_innodb.inc |
| 27 |
--source include/master-slave.inc |
| 28 |
|
| 29 |
--connection slave |
| 30 |
|
| 31 |
# Using_Gtid needs to start as NO before updating debug_dbug |
| 32 |
--source include/stop_slave.inc |
| 33 |
CHANGE MASTER TO MASTER_USE_GTID=NO; |
| 34 |
--source include/start_slave.inc |
| 35 |
|
| 36 |
--let $sleep_time=2 |
| 37 |
--echo # Future events must be logged at least $sleep_time seconds after |
| 38 |
--echo # the slave starts |
| 39 |
--sleep $sleep_time |
| 40 |
|
| 41 |
--connection master |
| 42 |
--echo # Write events to ensure slave will be consistent with master |
| 43 |
create table t1 (a int); |
| 44 |
insert into t1 values (1); |
| 45 |
--sync_slave_with_master |
| 46 |
let $wait_condition= SELECT STATE LIKE '%waiting for more updates' |
| 47 |
FROM information_schema.PROCESSLIST WHERE COMMAND = 'Slave_SQL'; |
| 48 |
--source include/wait_condition.inc |
| 49 |
|
| 50 |
--echo # Enable breakpoints |
| 51 |
SET @save_dbug= @@GLOBAL.debug_dbug; |
| 52 |
SET @@GLOBAL.debug_dbug= |
| 53 |
'+d,pause_sql_thread_on_fde,negate_clock_diff_with_master'; |
| 54 |
|
| 55 |
--connection master |
| 56 |
--echo # Flush logs on master forces slave to generate a Format description |
| 57 |
--echo # event in its relay log |
| 58 |
flush logs; |
| 59 |
|
| 60 |
--connection slave |
| 61 |
--echo # On the next FDE, the slave should have the master CREATE/INSERT events |
| 62 |
--sleep $sleep_time |
| 63 |
SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; |
| 64 |
select count(*)=1 from t1; |
| 65 |
|
| 66 |
--echo # The relay log FDE has been processed - here we check to ensure it was |
| 67 |
--echo # not considered in Seconds_Behind_Master calculation |
| 68 |
# `Seconds_Behind_Master` must remains 0. |
| 69 |
# * MDEV-16091: `Seconds_Behind_Master` should not point at the FDE's timestamp, |
| 70 |
# which is the time of `start_slave.inc`. |
| 71 |
# * MDEV-25999 & MDEV-36840: For a new event stream, `Seconds_Behind_Master` |
| 72 |
# should not point at anything at all, because FDEs are not user content. |
| 73 |
--let $status_items= Seconds_Behind_Master |
| 74 |
--source include/show_slave_status.inc |
| 75 |
|
| 76 |
--echo # Safely resume slave SQL (worker) thread |
| 77 |
|
| 78 |
--let $dbug_wait_state="debug sync point: now" |
| 79 |
--echo # Prove SQL thread is in state $dbug_wait_state |
| 80 |
--let $wait_condition= SELECT STATE=$dbug_wait_state from information_schema.PROCESSLIST where COMMAND="Slave_SQL" |
| 81 |
--source include/wait_condition.inc |
| 82 |
|
| 83 |
SET @@global.debug_dbug="-d,pause_sql_thread_on_fde"; |
| 84 |
SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; |
| 85 |
|
| 86 |
# We have to wait for the SQL thread to acknowledge the sql_thread_continue |
| 87 |
# signal. Otherwise the below RESET command can overwrite the signal before |
| 88 |
# the SQL thread is notified to proceed, causing it to "permanently" become |
| 89 |
# stuck awaiting the signal (until timeout is reached). |
| 90 |
|
| 91 |
--echo # Wait for SQL thread to continue into normal execution |
| 92 |
--let $wait_condition= SELECT STATE!= $dbug_wait_state from information_schema.PROCESSLIST where COMMAND="Slave_SQL" |
| 93 |
--source include/wait_condition.inc |
| 94 |
|
| 95 |
# Reset last sql_thread_continue signal |
| 96 |
SET DEBUG_SYNC='RESET'; |
| 97 |
|
| 98 |
|
| 99 |
--echo # |
| 100 |
--echo # MDEV-29639 |
| 101 |
--echo # When receiving an event after the SQL Thread idles, |
| 102 |
--echo # Seconds_Behind_Master should not update before it updates |
| 103 |
--echo # last_master_timestamp |
| 104 |
|
| 105 |
--connection slave |
| 106 |
--source include/stop_slave.inc |
| 107 |
set @@global.debug_dbug="+d,pause_sql_thread_on_next_event"; |
| 108 |
--source include/start_slave.inc |
| 109 |
|
| 110 |
--connection master |
| 111 |
insert into t1 values(2); |
| 112 |
--source include/save_master_gtid.inc |
| 113 |
|
| 114 |
# Each event after starting will trigger a pause, so continually send signal |
| 115 |
# sql_thread_continue until caught up |
| 116 |
--connection slave |
| 117 |
--let $caught_up=0 |
| 118 |
--let $tries= 0 |
| 119 |
set debug_sync='now wait_for paused_on_event'; |
| 120 |
--disable_query_log |
| 121 |
while (!$caught_up) |
| 122 |
{ |
| 123 |
set debug_sync='now signal sql_thread_continue'; |
| 124 |
--let $slave_gtid= `SELECT @@global.gtid_slave_pos` |
| 125 |
if (`SELECT strcmp("$master_pos","$slave_gtid") = 0`) |
| 126 |
{ |
| 127 |
--inc $caught_up |
| 128 |
} |
| 129 |
--inc $tries |
| 130 |
# Wait 30s |
| 131 |
if (`SELECT $tries > 300`) |
| 132 |
{ |
| 133 |
--die Replica failed to sync with primary |
| 134 |
} |
| 135 |
sleep 0.1; |
| 136 |
} |
| 137 |
set debug_sync="RESET"; |
| 138 |
--enable_query_log |
| 139 |
|
| 140 |
--connection master |
| 141 |
--echo # Sleeping 1s to create a visible SBM gap between events |
| 142 |
sleep 1; |
| 143 |
insert into t1 values(3); |
| 144 |
--source include/save_master_gtid.inc |
| 145 |
|
| 146 |
--connection slave |
| 147 |
set debug_sync='now wait_for paused_on_event'; |
| 148 |
--let $sbm= query_get_value(SHOW SLAVE STATUS, Seconds_Behind_Master, 1) |
| 149 |
|
| 150 |
if ($sbm) |
| 151 |
{ |
| 152 |
--echo # Expected Seconds_Behind_Master to be 0 but was $sbm |
| 153 |
--die Seconds_Behind_Master should not show updates before last_master_timestamp is updated |
| 154 |
} |
| 155 |
|
| 156 |
# Continually send signal sql_thread_continue until caught up |
| 157 |
--let $caught_up=0 |
| 158 |
--let $tries= 0 |
| 159 |
--disable_query_log |
| 160 |
while (!$caught_up) |
| 161 |
{ |
| 162 |
set debug_sync='now signal sql_thread_continue'; |
| 163 |
--let $slave_gtid= `SELECT @@global.gtid_slave_pos` |
| 164 |
if (`SELECT strcmp("$master_pos","$slave_gtid") = 0`) |
| 165 |
{ |
| 166 |
--inc $caught_up |
| 167 |
} |
| 168 |
--inc $tries |
| 169 |
# Wait 30s |
| 170 |
if (`SELECT $tries > 300`) |
| 171 |
{ |
| 172 |
--die Replica failed to sync with primary |
| 173 |
} |
| 174 |
sleep 0.1; |
| 175 |
} |
| 176 |
--enable_query_log |
| 177 |
|
| 178 |
# Cleanup |
| 179 |
--source include/stop_slave.inc |
| 180 |
set debug_sync='RESET'; |
| 181 |
SET @@global.debug_dbug=$save_dbug; |
| 182 |
--source include/start_slave.inc |
| 183 |
--source include/sync_with_master_gtid.inc |
| 184 |
|
| 185 |
--connection master |
| 186 |
DROP TABLE t1; |
| 187 |
|
| 188 |
--source include/rpl_end.inc |