| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Check that the logic for re-executing statements using GTID_NEXT |
| 4 |
# works as specified. |
| 5 |
# |
| 6 |
# The following properties are tested when GTID_NEXT is set: |
| 7 |
# |
| 8 |
# - SET GTID_NEXT sets @@SESSION.GTID_OWNED. |
| 9 |
# |
| 10 |
# - COMMIT sets @@GLOBAL.GTID_EXECUTED and clears @@SESSION.GTID_OWNED. |
| 11 |
# |
| 12 |
# - ROLLBACK does not change @@GLOBAL.GTID_EXECUTED, and clears |
| 13 |
# @@SESSION.GTID_OWNED. |
| 14 |
# |
| 15 |
# - ROLLBACK TO SAVEPOINT never clears @@SESSION.GTID_OWNED |
| 16 |
# |
| 17 |
# - When one thread owns a GTID, another session that sets GTID_NEXT |
| 18 |
# to the same GTID will block. |
| 19 |
# |
| 20 |
# - When a thread rolls back, a thread waiting for ownership gains |
| 21 |
# ownership. |
| 22 |
# |
| 23 |
# - When a thread commits, a thread waiting for ownership skips the |
| 24 |
# transaction. |
| 25 |
# |
| 26 |
# ==== Implementation ==== |
| 27 |
# |
| 28 |
# We use a table where each row contains a specification of a |
| 29 |
# statement, together with a description of how we expect |
| 30 |
# @@[GLOBAL|SESSION].GTID_[DONE|OWNED] to change when the statement is |
| 31 |
# executed. |
| 32 |
# |
| 33 |
# In the "main loop", we iterate over the rows in the table. For each |
| 34 |
# row, we execute the statement and check that the @@variables are |
| 35 |
# updated as expected. |
| 36 |
# |
| 37 |
# See comment above "CREATE TABLE stmts" for details. |
| 38 |
# |
| 39 |
# ==== References ==== |
| 40 |
# |
| 41 |
# Created as part in WL#3584: Global Transaction Identifiers. |
| 42 |
--source include/not_group_replication_plugin.inc |
| 43 |
--source include/not_valgrind.inc |
| 44 |
--source include/have_debug.inc |
| 45 |
--let $rpl_extra_connections_per_server= 3 |
| 46 |
--let $rpl_gtid_utils= 1 |
| 47 |
--source include/master-slave.inc |
| 48 |
|
| 49 |
--echo #### Initialize #### |
| 50 |
|
| 51 |
CREATE table t (a INT PRIMARY KEY) ENGINE = InnoDB; |
| 52 |
INSERT INTO t VALUES (1); |
| 53 |
|
| 54 |
--echo #### Specify test cases #### |
| 55 |
|
| 56 |
# This table contains specifications of all tests we are going to |
| 57 |
# perform. It contains the connection to execute in, the statement to |
| 58 |
# execute, and the expected outcome in terms of |
| 59 |
# @@[GLOBAL|SESSION].GTID_[DONE|OWNED]. |
| 60 |
# |
| 61 |
# Columns: |
| 62 |
# id |
| 63 |
# autoinc PK. This is used only to make it easier to map lines in |
| 64 |
# the result file to what is being tested. |
| 65 |
# |
| 66 |
# connection |
| 67 |
# A number identifying the connection to use. |
| 68 |
# |
| 69 |
# stmt_type |
| 70 |
# Code specifying what type of statement to execute. Can be one of the |
| 71 |
# following: |
| 72 |
# <SIDNO>:<GNO> |
| 73 |
# Execute the statement SET GTID_NEXT="SID:GNO". |
| 74 |
# We don't want to write out full UUIDs in the specification, |
| 75 |
# because they are too long and unreadable. Instead, we use |
| 76 |
# two-digit integers as abbreviations. For instance, 37:1 is an |
| 77 |
# abbreviation for 37373737-3737-3737-3737-373737373737:1 |
| 78 |
# (cf. the functions NUMBER_TO_UUID and UUID_TO_NUMBER defined |
| 79 |
# in include/gtid_utils.inc) |
| 80 |
# CREATE, INSERT, BEGIN, COMMIT, ROLLBACK |
| 81 |
# Execute the given statement. |
| 82 |
# CREATE-NODROP |
| 83 |
# Like CREATE, this executes a CREATE TABLE, but unlike CREATE, |
| 84 |
# the statement is expected to be skipped, so we do not have to |
| 85 |
# match the statement by a DROP TABLE at the cleanup stage. |
| 86 |
# SAVEPOINT <N> |
| 87 |
# Execute SAVEPOINT SP_<N> |
| 88 |
# ROLLBACK <N> |
| 89 |
# Execute ROLLBACK TO SAVEPOINT SP_<N> |
| 90 |
# send X |
| 91 |
# Asynchronously send statement X (X is one of the |
| 92 |
# specifications above); do not wait for the result. |
| 93 |
# reap |
| 94 |
# Reap (wait for the result of) last query sent on the |
| 95 |
# connection. |
| 96 |
# running |
| 97 |
# Do nothing; just assert that the last query sent by 'send' is |
| 98 |
# still running. |
| 99 |
# |
| 100 |
# gtid_executed |
| 101 |
# Specifies how @@GLOBAL.GTID_EXECUTE is expected to change after the |
| 102 |
# statement. This has the form of a gtid_set containing the gtids |
| 103 |
# that were added by the statement. If the gtid_set begins with |
| 104 |
# '~', the gtids are expected to be removed instead. UUIDs are |
| 105 |
# abbreviated as in stmt_type (see above). |
| 106 |
# |
| 107 |
# session_gtid_owned, global_gtid_owned |
| 108 |
# Specifies how and @@[SESSION|GLOBAL].GTID_OWNED are expected to change |
| 109 |
# after the statement. These have the same form as gtid_executed |
| 110 |
# (see above). |
| 111 |
# |
| 112 |
# error |
| 113 |
# Expected errno for the statement, or 0 if the statement is |
| 114 |
# expected to succeed. |
| 115 |
CREATE TABLE stmts ( |
| 116 |
id INT PRIMARY KEY NOT NULL, |
| 117 |
connection INT NOT NULL, |
| 118 |
stmt_type TEXT(100) NOT NULL, |
| 119 |
gtid_executed TEXT(10000) NOT NULL, |
| 120 |
session_gtid_owned TEXT(10000) NOT NULL, |
| 121 |
global_gtid_owned TEXT(10000) NOT NULL, |
| 122 |
error INT NOT NULL) |
| 123 |
ENGINE = InnoDB; |
| 124 |
|
| 125 |
eval INSERT INTO stmts VALUES |
| 126 |
# ID CON STATEMENT_TYPE G.EXECUTED, S.OWNED G.OWNED ERROR |
| 127 |
# DML statements |
| 128 |
(1000, 1, '1:1', '', '1:1', '1:1', 0) |
| 129 |
,(1001, 1, 'AUTOCOMMIT=1', '', '', '', 0) |
| 130 |
,(1002, 1, 'INSERT', '1:1', '~1:1', '~1:1', 0) |
| 131 |
,(1003, 1, '1:3', '', '1:3', '1:3', 0) |
| 132 |
,(1004, 1, 'INSERT', '1:3', '~1:3', '~1:3', 0) |
| 133 |
# skipped DML statements |
| 134 |
,(1010, 1, '1:3', '', '', '', 0) |
| 135 |
,(1011, 1, 'INSERT', '', '', '', 0) |
| 136 |
,(1012, 1, '1:1', '', '', '', 0) |
| 137 |
,(1013, 1, 'INSERT', '', '', '', 0) |
| 138 |
# DDL statements |
| 139 |
,(1020, 1, '2:3', '', '2:3', '2:3', 0) |
| 140 |
,(1021, 1, 'CREATE', '2:3', '~2:3', '~2:3', 0) |
| 141 |
,(1022, 1, '2:4', '', '2:4', '2:4', 0) |
| 142 |
,(1023, 1, 'CREATE', '2:4', '~2:4', '~2:4', 0) |
| 143 |
# skipped DDL statements |
| 144 |
,(1030, 1, '2:3', '', '', '', 0) |
| 145 |
,(1031, 1, 'CREATE-NODROP', '', '', '', 0) |
| 146 |
,(1032, 1, '2:4', '', '', '', 0) |
| 147 |
,(1033, 1, 'CREATE-NODROP', '', '', '', 0) |
| 148 |
# simple transaction |
| 149 |
,(1040, 1, '4:1', '', '4:1', '4:1', 0) |
| 150 |
,(1041, 1, 'BEGIN', '', '', '', 0) |
| 151 |
,(1042, 1, 'INSERT', '', '', '', 0) |
| 152 |
,(1043, 1, 'INSERT', '', '', '', 0) |
| 153 |
,(1044, 1, 'COMMIT', '4:1', '~4:1', '~4:1', 0) |
| 154 |
# skipped simple transaction |
| 155 |
,(1050, 1, '4:1', '', '', '', 0) |
| 156 |
,(1051, 1, 'BEGIN', '', '', '', 0) |
| 157 |
,(1052, 1, 'INSERT', '', '', '', 0) |
| 158 |
,(1053, 1, 'INSERT', '', '', '', 0) |
| 159 |
,(1054, 1, 'COMMIT', '', '', '', 0) |
| 160 |
# rollback transaction |
| 161 |
,(1060, 1, '6:1', '', '6:1', '6:1', 0) |
| 162 |
,(1061, 1, 'BEGIN', '', '', '', 0) |
| 163 |
,(1062, 1, 'INSERT', '', '', '', 0) |
| 164 |
,(1063, 1, 'INSERT', '', '', '', 0) |
| 165 |
,(1064, 1, 'ROLLBACK', '', '~6:1', '~6:1', 0) |
| 166 |
# rollback to savepoint, then rollback |
| 167 |
,(1070, 1, '6:1', '', '6:1', '6:1', 0) |
| 168 |
,(1071, 1, 'BEGIN', '', '', '', 0) |
| 169 |
,(1072, 1, 'SAVEPOINT 1', '', '', '', 0) |
| 170 |
,(1073, 1, 'SAVEPOINT 2', '', '', '', 0) |
| 171 |
,(1074, 1, 'INSERT', '', '', '', 0) |
| 172 |
,(1075, 1, 'INSERT', '', '', '', 0) |
| 173 |
,(1076, 1, 'ROLLBACK 2', '', '', '', 0) |
| 174 |
,(1077, 1, 'SAVEPOINT 3', '', '', '', 0) |
| 175 |
,(1078, 1, 'INSERT', '', '', '', 0) |
| 176 |
,(1079, 1, 'SAVEPOINT 4','', '', '', 0) |
| 177 |
,(1080, 1, 'ROLLBACK 3', '', '', '', 0) |
| 178 |
,(1081, 1, 'INSERT', '', '', '', 0) |
| 179 |
,(1082, 1, 'SAVEPOINT 2', '', '', '', 0) |
| 180 |
,(1083, 1, 'ROLLBACK 2', '', '', '', 0) |
| 181 |
,(1084, 1, 'ROLLBACK 1', '', '', '', 0) |
| 182 |
,(1085, 1, 'ROLLBACK', '', '~6:1', '~6:1', 0) |
| 183 |
# empty group |
| 184 |
,(1090, 1, '9:1', '', '9:1', '9:1', 0) |
| 185 |
,(1091, 1, 'COMMIT', '9:1', '~9:1', '~9:1', 0) |
| 186 |
# skipped empty group |
| 187 |
,(1100, 1, '9:1', '', '', '', 0) |
| 188 |
,(1101, 1, 'COMMIT', '', '', '', 0) |
| 189 |
# rollback 'empty' group |
| 190 |
,(1110, 1, '11:1', '', '11:1', '11:1', 0) |
| 191 |
,(1111, 1, 'ROLLBACK', '', '~11:1', '~11:1', 0) |
| 192 |
# concurrent group: committed and skipped |
| 193 |
,(1120, 1, '12:1', '', '12:1', '12:1', 0) |
| 194 |
,(1121, 2, 'send 12:1', '', '', '', 0) |
| 195 |
,(1122, 1, 'BEGIN', '', '', '', 0) |
| 196 |
,(1123, 1, 'INSERT', '', '', '', 0) |
| 197 |
,(1124, 2, 'running', '', '', '', 0) |
| 198 |
,(1125, 1, 'COMMIT', '12:1', '~12:1', '~12:1', 0) |
| 199 |
,(1126, 2, 'reap', '12:1', '', '~12:1', 0) |
| 200 |
# concurrent group: rolled back, other thread takes over |
| 201 |
,(1130, 1, '13:1', '', '13:1', '13:1', 0) |
| 202 |
,(1131, 2, 'send 13:1', '', '', '', 0) |
| 203 |
,(1132, 1, 'BEGIN', '', '', '', 0) |
| 204 |
,(1133, 1, 'INSERT', '', '', '', 0) |
| 205 |
,(1134, 2, 'running', '', '', '', 0) |
| 206 |
,(1135, 1, 'ROLLBACK', '', '~13:1', '', 0) |
| 207 |
,(1136, 2, 'reap', '', '13:1', '', 0) |
| 208 |
,(1137, 2, 'BEGIN', '', '', '', 0) |
| 209 |
,(1138, 2, 'INSERT', '', '', '', 0) |
| 210 |
,(1139, 2, 'COMMIT', '13:1', '~13:1', '~13:1', 0) |
| 211 |
# concurrent group: rolled back, ownership transferred from 1->2->3->1 |
| 212 |
,(1140, 1, '14:1', '', '14:1', '14:1', 0) |
| 213 |
,(1141, 2, 'send 14:1', '', '', '', 0) |
| 214 |
,(1142, 1, 'BEGIN', '', '', '', 0) |
| 215 |
,(1143, 1, 'INSERT', '', '', '', 0) |
| 216 |
,(1144, 2, 'running', '', '', '', 0) |
| 217 |
,(1145, 1, 'ROLLBACK', '', '~14:1', '', 0) |
| 218 |
,(1146, 2, 'reap', '', '14:1', '', 0) |
| 219 |
,(1147, 2, 'BEGIN', '', '', '', 0) |
| 220 |
,(1148, 2, 'INSERT', '', '', '', 0) |
| 221 |
,(1149, 3, 'send 14:1', '', '', '', 0) |
| 222 |
,(1150, 3, 'running', '', '', '', 0) |
| 223 |
,(1151, 2, 'ROLLBACK', '', '~14:1', '', 0) |
| 224 |
,(1152, 3, 'reap', '', '14:1', '', 0) |
| 225 |
,(1153, 1, 'send 14:1', '', '', '', 0) |
| 226 |
,(1154, 3, 'BEGIN', '', '', '', 0) |
| 227 |
,(1155, 3, 'INSERT', '', '', '', 0) |
| 228 |
,(1156, 1, 'running', '', '', '', 0) |
| 229 |
,(1157, 3, 'ROLLBACK', '', '~14:1', '', 0) |
| 230 |
,(1158, 1, 'reap', '', '14:1', '', 0) |
| 231 |
,(1159, 1, 'BEGIN', '', '', '', 0) |
| 232 |
,(1160, 1, 'INSERT', '', '', '', 0) |
| 233 |
,(1161, 1, 'COMMIT', '14:1', '~14:1', '~14:1', 0) |
| 234 |
# concurrent group and rollback to savepoint |
| 235 |
,(1170, 1, '17:1', '', '17:1', '17:1', 0) |
| 236 |
,(1171, 2, 'send 17:1', '', '', '', 0) |
| 237 |
,(1172, 1, 'BEGIN', '', '', '', 0) |
| 238 |
,(1173, 1, 'SAVEPOINT 1', '', '', '', 0) |
| 239 |
,(1174, 1, 'INSERT', '', '', '', 0) |
| 240 |
,(1175, 1, 'ROLLBACK 1', '', '', '', 0) |
| 241 |
,(1176, 1, 'INSERT', '', '', '', 0) |
| 242 |
,(1177, 2, 'running', '', '', '', 0) |
| 243 |
,(1178, 1, 'ROLLBACK', '', '~17:1', '', 0) |
| 244 |
,(1179, 2, 'reap', '', '17:1', '', 0) |
| 245 |
,(1180, 2, 'BEGIN', '', '', '', 0) |
| 246 |
,(1181, 2, 'INSERT', '', '', '', 0) |
| 247 |
,(1182, 2, 'COMMIT', '17:1', '~17:1', '~17:1', 0) |
| 248 |
# rollback to savepoint, then commit |
| 249 |
,(1190, 1, '19:1', '', '19:1', '19:1', 0) |
| 250 |
,(1191, 1, 'BEGIN', '', '', '', 0) |
| 251 |
,(1192, 1, 'SAVEPOINT 1', '', '', '', 0) |
| 252 |
,(1193, 1, 'SAVEPOINT 2', '', '', '', 0) |
| 253 |
,(1194, 1, 'INSERT', '', '', '', 0) |
| 254 |
,(1195, 1, 'INSERT', '', '', '', 0) |
| 255 |
,(1196, 1, 'ROLLBACK 2', '', '', '', 0) |
| 256 |
,(1197, 1, 'SAVEPOINT 3', '', '', '', 0) |
| 257 |
,(1198, 1, 'INSERT', '', '', '', 0) |
| 258 |
,(1199, 1, 'SAVEPOINT 4','', '', '', 0) |
| 259 |
,(1200, 1, 'ROLLBACK 3', '', '', '', 0) |
| 260 |
,(1201, 1, 'INSERT', '', '', '', 0) |
| 261 |
,(1202, 1, 'SAVEPOINT 2', '', '', '', 0) |
| 262 |
,(1203, 1, 'ROLLBACK 2', '', '', '', 0) |
| 263 |
,(1204, 1, 'ROLLBACK 1', '', '', '', 0) |
| 264 |
,(1205, 1, 'COMMIT', '19:1', '~19:1', '~19:1', 0) |
| 265 |
# |
| 266 |
# The following is waiting for BUG#13687542 |
| 267 |
# |
| 268 |
# # failing DML in transaction |
| 269 |
# ,(1190, 1, '19:1', '', '19:1', '19:1', 0) |
| 270 |
# ,(1191, 1, 'INSERT-ERROR', '', '', '', 1062)#dup |
| 271 |
# ,(1192, 1, 'ROLLBACK', '', '~19:1', '~19:1', 0) |
| 272 |
# # failing DDL in transaction |
| 273 |
# ,(1200, 1, '20:1', '', '20:1', '20:1', 0) |
| 274 |
# ,(1201, 1, 'CREATE-ERROR', '', '', '', 1062)#dup |
| 275 |
# ,(1202, 1, 'ROLLBACK', '', '~20:1', '~20:1', 0) |
| 276 |
; |
| 277 |
|
| 278 |
# Clear binlog to get better debug info |
| 279 |
--source include/rpl_reset.inc |
| 280 |
|
| 281 |
--echo #### Test #### |
| 282 |
|
| 283 |
if (!$rpl_debug) |
| 284 |
{ |
| 285 |
--disable_query_log |
| 286 |
} |
| 287 |
--let $id= `SELECT MIN(id) FROM stmts` |
| 288 |
--let $max_id= `SELECT MAX(id) FROM stmts` |
| 289 |
while ($id <= $max_id) |
| 290 |
{ |
| 291 |
while (`SELECT COUNT(*) = 0 FROM stmts WHERE id = $id`) |
| 292 |
{ |
| 293 |
--inc $id |
| 294 |
} |
| 295 |
--echo ==== row-id = $id ==== |
| 296 |
--let $connection= `SELECT connection FROM stmts WHERE id = $id` |
| 297 |
--let $stmt_type= `SELECT stmt_type FROM stmts WHERE id = $id` |
| 298 |
--let $error= `SELECT error FROM stmts WHERE id = $id` |
| 299 |
--let $orig_stmt_type= $stmt_type |
| 300 |
|
| 301 |
--let $send_reap= |
| 302 |
if (`SELECT '$stmt_type' REGEXP '^send '`) |
| 303 |
{ |
| 304 |
--let $stmt_type= `SELECT SUBSTR('$stmt_type', 6)` |
| 305 |
--let $send_reap= send |
| 306 |
} |
| 307 |
--let $stmt= |
| 308 |
if ($stmt_type == 'reap') |
| 309 |
{ |
| 310 |
--let $send_reap= reap |
| 311 |
} |
| 312 |
if ($stmt_type == 'running') |
| 313 |
{ |
| 314 |
--let $send_reap= running |
| 315 |
} |
| 316 |
if ($stmt_type == 'INSERT') |
| 317 |
{ |
| 318 |
--let $stmt= INSERT INTO t VALUES ($id) |
| 319 |
} |
| 320 |
if ($stmt_type == 'INSERT-ERROR') |
| 321 |
{ |
| 322 |
--let $stmt= INSERT INTO t VALUES (1) |
| 323 |
} |
| 324 |
if ($stmt_type == 'CREATE') |
| 325 |
{ |
| 326 |
--let $stmt= CREATE TABLE t_$id (a INT) ENGINE = InnoDB |
| 327 |
--let $drop_stmt= $drop_stmt DROP TABLE t_$id; |
| 328 |
} |
| 329 |
if ($stmt_type == 'CREATE-ERROR') |
| 330 |
{ |
| 331 |
--let $stmt= CREATE TABLE t (a INT) ENGINE = InnoDB; |
| 332 |
} |
| 333 |
if ($stmt_type == 'CREATE-NODROP') |
| 334 |
{ |
| 335 |
--let $stmt= CREATE TABLE t_$id (a INT) ENGINE = InnoDB |
| 336 |
} |
| 337 |
if ($stmt_type == 'BEGIN') |
| 338 |
{ |
| 339 |
--let $stmt= BEGIN |
| 340 |
} |
| 341 |
if ($stmt_type == 'COMMIT') |
| 342 |
{ |
| 343 |
--let $stmt= COMMIT |
| 344 |
} |
| 345 |
if ($stmt_type == 'ROLLBACK') |
| 346 |
{ |
| 347 |
--let $stmt= ROLLBACK |
| 348 |
} |
| 349 |
if ($stmt_type == 'AUTOCOMMIT=0') |
| 350 |
{ |
| 351 |
--let $stmt= SET AUTOCOMMIT = 0 |
| 352 |
} |
| 353 |
if ($stmt_type == 'AUTOCOMMIT=1') |
| 354 |
{ |
| 355 |
--let $stmt= SET AUTOCOMMIT = 1 |
| 356 |
} |
| 357 |
if (`SELECT '$stmt_type' REGEXP '^SAVEPOINT [0-9][0-9]*'`) |
| 358 |
{ |
| 359 |
--let $stmt= `SELECT CONCAT('SAVEPOINT SP_', SUBSTR('$stmt_type', 11))` |
| 360 |
} |
| 361 |
if (`SELECT '$stmt_type' REGEXP '^ROLLBACK [0-9][0-9]*'`) |
| 362 |
{ |
| 363 |
--let $stmt= `SELECT CONCAT('ROLLBACK TO SP_', SUBSTR('$stmt_type', 10))` |
| 364 |
} |
| 365 |
if (`SELECT '$stmt_type' REGEXP '^[0-9][0-9]*:[0-9][0-9]*'`) |
| 366 |
{ |
| 367 |
--let $stmt= `SELECT CONCAT('SET GTID_NEXT = "', NUMBER_TO_UUID('$stmt_type'), '"')` |
| 368 |
} |
| 369 |
if ($stmt == '') |
| 370 |
{ |
| 371 |
if ($stmt_type != reap) |
| 372 |
{ |
| 373 |
if ($stmt_type != running) |
| 374 |
{ |
| 375 |
--echo unrecognized statement specification: stmt_type='$stmt_type' orig_stmt_type='$orig_stmt_type' stmt='$stmt' |
| 376 |
--die error in test: unrecognized statement specification |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
--let $rpl_connection_name= server_1_$connection |
| 382 |
--source include/rpl_connection.inc |
| 383 |
|
| 384 |
--let $rpl_connection_silent= 1 |
| 385 |
|
| 386 |
--echo $orig_stmt_type |
| 387 |
|
| 388 |
if ($send_reap != 'reap') |
| 389 |
{ |
| 390 |
if ($send_reap != 'running') |
| 391 |
{ |
| 392 |
SET @gtid_executed= @@GLOBAL.GTID_EXECUTED; |
| 393 |
SET @session_gtid_owned= @@SESSION.GTID_OWNED; |
| 394 |
SET @global_gtid_owned= SUBSTRING_INDEX(@@GLOBAL.GTID_OWNED, '#', 1); |
| 395 |
|
| 396 |
--let $eval_no_result= 1 |
| 397 |
--let $include_silent= 1 |
| 398 |
--let $eval_expr= SET @binlog_file_before= "[master:SHOW MASTER STATUS, File, 1]" |
| 399 |
--source include/eval.inc |
| 400 |
--let $eval_expr= SET @binlog_pos_before= [master:SHOW MASTER STATUS, Position, 1] |
| 401 |
--source include/eval.inc |
| 402 |
--let $eval_expr= SET @slave_gtid_executed= "[slave:SELECT @@GLOBAL.GTID_EXECUTED]" |
| 403 |
--source include/eval.inc |
| 404 |
--let $include_silent= 0 |
| 405 |
--let $eval_no_result= 0 |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
if ($rpl_debug) |
| 410 |
{ |
| 411 |
--echo DEBUG: stmt='$stmt' connection='$connection' send_reap='$send_reap' error='$error' |
| 412 |
} |
| 413 |
|
| 414 |
# Execute statement (or send/reap) |
| 415 |
if ($send_reap == '') |
| 416 |
{ |
| 417 |
if ($error != 0) |
| 418 |
{ |
| 419 |
# This does not work because of BUG#13687542 |
| 420 |
--error $error |
| 421 |
eval $stmt; |
| 422 |
} |
| 423 |
if ($error == 0) |
| 424 |
{ |
| 425 |
eval $stmt; |
| 426 |
} |
| 427 |
} |
| 428 |
if ($send_reap == 'send') |
| 429 |
{ |
| 430 |
--let $last_send_id= `SELECT CONNECTION_ID()` |
| 431 |
--let $last_send_stmt= $stmt |
| 432 |
--send |
| 433 |
eval $stmt; |
| 434 |
--connection master |
| 435 |
--let $wait_condition= SELECT Info = '$last_send_stmt' FROM INFORMATION_SCHEMA.PROCESSLIST WHERE Id = $last_send_id |
| 436 |
--source include/wait_condition_or_abort.inc |
| 437 |
} |
| 438 |
if ($send_reap == 'reap') |
| 439 |
{ |
| 440 |
if ($error != 0) |
| 441 |
{ |
| 442 |
--error $error |
| 443 |
reap; |
| 444 |
} |
| 445 |
if ($error == 0) |
| 446 |
{ |
| 447 |
reap; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
--let $rpl_connection_name= master |
| 452 |
--source include/rpl_connection.inc |
| 453 |
|
| 454 |
# Check that thread is still running query |
| 455 |
if ($send_reap == 'running') |
| 456 |
{ |
| 457 |
# Don't use include/assert.inc because $last_send_stmt may contain quotes |
| 458 |
--echo Checking that thread is still running query |
| 459 |
--let $info= `SELECT Info FROM INFORMATION_SCHEMA.PROCESSLIST WHERE Id = $last_send_id` |
| 460 |
if ($info != $last_send_stmt) |
| 461 |
{ |
| 462 |
--source include/show_rpl_debug_info.inc |
| 463 |
--echo info='$info' |
| 464 |
--echo last_send_stmt='$last_send_stmt' |
| 465 |
--die Error: thread was supposed to be still running query |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
# Check that variables have their expected values. |
| 470 |
if ($send_reap != 'send') |
| 471 |
{ |
| 472 |
if ($send_reap != 'running') |
| 473 |
{ |
| 474 |
--source include/sync_slave_sql_with_master.inc |
| 475 |
--connection master |
| 476 |
# Concurrent tests require two or more connections and at least one connection sends |
| 477 |
# the statements in async mode (via send/reap command). We need to make sure that |
| 478 |
# SET GTID_NEXT is completed for all connections before getting values of |
| 479 |
# GTID variables and if COMMIT/ROLLBACK executed for any connection. |
| 480 |
if (`SELECT '$stmt' REGEXP '^(COMMIT|ROLLBACK)\$'`) |
| 481 |
{ |
| 482 |
--let $wait_condition= SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State LIKE 'waiting for GTID %' |
| 483 |
--source include/wait_condition_or_abort.inc |
| 484 |
} |
| 485 |
|
| 486 |
--let $text_0= @@GLOBAL.GTID_EXECUTED |
| 487 |
--let $after_0= [server_1_$connection:SELECT @@GLOBAL.GTID_EXECUTED] |
| 488 |
--let $before_0= @gtid_executed |
| 489 |
--let $col_0= gtid_executed |
| 490 |
|
| 491 |
--let $text_1= @@SESSION.GTID_OWNED |
| 492 |
--let $after_1= [server_1_$connection:SELECT @@SESSION.GTID_OWNED] |
| 493 |
--let $before_1= @session_gtid_owned |
| 494 |
--let $col_1= session_gtid_owned |
| 495 |
|
| 496 |
--let $text_2= @@GLOBAL.GTID_OWNED |
| 497 |
--let $after_2= [server_1_$connection:SELECT SUBSTRING_INDEX(@@GLOBAL.GTID_OWNED, "#", 1)] |
| 498 |
--let $before_2= @global_gtid_owned |
| 499 |
--let $col_2= global_gtid_owned |
| 500 |
|
| 501 |
--let $text_3= slave:@@GLOBAL.GTID_EXECUTED |
| 502 |
--let $after_3= [slave: SELECT @@GLOBAL.GTID_EXECUTED] |
| 503 |
--let $before_3= @slave_gtid_executed |
| 504 |
--let $col_3= gtid_executed |
| 505 |
|
| 506 |
--let $i= 0 |
| 507 |
while ($i < 4) |
| 508 |
{ |
| 509 |
--let $text= \$text_$i |
| 510 |
--let $after= \$after_$i |
| 511 |
--let $before= \$before_$i |
| 512 |
--let $col= \$col_$i |
| 513 |
|
| 514 |
# $after = the value of the $variable now |
| 515 |
--let $eval_expr= "$after" |
| 516 |
--let $include_silent= 1 |
| 517 |
--source include/eval.inc |
| 518 |
--let $include_silent= 0 |
| 519 |
--let $after= $eval_result |
| 520 |
|
| 521 |
# $before = the value of the $variable before the statement |
| 522 |
--let $rpl_connection_name= server_1_$connection |
| 523 |
--source include/rpl_connection.inc |
| 524 |
--let $before= `SELECT $before` |
| 525 |
--let $rpl_connection_name= master |
| 526 |
--source include/rpl_connection.inc |
| 527 |
|
| 528 |
# $diff = the expected change in the variable |
| 529 |
--let $diff= `SELECT NUMBER_TO_UUID($col) FROM stmts WHERE id = $id` |
| 530 |
|
| 531 |
if ($rpl_debug) |
| 532 |
{ |
| 533 |
--echo i='$i' before='$before' diff='$diff' after='$after' |
| 534 |
} |
| 535 |
|
| 536 |
# Assert that before + diff = after |
| 537 |
let $assert_text= ` |
| 538 |
SELECT CONCAT("#$id $text: '", |
| 539 |
UUID_TO_NUMBER('$before'), "' + '", |
| 540 |
UUID_TO_NUMBER('$diff'), "' = '", |
| 541 |
UUID_TO_NUMBER('$after'), "'")`; |
| 542 |
--let $assert_cond= GTID_COMPARE("$before", "$diff", "$after") |
| 543 |
--source include/assert.inc |
| 544 |
|
| 545 |
--inc $i |
| 546 |
} |
| 547 |
|
| 548 |
# Assert that binlog changed or didn't change (according to |
| 549 |
# whether gtid_executed changed/didn't change). |
| 550 |
|
| 551 |
--let $rpl_connection_name= master |
| 552 |
--source include/rpl_connection.inc |
| 553 |
|
| 554 |
--let $changed_binlog= `SELECT gtid_executed != '' FROM stmts WHERE id = $id` |
| 555 |
if ($changed_binlog) |
| 556 |
{ |
| 557 |
let $assert_cond= |
| 558 |
[SHOW MASTER STATUS, Position, 1] > |
| 559 |
[server_1_$connection:SELECT @binlog_pos_before]; |
| 560 |
--let $assert_text= Something was written to the binlog |
| 561 |
--source include/assert.inc |
| 562 |
|
| 563 |
let $assert_cond= |
| 564 |
"[SHOW BINLOG EVENTS IN |
| 565 |
"[server_1_$connection:SELECT @binlog_file_before]" |
| 566 |
FROM [server_1_$connection:SELECT @binlog_pos_before] |
| 567 |
LIMIT 1, Event_type, 1]" = "Gtid"; |
| 568 |
--let $assert_text= The first added event in the binlog should be a Gtid_log_event |
| 569 |
--source include/assert.inc |
| 570 |
#--let $assert_cond= "[SHOW BINLOG EVENTS IN "$binlog_file_before" FROM $binlog_pos_before LIMIT 1, Info, 1]" = "SET GTID_NEXT = " |
| 571 |
} |
| 572 |
if (!$changed_binlog) |
| 573 |
{ |
| 574 |
let $assert_cond= |
| 575 |
"[SHOW MASTER STATUS, File, 1]" = |
| 576 |
"[server_1_$connection:SELECT @binlog_file_before]"; |
| 577 |
--let $assert_text= Binlog was not rotated |
| 578 |
--source include/assert.inc |
| 579 |
|
| 580 |
let $assert_cond= |
| 581 |
[SHOW MASTER STATUS, Position, 1] = |
| 582 |
[server_1_$connection:SELECT @binlog_pos_before]; |
| 583 |
--let $assert_text= Binlog position was not updated |
| 584 |
--source include/assert.inc |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
--let $rpl_connection_silent= 0 |
| 589 |
|
| 590 |
--inc $id |
| 591 |
} |
| 592 |
|
| 593 |
--enable_query_log |
| 594 |
|
| 595 |
# The following partially tests what should be tested above, in the |
| 596 |
# test cases commented-out waiting for BUG#13687542 to be fixed. When |
| 597 |
# the bug has been fixed, please uncomment the code above and remove |
| 598 |
# this. |
| 599 |
|
| 600 |
if (!$fixed_bug13687542) |
| 601 |
{ |
| 602 |
SET GTID_NEXT = 'AUTOMATIC'; |
| 603 |
CREATE TABLE t1 (a INT); |
| 604 |
eval SET GTID_NEXT = '$uuida:1'; |
| 605 |
--error ER_TABLE_EXISTS_ERROR |
| 606 |
CREATE TABLE t1 (a INT); |
| 607 |
|
| 608 |
SET GTID_NEXT = 'AUTOMATIC'; |
| 609 |
eval SET GTID_NEXT = '$uuida:1'; |
| 610 |
--error ER_DUP_ENTRY |
| 611 |
INSERT INTO t VALUES (1); |
| 612 |
|
| 613 |
SET GTID_NEXT = 'AUTOMATIC'; |
| 614 |
DROP TABLE t1; |
| 615 |
} |
| 616 |
|
| 617 |
--echo #### Clean up #### |
| 618 |
|
| 619 |
--eval $drop_stmt |
| 620 |
DROP TABLE stmts; |
| 621 |
DROP TABLE t; |
| 622 |
|
| 623 |
--source include/rpl_end.inc |