| 1 |
# |
| 2 |
# Row specific tests for master_last_event_time |
| 3 |
# |
| 4 |
--source include/have_binlog_format_row.inc |
| 5 |
--source include/have_innodb.inc |
| 6 |
--let $rpl_skip_start_slave=1 |
| 7 |
--let $rpl_topology=1->2->3 |
| 8 |
--source include/rpl_init.inc |
| 9 |
|
| 10 |
--echo # |
| 11 |
--echo # Initialize test data |
| 12 |
--echo # Ensure that all slaves has master_last_event_time == NULL |
| 13 |
--echo # |
| 14 |
|
| 15 |
--connection server_1 |
| 16 |
SET STATEMENT sql_log_bin=0 FOR create table t1 (a int) engine=innodb; |
| 17 |
--source include/save_master_pos.inc |
| 18 |
--connection server_2 |
| 19 |
SET STATEMENT sql_log_bin=0 FOR create table t1 (a int) engine=innodb; |
| 20 |
--connection server_3 |
| 21 |
SET STATEMENT sql_log_bin=0 FOR create table t1 (a int) engine=innodb; |
| 22 |
|
| 23 |
--echo # |
| 24 |
--echo # Test *_last_event_time is updated at proper place. |
| 25 |
--echo # Master_last_event_time should be updated by the IO thread when reading |
| 26 |
--echo # in a new transaction from the primary. |
| 27 |
--echo # Slave_last_event_time should be updated by the SQL thread |
| 28 |
--echo # 1) immediately upon seeing the first transaction if the replica is |
| 29 |
--echo # starting fresh, or |
| 30 |
--echo # 2) after committing a transaction. |
| 31 |
--echo # |
| 32 |
|
| 33 |
--connection server_2 |
| 34 |
start slave io_thread; |
| 35 |
--source include/sync_io_with_master.inc |
| 36 |
|
| 37 |
# Ensure Master_last_event_time and Slave_last_event_time are not yet set |
| 38 |
--let $master_time= `select Master_last_event_time from information_schema.slave_status` |
| 39 |
--echo master_time: $master_time (should be empty) |
| 40 |
--let $slave_time=`select Slave_last_event_time from information_schema.slave_status` |
| 41 |
--echo slave_time: $slave_time (should be empty) |
| 42 |
|
| 43 |
--echo # Sleep 2s to create a time gap between the header events (i.e. |
| 44 |
--echo # Format_description and Gtid_list) and the transaction event to allow |
| 45 |
--echo # proving that header events should not update |
| 46 |
--echo # (Master|Slave)_last_event_time |
| 47 |
--sleep 2 |
| 48 |
|
| 49 |
--connect (server_1_1,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 50 |
--let $t1_time_begin= `select truncate(@@timestamp,0)` |
| 51 |
--replace_result $t1_time_begin TIMESTAMP |
| 52 |
--eval set @@timestamp= $t1_time_begin |
| 53 |
insert into t1 values (0); |
| 54 |
|
| 55 |
--source include/save_master_pos.inc |
| 56 |
|
| 57 |
--connection server_2 |
| 58 |
--source include/sync_io_with_master.inc |
| 59 |
|
| 60 |
--let $mle_time= `select Master_last_event_time from information_schema.slave_status` |
| 61 |
--let $mle_time_unix= `select truncate(unix_timestamp("$mle_time"),0)` |
| 62 |
if (`SELECT ($mle_time_unix < $t1_time_begin)`) |
| 63 |
{ |
| 64 |
--echo # Expected timestamp (master binlog time): $t1_time_begin |
| 65 |
--echo # Reported Master_last_event_time: $mle_time_unix ($mle_time) |
| 66 |
--die Master_last_event_time did not correspond to time that the transaction was binlogged on primary |
| 67 |
} |
| 68 |
|
| 69 |
--let $slave_time= `select Slave_last_event_time from information_schema.slave_status` |
| 70 |
if (`select strcmp("$slave_time", "") != 0`) |
| 71 |
{ |
| 72 |
--echo # Slave_last_event_time: $slave_time |
| 73 |
--die SQL thread was never started, Slave_last_event_time should be NULL |
| 74 |
} |
| 75 |
|
| 76 |
# Check that we also get the values from show all slaves status |
| 77 |
--let $time_diff= query_get_value(SHOW ALL SLAVES STATUS, Master_Slave_time_diff, 1) |
| 78 |
if (`select strcmp("$time_diff", "NULL") != 0`) |
| 79 |
{ |
| 80 |
--echo # Master_Slave_time_diff: $time_diff |
| 81 |
--die SQL thread was never started, Master_Slave_time_diff should be NULL |
| 82 |
} |
| 83 |
|
| 84 |
--echo # For the first event, at execution start, Slave_last_event_time should |
| 85 |
--echo # be updated to be 1 second prior to the time that the first transaction |
| 86 |
--echo # was binlogged on the primary. This is to represent that the slave is |
| 87 |
--echo # otherwise up-to-date. Note the table is locked to prevent the |
| 88 |
--echo # transaction from committing (and thereby progressing |
| 89 |
--echo # Slave_last_event_time to represent commit-time). |
| 90 |
|
| 91 |
--connect (server_2_2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) |
| 92 |
lock tables t1 write; |
| 93 |
|
| 94 |
--connection server_2 |
| 95 |
start slave sql_thread; |
| 96 |
|
| 97 |
--echo # Waiting for replica to start executing the transaction (yet get stuck on the table lock) |
| 98 |
--let $wait_condition= SELECT count(*) FROM information_schema.processlist WHERE state LIKE 'Waiting for table metadata lock'; |
| 99 |
--source include/wait_condition.inc |
| 100 |
|
| 101 |
--let $slave_time= query_get_value(SHOW ALL SLAVES STATUS, Slave_last_event_time, 1) |
| 102 |
--let $slave_time_unix= `select truncate(unix_timestamp("$slave_time"),0)` |
| 103 |
--let $expected_slave_time= `select ($t1_time_begin - 1)` |
| 104 |
if ($slave_time_unix != $expected_slave_time) |
| 105 |
{ |
| 106 |
--echo # Master_last_event_time: $mle_time_unix ($mle_time) |
| 107 |
--echo # Slave_last_event_time: $slave_time_unix ($slave_time) |
| 108 |
--echo # Expected value: $expected_slave_time |
| 109 |
--die SQL thread has not yet committed its first transaction, Slave_last_event_time should be 1s before that transaction |
| 110 |
} |
| 111 |
|
| 112 |
# Master_Slave_time_diff isn't guaranteed to be 1 second, despite the |
| 113 |
# hard-coded logic to subtract 1s from the first non-group event that comes in. |
| 114 |
# This is because the Gtid and Xid events can be logged with different |
| 115 |
# timestamps, and Slave_last_event_time is updated using the Gtid log event, |
| 116 |
# and Master_last_event_time is updated using the Xid log event. So to ensure |
| 117 |
# that Master_Slave_time_diff is updated correctly for the first transaction, |
| 118 |
# it must also take into account the difference in timestamps of these events |
| 119 |
--let $xid_gtid_time_diff=`SELECT $mle_time_unix - $t1_time_begin` |
| 120 |
--let $time_diff= query_get_value(SHOW ALL SLAVES STATUS, Master_Slave_time_diff, 1) |
| 121 |
if (`SELECT $time_diff != 1 + $xid_gtid_time_diff`) |
| 122 |
{ |
| 123 |
--echo # Master_Slave_time_diff: $time_diff |
| 124 |
--echo # Xid Gtid Timestamp Difference: $xid_gtid_time_diff |
| 125 |
--die SQL thread has not yet committed its first transaction, Master_Slave_time_diff should be updated to look up-to-date prior to this trx |
| 126 |
} |
| 127 |
|
| 128 |
--connection server_2_2 |
| 129 |
unlock tables; |
| 130 |
|
| 131 |
--connection server_2 |
| 132 |
--source include/sync_with_master.inc |
| 133 |
--source master_last_event_time.inc |
| 134 |
|
| 135 |
--echo # |
| 136 |
--echo # Test simple insert |
| 137 |
--echo # |
| 138 |
|
| 139 |
--connection server_1 |
| 140 |
insert into t1 values (1+sleep(3)); |
| 141 |
--source master_last_event_time.inc |
| 142 |
|
| 143 |
--echo # |
| 144 |
--echo # Test insert with forced time |
| 145 |
--echo # |
| 146 |
|
| 147 |
SET TIMESTAMP=unix_timestamp("2000-01-01"); |
| 148 |
insert into t1 values (2+sleep(3)); |
| 149 |
SET TIMESTAMP=DEFAULT; |
| 150 |
--source master_last_event_time.inc |
| 151 |
|
| 152 |
--echo # |
| 153 |
--echo # Test multi-transaction |
| 154 |
--echo # |
| 155 |
|
| 156 |
begin; |
| 157 |
insert into t1 values (3+sleep(3)); |
| 158 |
insert into t1 values (4+sleep(3)); |
| 159 |
commit; |
| 160 |
--source master_last_event_time.inc |
| 161 |
|
| 162 |
--echo # cleanup |
| 163 |
--connection server_3 |
| 164 |
--source include/start_slave.inc |
| 165 |
--connection server_1 |
| 166 |
drop table t1; |
| 167 |
--source include/rpl_end.inc |
| 168 |
--echo # End of master_last_event_time_row |