| 1 |
################################################################################ |
| 2 |
# Bug#27041759 RESET MASTER WHILE A TRX IN BGC(AFTER FLUSH) LEAVING SERVER IN |
| 3 |
# BAD GTID TATE |
| 4 |
# |
| 5 |
# Problem: When a transaction is in Binlog group commit, (flush stage is done |
| 6 |
# but third stage, commit stage, is not done yet), if some one executes |
| 7 |
# RESET MASTER, binlog will not contain the transaction (it will be |
| 8 |
# cleared by RESET MASTER), but after the transaction is committed, |
| 9 |
# transaction gtid is added to gtid_executed. And this gtid cannot be |
| 10 |
# utilized by server again even though the transaction is already |
| 11 |
# cleared from the binlog. This leaves the server in bad gtid state. |
| 12 |
# |
| 13 |
# Step to reproduce: |
| 14 |
# ------------------ |
| 15 |
# |
| 16 |
# Step-1) Initial Setup which is required for the test. |
| 17 |
# Step-2) Execute a transaction that will wait for a signal |
| 18 |
# at various stages of commit. Then execute 'RESET MASTER' |
| 19 |
# and observe binlog contents and GTID state. Repeat |
| 20 |
# the step when 'global read lock' is already acquired |
| 21 |
# by either the same thread or by some other thread |
| 22 |
# before executing 'RESET MASTER'. |
| 23 |
# Step-3) Test error cases |
| 24 |
# Step-4) Cleanup |
| 25 |
################################################################################ |
| 26 |
# Test is independent of Binlog format. One of the three formats is enough |
| 27 |
# for testing. Choosing 'Row' format. |
| 28 |
--source include/have_binlog_format_row.inc |
| 29 |
# Test has debug sync points. |
| 30 |
--source include/have_debug.inc |
| 31 |
--source include/have_debug_sync.inc |
| 32 |
|
| 33 |
# Some of the .incs in this test are only for gtid enabled test. |
| 34 |
--let $include_silent= 1 |
| 35 |
|
| 36 |
--echo # |
| 37 |
--echo # Step-1) Initial Setup which is required for the test. |
| 38 |
--echo # |
| 39 |
RESET MASTER; |
| 40 |
--source include/save_binlog_position.inc |
| 41 |
--let $gtid_mode= `SELECT @@GLOBAL.GTID_MODE` |
| 42 |
--let $gtid_event= Anonymous_Gtid |
| 43 |
if ($gtid_mode == 'ON') |
| 44 |
{ |
| 45 |
--source include/gtid_step_reset.inc |
| 46 |
--let $gtid_event= Gtid |
| 47 |
--source include/gtid_utils.inc |
| 48 |
} |
| 49 |
--echo # |
| 50 |
--echo # Step-1.1) Create four client connections. |
| 51 |
--echo # |
| 52 |
--connect(conn1,localhost,root,,test) |
| 53 |
--connect(conn2,localhost,root,,test) |
| 54 |
--connect(conn3,localhost,root,,test) |
| 55 |
--connect(conn4,localhost,root,,test) |
| 56 |
|
| 57 |
--echo # |
| 58 |
--echo # Step-1.2) Create a sample table. |
| 59 |
--echo # |
| 60 |
CREATE TABLE t1 (i INT); |
| 61 |
|
| 62 |
--echo # |
| 63 |
--echo # Step-2) Execute a simple insert transaction that will wait |
| 64 |
--echo # for a signal at various stages of transaction commit. |
| 65 |
--echo # Execute 'RESET MASTER' when it is waiting for the signal |
| 66 |
--echo # and check binlog contents and GTID_EXECUTED (if GTID |
| 67 |
--echo # enabled) that they are as expected. |
| 68 |
--echo # |
| 69 |
# Various Stages: |
| 70 |
# i = 1) Before commit takes global read lock. |
| 71 |
# (ha_commit_trans_before_acquire_commit_lock) |
| 72 |
# i = 2) After taking the lock, before entering into flush stage. |
| 73 |
# (bgc_before_flush_stage) |
| 74 |
# i = 3) After flush stage but before sync stage. |
| 75 |
# (bgc_after_flush_stage_before_sync_stage) |
| 76 |
# i = 4) After sync stage but before commit stage |
| 77 |
# (bgc_after_sync_stage_before_commit_stage) |
| 78 |
# i = 5) After commit stage is done |
| 79 |
# (bgc_after_commit_stage_before_rotation) |
| 80 |
# |
| 81 |
# Also repeat all the above steps when a thread has already acquired |
| 82 |
# 'FLUSH TABLES WITH READ LOCK' (either the same thread or some other thread), |
| 83 |
# to make sure that 'RESET MASTER' does not give any complaints. |
| 84 |
# |
| 85 |
# j = 1 , 'RESET MASTER' on a thread that did not execute |
| 86 |
# 'FLUSH TABLES WITH READ LOCK' |
| 87 |
# j = 2 , 'RESET MASTER' on a thread that already acquired |
| 88 |
# 'FLUSH TABLES WITH READ LOCK' |
| 89 |
# j = 3 , 'RESET MASTER' on a thread that did not execute |
| 90 |
# 'FLUSH TABLES WITH READ LOCK' but some other thread |
| 91 |
# has already acquired 'FLUSH TABLES WITH READ LOCK'. |
| 92 |
# |
| 93 |
--let $j= 1 |
| 94 |
while ($j <= 3) |
| 95 |
{ |
| 96 |
--let $i= 1 |
| 97 |
while ($i <= 5) |
| 98 |
{ |
| 99 |
--let $rpl_connection_name= conn1 |
| 100 |
--source include/rpl_connection.inc |
| 101 |
BEGIN; |
| 102 |
INSERT INTO t1 VALUES (1); |
| 103 |
if ($i == 1) |
| 104 |
{ |
| 105 |
SET debug_sync="ha_commit_trans_before_acquire_commit_lock SIGNAL reached WAIT_FOR insert_continue"; |
| 106 |
} |
| 107 |
if ($i == 2) |
| 108 |
{ |
| 109 |
SET debug_sync="bgc_before_flush_stage SIGNAL reached WAIT_FOR insert_continue"; |
| 110 |
} |
| 111 |
if ($i == 3) |
| 112 |
{ |
| 113 |
SET debug_sync="bgc_after_flush_stage_before_sync_stage SIGNAL reached WAIT_FOR insert_continue"; |
| 114 |
} |
| 115 |
if ($i == 4) |
| 116 |
{ |
| 117 |
SET debug_sync="bgc_after_sync_stage_before_commit_stage SIGNAL reached WAIT_FOR insert_continue"; |
| 118 |
} |
| 119 |
if ($i == 5) |
| 120 |
{ |
| 121 |
SET debug_sync="bgc_after_commit_stage_before_rotation SIGNAL reached WAIT_FOR insert_continue"; |
| 122 |
} |
| 123 |
--send COMMIT |
| 124 |
|
| 125 |
# |
| 126 |
# Step-2.1) Wait till insert query reaches debug_sync point and |
| 127 |
# generates signal 'reached'. |
| 128 |
# |
| 129 |
--let $rpl_connection_name= conn2 |
| 130 |
--source include/rpl_connection.inc |
| 131 |
SET debug_sync="now WAIT_FOR reached"; |
| 132 |
|
| 133 |
# |
| 134 |
# Step-2.2) Now, when transaction is waiting for signal, |
| 135 |
# execute 'RESET MASTER'. If this is second iteration (j = 2) |
| 136 |
# wrap 'RESET MASTER' with 'FLUSH TABLES WITH READ LOCK' |
| 137 |
# and 'UNLOCK TABLES'. |
| 138 |
if ($j == 1) |
| 139 |
{ |
| 140 |
--send RESET MASTER |
| 141 |
} |
| 142 |
if ($j != 1) |
| 143 |
{ |
| 144 |
--send FLUSH TABLES WITH READ LOCK |
| 145 |
} |
| 146 |
if ($i == 1) |
| 147 |
{ |
| 148 |
--reap |
| 149 |
SET debug_sync="now SIGNAL insert_continue"; |
| 150 |
} |
| 151 |
if ($i != 1) |
| 152 |
{ |
| 153 |
--let $rpl_connection_name= conn3 |
| 154 |
--source include/rpl_connection.inc |
| 155 |
--let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist WHERE STATE LIKE 'Waiting for commit lock' |
| 156 |
--source include/wait_condition.inc |
| 157 |
SET debug_sync="now SIGNAL insert_continue"; |
| 158 |
--let $rpl_connection_name= conn2 |
| 159 |
--source include/rpl_connection.inc |
| 160 |
--reap |
| 161 |
} |
| 162 |
if ($j == 2) |
| 163 |
{ |
| 164 |
RESET MASTER; |
| 165 |
UNLOCK TABLES; |
| 166 |
} |
| 167 |
if ($j == 3) |
| 168 |
{ |
| 169 |
--let $rpl_connection_name= conn4 |
| 170 |
--source include/rpl_connection.inc |
| 171 |
RESET MASTER; |
| 172 |
--let $rpl_connection_name= conn2 |
| 173 |
--source include/rpl_connection.inc |
| 174 |
UNLOCK TABLES; |
| 175 |
} |
| 176 |
# |
| 177 |
# Step-2.3) Wait till the transaction is finished. |
| 178 |
# |
| 179 |
--let $rpl_connection_name= conn1 |
| 180 |
--source include/rpl_connection.inc |
| 181 |
--reap |
| 182 |
|
| 183 |
# |
| 184 |
# Step-2.4) Check binlog contents and GTID state (if GTID enabled) |
| 185 |
# If 'RESET MASTER' is executed before the transaction |
| 186 |
# commit acquires 'global read lock' (i = 1 iteration), |
| 187 |
# then binlog should contain the transaction events |
| 188 |
# and one GTID should be utilized. |
| 189 |
# |
| 190 |
# If transaction commit is already in BGC (after acquiring |
| 191 |
# 'global read lock', then 'RESET MASTER' will wait for |
| 192 |
# the transaction to complete and then will do it's work. |
| 193 |
# In this case (i = 2, 3, 4, 5), binlog should be empty |
| 194 |
# and no GTIDs are utilized. |
| 195 |
if ($i == 1) |
| 196 |
{ |
| 197 |
--let $event_sequence= $gtid_event # !Begin # !Insert # !Commit |
| 198 |
--source include/assert_binlog_events.inc |
| 199 |
if ($gtid_mode == 'ON') |
| 200 |
{ |
| 201 |
--let $gtid_step_count= 1 |
| 202 |
--source include/gtid_step_assert.inc |
| 203 |
} |
| 204 |
} |
| 205 |
if ($i != 1) |
| 206 |
{ |
| 207 |
--let $event_sequence= () |
| 208 |
--source include/assert_binlog_events.inc |
| 209 |
if ($gtid_mode == 'ON') |
| 210 |
{ |
| 211 |
--let $gtid_step_count= 0 |
| 212 |
--source include/gtid_step_assert.inc |
| 213 |
} |
| 214 |
} |
| 215 |
--echo # |
| 216 |
--echo # Step-2.4) Reset the debug signals for the next iteration |
| 217 |
--echo # |
| 218 |
--let $rpl_connection_name= conn2 |
| 219 |
--source include/rpl_connection.inc |
| 220 |
SET debug_sync="RESET"; |
| 221 |
--inc $i |
| 222 |
} |
| 223 |
--inc $j |
| 224 |
} |
| 225 |
|
| 226 |
--echo # |
| 227 |
--echo # Step-3) Check that 'RESET MASTER' fails if it is executed from a |
| 228 |
--echo # session that has already acquired locks on a table. |
| 229 |
--echo # |
| 230 |
LOCK TABLE t1 READ; |
| 231 |
--error ER_LOCK_OR_ACTIVE_TRANSACTION |
| 232 |
RESET MASTER; |
| 233 |
UNLOCK TABLES; |
| 234 |
|
| 235 |
LOCK TABLE t1 WRITE; |
| 236 |
--error ER_LOCK_OR_ACTIVE_TRANSACTION |
| 237 |
RESET MASTER; |
| 238 |
UNLOCK TABLES; |
| 239 |
|
| 240 |
--echo # Step-4) Cleanup |
| 241 |
--echo # |
| 242 |
DROP TABLE t1; |
| 243 |
if ($gtid_mode == 'ON') |
| 244 |
{ |
| 245 |
--source include/gtid_utils_end.inc |
| 246 |
} |
| 247 |
--disconnect conn1 |
| 248 |
--disconnect conn2 |
| 249 |
--disconnect conn3 |
| 250 |
--disconnect conn4 |