|
| 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 | +# |
| 22 | +--source include/have_debug.inc |
| 23 | +--source include/have_innodb.inc |
| 24 | +--source include/master-slave.inc |
| 25 | + |
| 26 | +--connection slave |
| 27 | +--source include/stop_slave.inc |
| 28 | +SET @save_dbug= @@GLOBAL.debug_dbug; |
| 29 | +SET @@global.debug_dbug="+d,pause_sql_thread_on_fde"; |
| 30 | +--source include/start_slave.inc |
| 31 | + |
| 32 | +--let $sleep_time=2 |
| 33 | +--echo # Future events must be logged at least $sleep_time seconds after |
| 34 | +--echo # the slave starts |
| 35 | +--sleep $sleep_time |
| 36 | + |
| 37 | +--connection master |
| 38 | +--echo # Write events to ensure slave will be consistent with master |
| 39 | +create table t1 (a int); |
| 40 | +insert into t1 values (1); |
| 41 | +--let $t_master_events_logged= `SELECT UNIX_TIMESTAMP()` |
| 42 | + |
| 43 | +--echo # Flush logs on master forces slave to generate a Format description |
| 44 | +--echo # event in its relay log |
| 45 | +flush logs; |
| 46 | + |
| 47 | +--connection slave |
| 48 | +--echo # Ignore FDEs that happen before the CREATE/INSERT commands |
| 49 | +SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; |
| 50 | +SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; |
| 51 | +SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; |
| 52 | +SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; |
| 53 | + |
| 54 | +--echo # On the next FDE, the slave should have the master CREATE/INSERT events |
| 55 | +SET DEBUG_SYNC='now WAIT_FOR paused_on_fde'; |
| 56 | +select count(*)=1 from t1; |
| 57 | + |
| 58 | +--echo # The relay log FDE has been processed - here we check to ensure it was |
| 59 | +--echo # not considered in Seconds_Behind_Master calculation |
| 60 | +--connection slave1 |
| 61 | +let $sbm= query_get_value(SHOW SLAVE STATUS, Seconds_Behind_Master, 1); |
| 62 | +--let $t_now= `SELECT UNIX_TIMESTAMP()` |
| 63 | + |
| 64 | +if(`select $sbm > $t_now - $t_master_events_logged`) |
| 65 | +{ |
| 66 | + die "A relay log event was incorrectly used to set Seconds_Behind_Master"; |
| 67 | +} |
| 68 | + |
| 69 | +--echo # Safely resume slave SQL thread |
| 70 | +SET @@global.debug_dbug=''; |
| 71 | +SET DEBUG_SYNC='pause_sql_thread_on_fde CLEAR'; |
| 72 | +SET DEBUG_SYNC='now SIGNAL sql_thread_continue'; |
| 73 | + |
| 74 | +# Reset last sql_thread_continue signal |
| 75 | +SET DEBUG_SYNC='RESET'; |
| 76 | + |
| 77 | +# Cleanup |
| 78 | +--connection master |
| 79 | +DROP TABLE t1; |
| 80 | +--save_master_pos |
| 81 | +--sync_slave_with_master |
| 82 | + |
| 83 | +--connection slave |
| 84 | +SET @@global.debug_dbug=$save_dbug; |
| 85 | + |
| 86 | +--source include/rpl_end.inc |
0 commit comments