| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# This test will verify if the IO thread will correctly handle the GTID and |
| 4 |
# the transaction boundary of transactions spanned along multiple relay log |
| 5 |
# files. |
| 6 |
# |
| 7 |
# This test starts creating a single transaction (CREATE TABLE), and then |
| 8 |
# sets a debug point that will make the IO thread to stop after queuing an |
| 9 |
# QUERY_LOG_EVENT. The test will stop the SQL thread after syncing with the |
| 10 |
# master. |
| 11 |
# |
| 12 |
# The test will then apply a transaction composed by three INSERT statements |
| 13 |
# that will be logged on master as one GTID_LOG_EVENT, four QUERY_LOG_EVENTS |
| 14 |
# (the BEGIN plus the three INSERT) and a XID_LOG_EVENT. |
| 15 |
# |
| 16 |
# By disabling GTID auto positioning, and restating the IO thread after each |
| 17 |
# time it stops because of the debug point, we guarantee that GTID+BEGIN will |
| 18 |
# be in one relay log file, each INSERT will be alone in distinct relay log |
| 19 |
# files and the XID will finalize the transaction in another relay log file. |
| 20 |
# |
| 21 |
# Finally, the test will restart the MySQL slave server to make it recover the |
| 22 |
# Retrieved_Gtid_Set from the relay log with the spanned transaction. |
| 23 |
# |
| 24 |
# ==== Related Bugs and Worklogs ==== |
| 25 |
# |
| 26 |
# BUG#17943188: SHOW SLAVE STATUS/RETRIEVED_GTID_SET MAY HAVE PARTIAL TRX OR |
| 27 |
# MISS COMPLETE TRX |
| 28 |
# |
| 29 |
|
| 30 |
# This test should run only on debug build |
| 31 |
--source include/have_debug.inc |
| 32 |
# This test uses debug sync to stop the IO thread in the middle of a transaction |
| 33 |
--source include/have_debug_sync.inc |
| 34 |
|
| 35 |
--source include/have_binlog_format_statement.inc |
| 36 |
--let $rpl_gtid_utils= 1 |
| 37 |
--source include/master-slave.inc |
| 38 |
|
| 39 |
# Disable GTID auto positioning |
| 40 |
--source include/rpl_connection_slave.inc |
| 41 |
--source include/stop_slave.inc |
| 42 |
CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION= 0; |
| 43 |
--source include/start_slave.inc |
| 44 |
|
| 45 |
--source include/rpl_connection_master.inc |
| 46 |
CREATE TABLE t1 (c1 INT) ENGINE= InnoDB; |
| 47 |
|
| 48 |
--source include/sync_slave_sql_with_master.inc |
| 49 |
# We stop the SQL thread as we don't want it to apply the transaction to be |
| 50 |
# replicated before the recovery |
| 51 |
--source include/stop_slave_sql.inc |
| 52 |
|
| 53 |
--let $debug_point= stop_io_after_reading_query_log_event |
| 54 |
--source include/add_debug_point.inc |
| 55 |
|
| 56 |
--source include/rpl_connection_master.inc |
| 57 |
--let $inserts= 3 |
| 58 |
--let $counter= 0 |
| 59 |
# This transaction should be spanned on every query log event: |
| 60 |
# - 1 x BEGIN; |
| 61 |
# - 3 x INSERT; |
| 62 |
BEGIN; |
| 63 |
while ($counter < $inserts) |
| 64 |
{ |
| 65 |
--inc $counter |
| 66 |
--eval INSERT INTO t1 VALUES ($counter) |
| 67 |
} |
| 68 |
COMMIT; |
| 69 |
--eval INSERT INTO t1 VALUES ($counter + 1) |
| 70 |
|
| 71 |
# We now span the transaction along distinct relay log files |
| 72 |
--source include/rpl_connection_slave.inc |
| 73 |
--let $restarts= $inserts |
| 74 |
# The amount of restarts is the amount of INSERT + 1 (BEGIN) |
| 75 |
--inc $restarts |
| 76 |
while ($restarts > 0) |
| 77 |
{ |
| 78 |
# Waiting for replica IO thread to stop |
| 79 |
--source include/wait_for_slave_io_to_stop.inc |
| 80 |
--dec $restarts |
| 81 |
# At this point, the Retrieved_Gtid_Set should have only one GTID |
| 82 |
--let $retrieved_gtids= query_get_value(SHOW SLAVE STATUS, Retrieved_Gtid_Set, 1) |
| 83 |
--let $assert_text= Exactly one GTID should have been retrieved before having all the transaction |
| 84 |
--let $assert_cond= GTID_COUNT("$retrieved_gtids") = 1 |
| 85 |
--source include/assert.inc |
| 86 |
# |
| 87 |
if ($restarts == 0) |
| 88 |
{ |
| 89 |
--source include/remove_debug_point.inc |
| 90 |
} |
| 91 |
# We should not use "start_slave_io.inc" here because the IO thread |
| 92 |
# will stop just a few events after starting. |
| 93 |
START SLAVE IO_THREAD; |
| 94 |
} |
| 95 |
|
| 96 |
--source include/rpl_connection_master.inc |
| 97 |
--source include/sync_slave_io_with_master.inc |
| 98 |
|
| 99 |
# At this point, the Retrieved_Gtid_Set should have three GTIDs |
| 100 |
# One for the CREATE TABLE, one for the transaction with the split |
| 101 |
# INSERT and one for the last INSERT |
| 102 |
--let $retrieved_gtids= query_get_value(SHOW SLAVE STATUS, Retrieved_Gtid_Set, 1) |
| 103 |
--let $assert_text= Exactly three GTIDs should have been retrieved from master before restarting |
| 104 |
--let $assert_cond= GTID_COUNT("$retrieved_gtids") = 3 |
| 105 |
--source include/assert.inc |
| 106 |
|
| 107 |
# Restart the slave to verify the spanned transaction |
| 108 |
--let $rpl_server_number= 2 |
| 109 |
--let $rpl_force_stop= 0 |
| 110 |
--source include/rpl_stop_server.inc |
| 111 |
--source include/rpl_start_server.inc |
| 112 |
|
| 113 |
# As we restarted the whole slave server with the spanned transaction fully |
| 114 |
# replicated but without any additional relay log rotation, there is no |
| 115 |
# PREVIOUS_GTID_LOG_EVENT on the relay log stating that the GTID of the |
| 116 |
# spanned transaction was retrieved. The slave will have to scan this info |
| 117 |
# during the relay log recovery. |
| 118 |
|
| 119 |
--source include/start_slave.inc |
| 120 |
--source include/rpl_connection_master.inc |
| 121 |
--source include/sync_slave_io_with_master.inc |
| 122 |
# At this point, the Retrieved_Gtid_Set should have three GTIDs |
| 123 |
--let $retrieved_gtids= query_get_value(SHOW SLAVE STATUS, Retrieved_Gtid_Set, 1) |
| 124 |
--let $assert_text= Exactly two GTIDs should have been retrieved from master after restarting |
| 125 |
--let $assert_cond= GTID_COUNT("$retrieved_gtids") = 3 |
| 126 |
--source include/assert.inc |
| 127 |
|
| 128 |
# Cleanup |
| 129 |
--source include/rpl_connection_master.inc |
| 130 |
DROP TABLE t1; |
| 131 |
|
| 132 |
--source include/rpl_end.inc |