| 1 |
# |
| 2 |
# Helper file to run through test cases to validate that the replica will stop |
| 3 |
# at the correct place when running STOP SLAVE UNTIL with options |
| 4 |
# SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS. |
| 5 |
# |
| 6 |
# MTR Parameters: |
| 7 |
# ssu_before_gtids (Boolean): Indicates whether to test SQL_BEFORE_GTIDS, |
| 8 |
# (when true), or SQL_AFTER_GTIDS (when false). |
| 9 |
# |
| 10 |
|
| 11 |
--let $include_filename= rpl_gtid_until_before_after_gtids.inc |
| 12 |
--source include/begin_include_file.inc |
| 13 |
|
| 14 |
if ($ssu_before_gtids) |
| 15 |
{ |
| 16 |
--let $ssu_opt=SQL_BEFORE_GTIDS |
| 17 |
} |
| 18 |
if (!$ssu_before_gtids) |
| 19 |
{ |
| 20 |
--let $ssu_opt=SQL_AFTER_GTIDS |
| 21 |
} |
| 22 |
|
| 23 |
--echo # |
| 24 |
--echo # Test Setup ($ssu_opt) |
| 25 |
|
| 26 |
--echo # Clean primary and replica states |
| 27 |
--connection master |
| 28 |
--source include/save_master_gtid.inc |
| 29 |
--connection slave |
| 30 |
--source include/stop_slave.inc |
| 31 |
--source include/start_slave.inc |
| 32 |
--source include/sync_with_master_gtid.inc |
| 33 |
--source include/stop_slave.inc |
| 34 |
--source include/reset_slave.inc |
| 35 |
--connection master |
| 36 |
RESET MASTER; |
| 37 |
set session gtid_domain_id=0; |
| 38 |
|
| 39 |
--echo # Initialize test data |
| 40 |
--connection master |
| 41 |
create table t1 (a int); |
| 42 |
create table t2 (a int); |
| 43 |
|
| 44 |
# Set the value counters to use on insertions. Note they are only set once per |
| 45 |
# test, subsequent invocations of this .inc file continue to increment the |
| 46 |
# previous values. |
| 47 |
if (!$t1_ctr) |
| 48 |
{ |
| 49 |
--let $t1_ctr= 100 |
| 50 |
--let $t2_ctr= 200 |
| 51 |
} |
| 52 |
|
| 53 |
--source include/save_master_gtid.inc |
| 54 |
|
| 55 |
--connection slave |
| 56 |
--source include/start_slave.inc |
| 57 |
--source include/sync_with_master_gtid.inc |
| 58 |
|
| 59 |
|
| 60 |
--echo # |
| 61 |
--echo # Test Case 1 ($ssu_opt): For a single-dimensional binlog state and a |
| 62 |
--echo # STOP SLAVE UNTIL gtid position with one GTID, the replica should |
| 63 |
if ($ssu_before_gtids) |
| 64 |
{ |
| 65 |
--echo # execute events up until the GTID is encountered, and immediately stop |
| 66 |
} |
| 67 |
if (!$ssu_before_gtids) |
| 68 |
{ |
| 69 |
--echo # execute events up until the GTID is encountered, finish replicating |
| 70 |
--echo # that event group, and then stop |
| 71 |
} |
| 72 |
|
| 73 |
--connection slave |
| 74 |
--source include/stop_slave.inc |
| 75 |
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1) |
| 76 |
|
| 77 |
--connection master |
| 78 |
set session gtid_domain_id=0; |
| 79 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 80 |
--inc $t1_ctr |
| 81 |
if ($ssu_before_gtids) |
| 82 |
{ |
| 83 |
--let $expected_stop_gtid= `SELECT @@gtid_binlog_pos` |
| 84 |
} |
| 85 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 86 |
--inc $t1_ctr |
| 87 |
--let $until_gtid= `SELECT @@gtid_binlog_pos` |
| 88 |
if (!$ssu_before_gtids) |
| 89 |
{ |
| 90 |
--let $expected_stop_gtid= `SELECT @@gtid_binlog_pos` |
| 91 |
} |
| 92 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 93 |
--inc $t1_ctr |
| 94 |
|
| 95 |
--connection slave |
| 96 |
--eval START SLAVE UNTIL $ssu_opt="$until_gtid" |
| 97 |
|
| 98 |
--echo # Ensure the slave started |
| 99 |
--let $slave_param= Exec_Master_Log_Pos |
| 100 |
--let $slave_param_comparison= != |
| 101 |
--let $slave_param_value= $initial_slave_pos |
| 102 |
--source include/wait_for_slave_param.inc |
| 103 |
--let $slave_param_comparison= = |
| 104 |
|
| 105 |
--source include/wait_for_slave_to_stop.inc |
| 106 |
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos` |
| 107 |
|
| 108 |
if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`) |
| 109 |
{ |
| 110 |
--echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid) |
| 111 |
--die Expected stop gtid != actual stop gtid |
| 112 |
} |
| 113 |
|
| 114 |
--echo # Clean replica state |
| 115 |
--connection master |
| 116 |
--source include/save_master_gtid.inc |
| 117 |
--connection slave |
| 118 |
--source include/start_slave.inc |
| 119 |
--source include/sync_with_master_gtid.inc |
| 120 |
|
| 121 |
|
| 122 |
--echo # |
| 123 |
--echo # Test Case 2 ($ssu_opt): If a provided until GTID doesn't exist in the |
| 124 |
--echo # binary log due to a gap, once an event is seen that is beyond the |
| 125 |
--echo # until GTID, the slave should immediately stop. Note the behavior of |
| 126 |
--echo # this test case should be the same between SQL_BEFORE_GTIDS and |
| 127 |
--echo # SQL_AFTER_GTIDS. |
| 128 |
|
| 129 |
--connection slave |
| 130 |
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1) |
| 131 |
--source include/stop_slave.inc |
| 132 |
|
| 133 |
--connection master |
| 134 |
set session gtid_domain_id=0; |
| 135 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 136 |
--inc $t1_ctr |
| 137 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 138 |
--inc $t1_ctr |
| 139 |
|
| 140 |
|
| 141 |
--echo # Skip a seq_no |
| 142 |
--let $binlog_pos= `SELECT @@gtid_binlog_pos` |
| 143 |
--let $domain_id= `SELECT @@gtid_domain_id` |
| 144 |
--let $server_id= `SELECT @@server_id` |
| 145 |
--let $last_seq_no= `SELECT REGEXP_SUBSTR('$binlog_pos','[0-9]+\\\$')` |
| 146 |
|
| 147 |
--let $skipped_seq_no= `SELECT ($last_seq_no + 1)` |
| 148 |
--let $new_seq_no= `SELECT ($skipped_seq_no + 1)` |
| 149 |
--eval set @@session.gtid_seq_no= $new_seq_no |
| 150 |
|
| 151 |
--let $until_gtid= $domain_id-$server_id-$skipped_seq_no |
| 152 |
--let $expected_stop_gtid= $binlog_pos |
| 153 |
|
| 154 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 155 |
--inc $t1_ctr |
| 156 |
|
| 157 |
--connection slave |
| 158 |
--eval START SLAVE UNTIL $ssu_opt="$until_gtid" |
| 159 |
|
| 160 |
--echo # Ensure the slave started |
| 161 |
--let $slave_param= Exec_Master_Log_Pos |
| 162 |
--let $slave_param_comparison= != |
| 163 |
--let $slave_param_value= $initial_slave_pos |
| 164 |
--source include/wait_for_slave_param.inc |
| 165 |
--let $slave_param_comparison= = |
| 166 |
|
| 167 |
--source include/wait_for_slave_to_stop.inc |
| 168 |
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos` |
| 169 |
|
| 170 |
if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`) |
| 171 |
{ |
| 172 |
--echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid) |
| 173 |
--die Expected stop gtid != actual stop gtid |
| 174 |
} |
| 175 |
|
| 176 |
--connection slave |
| 177 |
--source include/start_slave.inc |
| 178 |
--connection master |
| 179 |
--sync_slave_with_master |
| 180 |
|
| 181 |
|
| 182 |
--echo # |
| 183 |
--echo # Test Case 3 ($ssu_opt): For a multi-dimensional binlog state and a |
| 184 |
--echo # STOP SLAVE UNTIL gtid position with one GTID, the replica should |
| 185 |
--echo # execute events from only the specified domain until the provided GTID |
| 186 |
if ($ssu_before_gtids) |
| 187 |
{ |
| 188 |
--echo # is encountered, and immediately stop |
| 189 |
} |
| 190 |
if (!$ssu_before_gtids) |
| 191 |
{ |
| 192 |
--echo # is encountered, finish replicating that event group, and then stop |
| 193 |
} |
| 194 |
|
| 195 |
--connection slave |
| 196 |
--source include/stop_slave.inc |
| 197 |
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1) |
| 198 |
|
| 199 |
--connection master |
| 200 |
set session gtid_domain_id=0; |
| 201 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 202 |
--inc $t1_ctr |
| 203 |
|
| 204 |
set session gtid_domain_id=1; |
| 205 |
--eval INSERT INTO t2 VALUES ($t2_ctr) |
| 206 |
--inc $t2_ctr |
| 207 |
--eval INSERT INTO t2 VALUES ($t2_ctr) |
| 208 |
--inc $t2_ctr |
| 209 |
|
| 210 |
if ($ssu_before_gtids) |
| 211 |
{ |
| 212 |
# Will have GTIDs for both domains 0 and 1 |
| 213 |
--let $binlog_pos= `SELECT @@gtid_binlog_pos` |
| 214 |
--let $expected_stop_gtid= `SELECT REGEXP_SUBSTR('$binlog_pos','0-[0-9]+-[0-9]+')` |
| 215 |
} |
| 216 |
|
| 217 |
set session gtid_domain_id=0; |
| 218 |
--eval INSERT INTO t1 VALUES ($t1_ctr) |
| 219 |
--inc $t1_ctr |
| 220 |
|
| 221 |
--let $binlog_pos= `SELECT @@gtid_binlog_pos` |
| 222 |
|
| 223 |
# Just the GTID for domain 0 |
| 224 |
--let $until_gtid= `SELECT REGEXP_SUBSTR('$binlog_pos','0-[0-9]+-[0-9]+')` |
| 225 |
|
| 226 |
if (!$ssu_before_gtids) |
| 227 |
{ |
| 228 |
--let $expected_stop_gtid= $until_gtid |
| 229 |
} |
| 230 |
|
| 231 |
set session gtid_domain_id=1; |
| 232 |
--eval INSERT INTO t2 VALUES ($t2_ctr) |
| 233 |
--inc $t2_ctr |
| 234 |
set session gtid_domain_id=0; |
| 235 |
|
| 236 |
--connection slave |
| 237 |
--eval START SLAVE UNTIL $ssu_opt="$until_gtid" |
| 238 |
|
| 239 |
--echo # Ensure the slave started |
| 240 |
--let $slave_param= Exec_Master_Log_Pos |
| 241 |
--let $slave_param_comparison= != |
| 242 |
--let $slave_param_value= $initial_slave_pos |
| 243 |
--source include/wait_for_slave_param.inc |
| 244 |
--let $slave_param_comparison= = |
| 245 |
|
| 246 |
--source include/wait_for_slave_to_stop.inc |
| 247 |
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos` |
| 248 |
|
| 249 |
if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`) |
| 250 |
{ |
| 251 |
--echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid) |
| 252 |
--die Expected stop gtid != actual stop gtid |
| 253 |
} |
| 254 |
|
| 255 |
--connection slave |
| 256 |
--source include/start_slave.inc |
| 257 |
--connection master |
| 258 |
--sync_slave_with_master |
| 259 |
|
| 260 |
|
| 261 |
--echo # |
| 262 |
--echo # Test Case 4 ($ssu_opt): For a multi-dimensional binlog state and a |
| 263 |
--echo # STOP SLAVE UNTIL gtid position with multiple GTIDs, the replica should |
| 264 |
if ($ssu_before_gtids) |
| 265 |
{ |
| 266 |
--echo # for each domain, execute events only up until its provided GTID, and |
| 267 |
--echo # once all domains have hit their end point, immediately stop. |
| 268 |
} |
| 269 |
if (!$ssu_before_gtids) |
| 270 |
{ |
| 271 |
--echo # stop executing events as soon as all listed GTIDs in the UNTIL list |
| 272 |
--echo # have been executed. |
| 273 |
} |
| 274 |
|
| 275 |
--connection slave |
| 276 |
--source include/stop_slave.inc |
| 277 |
--let $initial_slave_pos= query_get_value(SHOW ALL SLAVES STATUS, Exec_Master_Log_Pos, 1) |
| 278 |
|
| 279 |
--connection master |
| 280 |
--eval SET STATEMENT gtid_domain_id=0 FOR INSERT INTO t1 VALUES ($t1_ctr) |
| 281 |
--inc $t1_ctr |
| 282 |
|
| 283 |
if ($ssu_before_gtids) |
| 284 |
{ |
| 285 |
# Save binlog pos for domain 0 |
| 286 |
--let $expected_stop_gtid_d0= `SELECT REGEXP_SUBSTR(@@global.gtid_binlog_pos,'0-[0-9]+-[0-9]+')` |
| 287 |
--echo # Tagging domain 0 stop: $expected_stop_gtid_d0 |
| 288 |
} |
| 289 |
|
| 290 |
--eval SET STATEMENT gtid_domain_id=0 FOR INSERT INTO t1 VALUES ($t1_ctr) |
| 291 |
--inc $t1_ctr |
| 292 |
|
| 293 |
--eval SET STATEMENT gtid_domain_id=1 FOR INSERT INTO t2 VALUES ($t2_ctr) |
| 294 |
--inc $t2_ctr |
| 295 |
|
| 296 |
if ($ssu_before_gtids) |
| 297 |
{ |
| 298 |
# Save binlog pos for domain 1 |
| 299 |
--let $expected_stop_gtid_d1= `SELECT REGEXP_SUBSTR(@@global.gtid_binlog_pos,'1-[0-9]+-[0-9]+')` |
| 300 |
--let $expected_stop_gtid= $expected_stop_gtid_d0,$expected_stop_gtid_d1 |
| 301 |
} |
| 302 |
|
| 303 |
--eval SET STATEMENT gtid_domain_id=1 FOR INSERT INTO t2 VALUES ($t2_ctr) |
| 304 |
--inc $t2_ctr |
| 305 |
|
| 306 |
--let $until_gtid= `SELECT @@gtid_binlog_pos` |
| 307 |
if (!$ssu_before_gtids) |
| 308 |
{ |
| 309 |
--let $expected_stop_gtid= $until_gtid |
| 310 |
} |
| 311 |
|
| 312 |
--eval SET STATEMENT gtid_domain_id=0 FOR INSERT INTO t1 VALUES ($t1_ctr) |
| 313 |
--inc $t1_ctr |
| 314 |
--eval SET STATEMENT gtid_domain_id=1 FOR INSERT INTO t2 VALUES ($t2_ctr) |
| 315 |
--inc $t2_ctr |
| 316 |
|
| 317 |
--connection slave |
| 318 |
--eval START SLAVE UNTIL $ssu_opt="$until_gtid" |
| 319 |
|
| 320 |
--echo # Ensure the slave started |
| 321 |
--let $slave_param= Exec_Master_Log_Pos |
| 322 |
--let $slave_param_comparison= != |
| 323 |
--let $slave_param_value= $initial_slave_pos |
| 324 |
--source include/wait_for_slave_param.inc |
| 325 |
--let $slave_param_comparison= = |
| 326 |
|
| 327 |
--source include/wait_for_slave_to_stop.inc |
| 328 |
--let $actual_stop_gtid= `SELECT @@gtid_slave_pos` |
| 329 |
|
| 330 |
if (`SELECT strcmp("$expected_stop_gtid","$actual_stop_gtid") != 0`) |
| 331 |
{ |
| 332 |
--echo # Expected stop gtid != actual stop gtid ($expected_stop_gtid != $actual_stop_gtid) |
| 333 |
--die Expected stop gtid != actual stop gtid |
| 334 |
} |
| 335 |
|
| 336 |
--connection slave |
| 337 |
--source include/start_slave.inc |
| 338 |
--connection master |
| 339 |
--sync_slave_with_master |
| 340 |
|
| 341 |
|
| 342 |
--echo # |
| 343 |
--echo # Error Case 1: Not providing a valid GTID should result in a syntax |
| 344 |
--echo # error |
| 345 |
|
| 346 |
--connection slave |
| 347 |
--source include/stop_slave.inc |
| 348 |
|
| 349 |
--error ER_INCORRECT_GTID_STATE |
| 350 |
--eval START SLAVE UNTIL $ssu_opt="a" |
| 351 |
|
| 352 |
--error ER_INCORRECT_GTID_STATE |
| 353 |
--eval START SLAVE UNTIL $ssu_opt="0" |
| 354 |
|
| 355 |
--error ER_INCORRECT_GTID_STATE |
| 356 |
--eval START SLAVE UNTIL $ssu_opt="0-1" |
| 357 |
|
| 358 |
--error ER_INCORRECT_GTID_STATE |
| 359 |
--eval START SLAVE UNTIL $ssu_opt="0-1-" |
| 360 |
|
| 361 |
--error ER_INCORRECT_GTID_STATE |
| 362 |
--eval START SLAVE UNTIL $ssu_opt="a-b-c" |
| 363 |
|
| 364 |
--source include/start_slave.inc |
| 365 |
|
| 366 |
--echo # |
| 367 |
--echo # Cleanup test data |
| 368 |
--connection master |
| 369 |
DROP TABLE t1, t2; |
| 370 |
--source include/save_master_gtid.inc |
| 371 |
--connection slave |
| 372 |
--source include/sync_with_master_gtid.inc |
| 373 |
|
| 374 |
--let $include_filename= rpl_gtid_until_before_after_gtids.inc |
| 375 |
--source include/end_include_file.inc |