| 1 |
# |
| 2 |
# WL#5569/7165 MTS |
| 3 |
# |
| 4 |
# The test checks START and STOP, graceful, killing or |
| 5 |
# due to an error of a Worker. |
| 6 |
# START is considered to be with UNTIL that forces the sequential execution mode |
| 7 |
# and with non-zero @@global.sql_replica_skip_counter that is compatible to |
| 8 |
# the parallel mode. |
| 9 |
# The test is MTS scheduler agnostic. |
| 10 |
# |
| 11 |
|
| 12 |
--source include/have_binlog_format_row.inc |
| 13 |
--source include/force_myisam_default.inc |
| 14 |
--source include/have_myisam.inc |
| 15 |
--source include/master-slave.inc |
| 16 |
|
| 17 |
# sql_replica_skip_counter is not supported with compression |
| 18 |
--source include/not_binlog_transaction_compression_on.inc |
| 19 |
|
| 20 |
--connection slave |
| 21 |
|
| 22 |
call mtr.add_suppression("Replica SQL for channel '':.* Could not execute Write_rows event on table test.t1"); |
| 23 |
call mtr.add_suppression("Replica SQL for channel '':.* Could not execute Update_rows event on table d1.t1; Deadlock found when trying to get lock"); |
| 24 |
call mtr.add_suppression("The replica coordinator and worker threads are stopped, possibly leaving data in inconsistent state"); |
| 25 |
|
| 26 |
create view worker_proc_list as SELECT id from Information_Schema.processlist |
| 27 |
where state like 'Waiting for an event from Coordinator'; |
| 28 |
create view coord_proc_list as SELECT id from Information_Schema.processlist where state like 'Replica has read all relay log%'; |
| 29 |
|
| 30 |
source include/stop_slave.inc; |
| 31 |
|
| 32 |
set @save.replica_parallel_workers= @@global.replica_parallel_workers; |
| 33 |
set @@global.replica_parallel_workers= 4; |
| 34 |
|
| 35 |
source include/start_slave.inc; |
| 36 |
|
| 37 |
let $count= `select @@global.replica_parallel_workers`; |
| 38 |
let $table= worker_proc_list; |
| 39 |
source include/wait_until_rows_count.inc; |
| 40 |
|
| 41 |
# |
| 42 |
# KILL of a Worker stops the pool and the Coordinator |
| 43 |
# |
| 44 |
select min(id) from worker_proc_list into @w_id; |
| 45 |
kill query @w_id; |
| 46 |
|
| 47 |
let $count= 0; |
| 48 |
let $table= worker_proc_list; |
| 49 |
source include/wait_until_rows_count.inc; |
| 50 |
|
| 51 |
--let $slave_sql_errno= convert_error(ER_MTA_INCONSISTENT_DATA) |
| 52 |
source include/wait_for_slave_sql_to_stop.inc; |
| 53 |
|
| 54 |
# |
| 55 |
# KILL of the Coordinator stops the pool as well |
| 56 |
# |
| 57 |
source include/start_slave.inc; |
| 58 |
|
| 59 |
# testing of the poll is up |
| 60 |
|
| 61 |
let $count= `select @@global.replica_parallel_workers`; |
| 62 |
let $table= worker_proc_list; |
| 63 |
source include/wait_until_rows_count.inc; |
| 64 |
|
| 65 |
let $count= 1; |
| 66 |
let $table= coord_proc_list; |
| 67 |
source include/wait_until_rows_count.inc; |
| 68 |
|
| 69 |
select id from coord_proc_list into @c_id; |
| 70 |
|
| 71 |
kill query @c_id; |
| 72 |
|
| 73 |
let $count= 0; |
| 74 |
let $table= worker_proc_list; |
| 75 |
source include/wait_until_rows_count.inc; |
| 76 |
|
| 77 |
let $slave_sql_errno= 1756; # ER_MTA_PARALLEL_INCONSISTENT_DATA |
| 78 |
source include/wait_for_slave_sql_error.inc; |
| 79 |
|
| 80 |
source include/start_slave.inc; |
| 81 |
|
| 82 |
## |
| 83 |
# Errored-out Worker stops the pool and the Coordinator |
| 84 |
## |
| 85 |
|
| 86 |
# |
| 87 |
# A. A regular error case |
| 88 |
# |
| 89 |
--connection master |
| 90 |
|
| 91 |
# make some load |
| 92 |
|
| 93 |
CREATE TABLE t1 (a int primary key) engine=innodb; |
| 94 |
|
| 95 |
insert into t1 values (1),(2); |
| 96 |
|
| 97 |
--source include/sync_slave_sql_with_master.inc |
| 98 |
#connection slave; |
| 99 |
|
| 100 |
let $count= 2; |
| 101 |
let $table= t1; |
| 102 |
source include/wait_until_rows_count.inc; |
| 103 |
|
| 104 |
# create an offending record |
| 105 |
insert into t1 values (3); |
| 106 |
|
| 107 |
--connection master |
| 108 |
|
| 109 |
# hit it |
| 110 |
insert into t1 values (3); |
| 111 |
|
| 112 |
--connection slave |
| 113 |
|
| 114 |
let $count= 0; |
| 115 |
let $table= worker_proc_list; |
| 116 |
source include/wait_until_rows_count.inc; |
| 117 |
|
| 118 |
--let $slave_sql_errno= convert_error(ER_DUP_ENTRY) |
| 119 |
source include/wait_for_slave_sql_to_stop.inc; |
| 120 |
delete from t1 where a=3; |
| 121 |
|
| 122 |
set @save.replica_transaction_retries= @@global.replica_transaction_retries; |
| 123 |
set @@global.replica_transaction_retries= 10; |
| 124 |
source include/start_slave.inc; |
| 125 |
|
| 126 |
--connection master |
| 127 |
|
| 128 |
--source include/sync_slave_sql_with_master.inc |
| 129 |
#connection slave; |
| 130 |
|
| 131 |
if (`select count(*) != 3 from t1`) |
| 132 |
{ |
| 133 |
query_vertical show slave status; |
| 134 |
--die Wrong recovery after restart |
| 135 |
} |
| 136 |
|
| 137 |
# cleanup but leaving on t1 |
| 138 |
|
| 139 |
--connection master |
| 140 |
delete from t1; |
| 141 |
|
| 142 |
--source include/sync_slave_sql_with_master.inc |
| 143 |
#connection slave; |
| 144 |
|
| 145 |
# |
| 146 |
# B. In a temporary error execution is retried |
| 147 |
# |
| 148 |
|
| 149 |
--connection master |
| 150 |
insert into t1 values (1),(2),(3); |
| 151 |
create table t2m (a int) engine=myisam; # non-trans engine to detect deadlock |
| 152 |
insert into t2m values (1); |
| 153 |
|
| 154 |
--source include/sync_slave_sql_with_master.inc |
| 155 |
#connection slave; |
| 156 |
|
| 157 |
begin; |
| 158 |
# set up a deadlock |
| 159 |
update t1 set a=31 where a=3; |
| 160 |
insert into t1 values (5),(6),(7); |
| 161 |
update t1 set a=a+10; |
| 162 |
|
| 163 |
--connection master |
| 164 |
|
| 165 |
begin; |
| 166 |
update t1 set a=20 where a=2; |
| 167 |
insert into t2m values (2); |
| 168 |
update t1 set a=30 where a=3; |
| 169 |
commit; |
| 170 |
|
| 171 |
|
| 172 |
--connection slave |
| 173 |
|
| 174 |
let $count= 2; |
| 175 |
let $table= t2m; |
| 176 |
source include/wait_until_rows_count.inc; |
| 177 |
|
| 178 |
# must victimize the master trans because of deadlock or timeout |
| 179 |
update t1 set a=21 where a=2; |
| 180 |
|
| 181 |
rollback; |
| 182 |
|
| 183 |
--connection master |
| 184 |
|
| 185 |
# recovery is proved |
| 186 |
#--connection slave |
| 187 |
--source include/sync_slave_sql_with_master.inc |
| 188 |
|
| 189 |
# |
| 190 |
# Skipping works with Parallel slave |
| 191 |
# |
| 192 |
|
| 193 |
--connection slave |
| 194 |
stop slave sql_thread; |
| 195 |
set @@global.sql_replica_skip_counter=7; |
| 196 |
|
| 197 |
--connection master |
| 198 |
|
| 199 |
# the following creates 8 events |
| 200 |
begin; |
| 201 |
select max(a) + 1 from t1 into @a; |
| 202 |
insert into t1 set a=@a; |
| 203 |
commit; |
| 204 |
begin; |
| 205 |
select max(a) + 1 from t1 into @a; |
| 206 |
insert into t1 set a=@a; |
| 207 |
commit; |
| 208 |
|
| 209 |
# which will force to skip the two above transactions by the slave |
| 210 |
# And the third will be executed: |
| 211 |
|
| 212 |
begin; |
| 213 |
select max(a) + 1 from t1 into @a; |
| 214 |
insert into t1 set a=@a; |
| 215 |
commit; |
| 216 |
|
| 217 |
--connection slave |
| 218 |
|
| 219 |
start slave sql_thread; |
| 220 |
|
| 221 |
--connection master |
| 222 |
let $a=`select max(a) from t1`; |
| 223 |
|
| 224 |
--source include/sync_slave_sql_with_master.inc |
| 225 |
#connection slave; |
| 226 |
|
| 227 |
if (`select $a - max(a) from t1`) |
| 228 |
{ |
| 229 |
eval select $a as 'max(a) from t1 on master'; |
| 230 |
eval select max(a) as 'max(a) from t1 on slave' from t1; |
| 231 |
--die Wrong skipping logics or a flaw in the test |
| 232 |
} |
| 233 |
|
| 234 |
# |
| 235 |
# UNTIL condition other than SQL_AFTER_MTS_GAPS |
| 236 |
# is not supported by Parallel slave to reject |
| 237 |
# with a warning and no Worker thread is started |
| 238 |
# |
| 239 |
|
| 240 |
--connection slave |
| 241 |
source include/stop_slave.inc; |
| 242 |
|
| 243 |
--connection master |
| 244 |
create table t2 (a int); |
| 245 |
|
| 246 |
let $master_log_file= query_get_value(SHOW MASTER STATUS, File, 1); |
| 247 |
let $master_log_pos= query_get_value(SHOW MASTER STATUS, Position, 1); |
| 248 |
|
| 249 |
insert into t2 values (1); |
| 250 |
|
| 251 |
--connection slave |
| 252 |
--replace_regex /SOURCE_LOG_POS=[0-9]+/SOURCE_LOG_POS=MASTER_LOG_POS/ |
| 253 |
eval start slave until SOURCE_LOG_FILE='$master_log_file', SOURCE_LOG_POS=$master_log_pos; |
| 254 |
|
| 255 |
source include/wait_for_slave_sql_to_stop.inc; |
| 256 |
if (`select count(*) from t2`) |
| 257 |
{ |
| 258 |
select count(*) from t2; |
| 259 |
--die Wrong UNTIL condtion handling or a flaw in the test |
| 260 |
} |
| 261 |
|
| 262 |
source include/start_slave.inc; |
| 263 |
|
| 264 |
## |
| 265 |
# cleanup |
| 266 |
## |
| 267 |
--connection master |
| 268 |
drop table t1; |
| 269 |
drop table t2m; |
| 270 |
drop table t2; |
| 271 |
|
| 272 |
--source include/sync_slave_sql_with_master.inc |
| 273 |
drop view worker_proc_list; |
| 274 |
drop view coord_proc_list; |
| 275 |
|
| 276 |
# |
| 277 |
# START SLAVE UNTIL SQL_AFTER_MTS_GAPS |
| 278 |
# |
| 279 |
# A new UNTIL condition is introduced as a tool to |
| 280 |
# fill gaps in the sequence of executed transaction started |
| 281 |
# at Exec_Master_Log_Pos. |
| 282 |
# The gaps could be caused by the previous slave session stop |
| 283 |
# with an error, or it was killed, or the server crashed. |
| 284 |
# |
| 285 |
|
| 286 |
--connection slave |
| 287 |
|
| 288 |
# |
| 289 |
# Retry is supported now, but the following block of the test is written |
| 290 |
# in assumption that it's not yet. |
| 291 |
# |
| 292 |
set @@global.replica_transaction_retries= 0; |
| 293 |
source include/stop_slave.inc; |
| 294 |
|
| 295 |
# Show SQL_AFTER_MTS_GAPS is meaningless in combination with coordinates |
| 296 |
# related options |
| 297 |
--error 1064 |
| 298 |
start slave until sql_after_mts_gaps relay_log_file='dummy'; |
| 299 |
--error 1064 |
| 300 |
start slave until sql_after_mts_gaps relay_log_pos=0; |
| 301 |
--error 1064 |
| 302 |
start slave until sql_after_mts_gaps SOURCE_LOG_FILE='dummy'; |
| 303 |
--error 1064 |
| 304 |
start slave until sql_after_mts_gaps SOURCE_LOG_POS=0; |
| 305 |
--error 1064 |
| 306 |
start slave until sql_after_mts_gaps SQL_BEFORE_GTIDS='dummy'; |
| 307 |
|
| 308 |
call mtr.add_suppression('Replica SQL for channel '': Could not execute Update_rows event on table d1.t1; Deadlock found when trying to get lock'); |
| 309 |
|
| 310 |
# regular start now |
| 311 |
source include/start_slave.inc; |
| 312 |
|
| 313 |
# set up gaps when slave sql errors out |
| 314 |
--connection master |
| 315 |
|
| 316 |
create database d1; |
| 317 |
create database d2; |
| 318 |
create table d1.t1 (a int primary key) engine=innodb; |
| 319 |
create table d2.t1 (a int primary key) engine=innodb; |
| 320 |
create table d1.t2m (a int) engine=myisam; # non-trans engine to detect deadlock |
| 321 |
insert into d1.t1 values (1),(2),(3); |
| 322 |
insert into d2.t1 values (1),(2),(3); |
| 323 |
insert into d1.t2m values (1); |
| 324 |
|
| 325 |
--source include/sync_slave_sql_with_master.inc |
| 326 |
#connection slave; |
| 327 |
begin; # the blocker |
| 328 |
# set up a deadlock at the 1st job |
| 329 |
update d1.t1 set a=31 where a=3; |
| 330 |
insert into d1.t1 values (5),(6),(7); |
| 331 |
|
| 332 |
# create the 1st job to get blocked on the slave |
| 333 |
--connection master |
| 334 |
begin; |
| 335 |
update d1.t1 set a=20 where a=2; |
| 336 |
insert into d1.t2m values (2); |
| 337 |
update d1.t1 set a=30 where a=3; |
| 338 |
insert into d1.t1 values (4); |
| 339 |
|
| 340 |
# create the 2nd job for another worker |
| 341 |
--connection master1 |
| 342 |
begin; |
| 343 |
delete from d2.t1; |
| 344 |
|
| 345 |
# the two jobs are parallelizable now regardless of the type of MTS scheduler |
| 346 |
--connection master |
| 347 |
commit; |
| 348 |
--connection master1 |
| 349 |
commit; |
| 350 |
|
| 351 |
--connection master |
| 352 |
# create the 3nd job to help UNTIL SQL_AFTER_MTS_GAPS be reached |
| 353 |
# (todo: if the last gap event ends the relay-log SQL thread will |
| 354 |
# hang - to be fixed with MTS support for regular UNTIL:s) |
| 355 |
delete from d1.t1; |
| 356 |
|
| 357 |
# wait till the 2nd job will be done |
| 358 |
connection slave1; |
| 359 |
let $count= 0; |
| 360 |
let $table= d2.t1; |
| 361 |
source include/wait_until_rows_count.inc; |
| 362 |
|
| 363 |
# proceed with 1st job into its middle |
| 364 |
--connection slave |
| 365 |
let $count= 2; |
| 366 |
let $table= d1.t2m; |
| 367 |
source include/wait_until_rows_count.inc; |
| 368 |
|
| 369 |
# must victimize the master trans because of deadlock or timeout |
| 370 |
update d1.t1 set a=21 where a=2; |
| 371 |
|
| 372 |
# slave is stopped |
| 373 |
# setting timeout to be as twice as greater than innodb's. |
| 374 |
--let $slave_timeout=`select 2*@@global.innodb_lock_wait_timeout` |
| 375 |
|
| 376 |
let $slave_sql_errno= 1213, 1205; |
| 377 |
source include/wait_for_slave_sql_error.inc; |
| 378 |
|
| 379 |
rollback; # the blocker |
| 380 |
|
| 381 |
# find out Exec_Master_Log_Pos to store it in Exec_0 |
| 382 |
let $exec_pos_0= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1); |
| 383 |
|
| 384 |
start slave until sql_after_mts_gaps; |
| 385 |
|
| 386 |
# Efficiency of UNTIL proof: |
| 387 |
source include/wait_for_slave_sql_to_stop.inc; |
| 388 |
|
| 389 |
# Consistency proof: |
| 390 |
|
| 391 |
if (`select count(*) <> 4 from d1.t1`) |
| 392 |
{ |
| 393 |
--echo *** Something is wrong in recovery *** |
| 394 |
--die |
| 395 |
} |
| 396 |
|
| 397 |
# Efficiency of gap filling proof: |
| 398 |
# find out Exec_Master_Log_Pos and compare with Exec_0 |
| 399 |
let $exec_pos_1= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1); |
| 400 |
|
| 401 |
if (`select $exec_pos_1 - $exec_pos_0 <= 0`) |
| 402 |
{ |
| 403 |
--echo *** No gap transaction is executed as expected *** |
| 404 |
--connection slave |
| 405 |
show slave status; |
| 406 |
--connection master |
| 407 |
show master status; |
| 408 |
--die |
| 409 |
} |
| 410 |
|
| 411 |
# UNTIL SQL_AFTER_MTS_GAPS cleanup |
| 412 |
--disable_warnings |
| 413 |
set @@global.replica_parallel_workers= @save.replica_parallel_workers; |
| 414 |
--enable_warnings |
| 415 |
source include/start_slave.inc; |
| 416 |
--connection master |
| 417 |
drop database d1; |
| 418 |
drop database d2; |
| 419 |
|
| 420 |
--source include/sync_slave_sql_with_master.inc |
| 421 |
set @@global.replica_transaction_retries= @save.replica_transaction_retries; |
| 422 |
|
| 423 |
--source include/rpl_end.inc |