1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
# ==== Purpose ====
#
# This test's goal is to check that no deadlock occurs in an SPCO enabled
# multi-threaded replica when client connections issue global locking or
# ACL statements concurrently with the applier worker threads.
#
# ==== Usage ====
#
# [--let $rpl_diff_statemetn = <STATEMENT>]
# The statement to be used with `include/rpl_diff.inc`. This parameter is
# mandatory.
#
# [--let $mts_spco_gd_trx_blocking_worker_1 = <STATEMENT>]
# The statement to be executed by the first available worker that will be
# blocked until all workers are waiting on the commit order.
#
# [--let $mts_spco_gd_trx_assigned_worker_2 = <STATEMENT>]
# The statement to be execute by one of the workers that should block the
# client connection.
#
# [--let $mts_spco_gd_trx_assigned_worker_3 = <STATEMENT>]
# The statement to be execute by one of the workers that should block the
# client connection.
#
# [--let $mts_spco_gd_worker_3_only_runs_after_deadlock = 0|1]
# Whether or not worker 3 should only proceed with the transaction
# execution after the deadlocak has been detected. If `0`, worker 3 will
# wait on the commit order queue before the deadlock is detected, leading
# to the use-case where both workers 2 and 3 will be force to rollback by
# the MDL graph infra-structure. If `1`, worker 3 will only start the
# transaction execution after the deadlock is detected and the coordinator
# already started the shutdown process, leading to the use-case where
# worker 2 is forced to rollback by the MDL graph infra-structure but
# worker 3 will rollback due to the commit queue infra-structure. These
# two use-cases generate a different set of error messages, hence the need
# to test each of them separately, and prohibit executing a scenario where
# either of them can happen nondeterministically.
#
# [--let $mts_spco_gd_trx_blocking_client = <STATEMENT>]
# The statement to be executed by a client connection that should be
# blocked by one or both workers waiting on the commit queue.
#
# [--let $mts_spco_gd_state_blocking_client = <STATUS text>]
# The status text for the client connection when it becomes blocked by one
# of the workers, as appears in information_schema.processlist.STATE
#
# [--let $mts_spco_gd_error_expected_replica = <ERROR>]
# The error that should be expected the replica applier to reach in order
# to not reach the deadlock, if any.
#
# [--let $mts_spco_gd_wait_for_coordinator_running_state = <STATUS text>]
# The status text to wait for the coordinator to reach before letting it
# stop, if any.
#
# [--let $mts_spco_gd_trx_to_client_unblocking_workers = <STATEMENT>]
# The statement the client connection should execute after the replica
# applier thread stopped, in order for the workers to finish applying
# after restarted.
#
# [--let $mts_spco_gd_trx_finishing_group = <STATEMENT>]
# The statement to be executed on the source to allow the replica to
# properly finish synchronizing with the master.
#
# ==== Implementation ====
#
# 1. Execute $mts_spco_gd_trx_blocking_worker_1,
# $mts_spco_gd_trx_assigned_worker_2 and
# $mts_spco_gd_trx_assigned_worker_3 on the source in a way that they
# will belong to the same commit group and scheduled to be
# parallelized on the replica.
# 2. On the replica, using client connection A, start a transaction and
# assign it the same GTID as $mts_spco_gd_trx_blocking_worker_1.
# 3. Start the replication threads
# 4. On the replica, ensure that the applier worker threads are waiting
# on the pending client connection transaction.
# 5. On the replica, using client connection B, execute
# $mts_spco_gd_trx_blocking_client (to block the first replicated
# transaction further down the execution), leading to the following
# lock acquisition dependencies: Client B --statement required lock-->
# Worker 2 --commit order lock--> Worker 1 --gtid lock--> Client A.
# 6. On the replica, ensure that client connection B is waiting on the
# lock being held by Worker 2 or Worker 3, reaching the state
# $mts_spco_gd_state_blocking_client.
# 7. On the replica, using client connection A, rollback the pending
# transaction, leading to the following lock acquisition dependencies:
# Client B --statement required lock--> Worker 2 --commit order
# lock--> Worker 1 --statement required lock--> Client B.
# 8. Wait for the client connection B to receive its return packet from
# the server.
# 9. Wait for the coordinator to reach the
# $mts_spco_gd_wait_for_coordinator_running_state state before
# allowing it to error out, if any is defined.
# 10. Wait for the replica applier thread to error out with
# $mts_spco_gd_error_expected_replica, if any is defined.
# 11. Synchronize the replica with the source.
#
# ==== References ====
#
# WL#13574 Include MDL and ACL locks in MTS deadlock detection
# infra-structure
#
--source include/have_debug_sync.inc
--source include/have_slave_repository_type_table.inc
if ($mts_spco_gd_trx_blocking_worker_1 == '')
{
--die ERROR IN TEST: you must set `mts_spco_gd_trx_blocking_worker_1` before sourcing mts_spco_generate_deadlock.test
}
if ($mts_spco_gd_error_expected_replica == '')
{
--let $mts_spco_gd_error_expected_replica = 0
}
if ($mts_spco_gd_worker_3_only_runs_after_deadlock == '')
{
--let $mts_spco_gd_worker_3_only_runs_after_deadlock = 0
}
--source include/rpl_connection_slave.inc
--let $mts_spco_gd_is_replica_sql_running = query_get_value(SHOW REPLICA STATUS, Replica_SQL_Running, 1)
if ($mts_spco_gd_is_replica_sql_running == 'Yes')
{
--die ERROR IN TEST: slave applier thread must be stopped before sourcing mts_spco_generate_deadlock.test
}
if ($mts_spco_gd_seqno_to_wait_for == '')
{
--let $mts_spco_gd_seqno_to_wait_for = 0
}
--inc $mts_spco_gd_seqno_to_wait_for
--let $mts_spco_gd_gtid_to_wait_for_1 = "aaaaaaaa-1111-bbbb-2222-cccccccccccc:$mts_spco_gd_seqno_to_wait_for"
# 1. Execute $mts_spco_gd_trx_blocking_worker_1,
# $mts_spco_gd_trx_assigned_worker_2 and
# $mts_spco_gd_trx_assigned_worker_3 on the source in a way that they
# will belong to the same commit group and scheduled to be
# parallelized on the replica.
--source include/rpl_connection_master.inc
--let $debug_point = set_commit_parent_100
--source include/add_debug_point.inc
--eval SET GTID_NEXT = $mts_spco_gd_gtid_to_wait_for_1
--eval $mts_spco_gd_trx_blocking_worker_1
SET GTID_NEXT = AUTOMATIC;
if ($mts_spco_gd_trx_assigned_worker_2 != '')
{
--inc $mts_spco_gd_seqno_to_wait_for
--let $mts_spco_gd_gtid_to_wait_for_2 = "aaaaaaaa-1111-bbbb-2222-cccccccccccc:$mts_spco_gd_seqno_to_wait_for"
--eval SET GTID_NEXT = $mts_spco_gd_gtid_to_wait_for_2
--eval $mts_spco_gd_trx_assigned_worker_2
SET GTID_NEXT = AUTOMATIC;
}
if ($mts_spco_gd_trx_assigned_worker_3 != '')
{
--inc $mts_spco_gd_seqno_to_wait_for
--let $mts_spco_gd_gtid_to_wait_for_3 = "aaaaaaaa-1111-bbbb-2222-cccccccccccc:$mts_spco_gd_seqno_to_wait_for"
--eval SET GTID_NEXT = $mts_spco_gd_gtid_to_wait_for_3
--eval $mts_spco_gd_trx_assigned_worker_3
SET GTID_NEXT = AUTOMATIC;
}
--source include/remove_debug_point.inc
# 2. On the replica, using client connection A, start a transaction and
# assign it the same GTID as to one of the statements issued on the
# source.
--source include/rpl_connection_slave.inc
--eval SET GTID_NEXT = $mts_spco_gd_gtid_to_wait_for_1
BEGIN;
if ($mts_spco_gd_trx_assigned_worker_2 != '')
{
--let $rpl_connection_name = rpl_slave_connection_2
--source include/rpl_connection.inc
--eval SET GTID_NEXT = $mts_spco_gd_gtid_to_wait_for_2
BEGIN;
}
if ($mts_spco_gd_trx_assigned_worker_3 != '')
{
--let $rpl_connection_name = rpl_slave_connection_3
--source include/rpl_connection.inc
--eval SET GTID_NEXT = $mts_spco_gd_gtid_to_wait_for_3
BEGIN;
}
--source include/rpl_connection_slave1.inc
# 3. Start the replication threads
--source include/start_slave_sql.inc
--let $client = `SELECT CONNECTION_ID()`
--let $assert_text = Replica parallel type is LOGICAL_CLOCK
--let $assert_cond = "[SELECT @@GLOBAL.replica_parallel_type]" = "LOGICAL_CLOCK"
--source include/assert.inc
--let $worker_count = `SELECT COUNT(*) FROM performance_schema.replication_applier_status_by_worker WHERE channel_name='' AND service_state="ON"`
--let $assert_text = MTS worker thread count is correct
--let $assert_cond = "3" = "$worker_count"
--source include/assert.inc
--let $assert_text = Replica preserve commit order is 1
--let $assert_cond = "[SELECT @@GLOBAL.replica_preserve_commit_order]" = "1"
--source include/assert.inc
--let $assert_text = Replica transaction retries has correct configured value
--let $assert_cond = "[SELECT @@GLOBAL.replica_transaction_retries]" = "$mts_spco_gd_transaction_retries"
--source include/assert.inc
--let $assert_text = InnoDB lock wait timeout has correct configured value
--let $assert_cond = "[SELECT @@GLOBAL.innodb_lock_wait_timeout]" = "$mts_spco_gd_innodb_wait_timeout"
--source include/assert.inc
# 4. On the replica, ensure that the applier worker threads are waiting
# on the pending client connection transaction.
if ($mts_spco_gd_trx_assigned_worker_2 != '')
{
--let $rpl_connection_name = rpl_slave_connection_2
--source include/rpl_connection.inc
ROLLBACK;
SET GTID_NEXT = AUTOMATIC;
--echo include/wait_condition.inc [First worker must wait on commit order]
--let $wait_condition = SELECT count(*) = 1 FROM information_schema.processlist WHERE STATE = "Waiting for preceding transaction to commit"
--source include/wait_condition.inc
}
if ($mts_spco_gd_trx_assigned_worker_3 != '')
{
if ($mts_spco_gd_worker_3_only_runs_after_deadlock == 0)
{
--source include/wait_condition.inc
--let $rpl_connection_name = rpl_slave_connection_3
--source include/rpl_connection.inc
ROLLBACK;
SET GTID_NEXT = AUTOMATIC;
--echo include/wait_condition.inc [Second worker must wait on commit order]
--let $wait_condition = SELECT count(*) = 2 FROM information_schema.processlist WHERE STATE = "Waiting for preceding transaction to commit"
--source include/wait_condition.inc
}
}
# 5. On the replica, using client connection B, execute
# $mts_spco_gd_trx_blocking_client (to block the first replicated
# transaction further down the execution), leading to the following
# lock acquisition dependencies: Client B --statement required lock-->
# Worker 2 --commit order lock--> Worker 1 --gtid lock--> Client A.
if ($mts_spco_gd_trx_blocking_client != '')
{
--source include/rpl_connection_slave1.inc
--send_eval $mts_spco_gd_trx_blocking_client
}
--source include/rpl_connection_slave.inc
# 6. On the replica, ensure that client connection B is waiting on the
# lock being held by Worker 2 or Worker 3, reaching the state
# $mts_spco_gd_state_blocking_client.
if ($mts_spco_gd_state_blocking_client != '')
{
--echo include/wait_condition.inc [Client connection must wait for state]
--let $_mts_spco_gd_state_blocking_client = $mts_spco_gd_state_blocking_client
if ($_mts_spco_gd_state_blocking_client == None)
{
--let $_mts_spco_gd_state_blocking_client =
}
--let $wait_condition = SELECT count(*) = 1 FROM information_schema.processlist WHERE STATE = "$_mts_spco_gd_state_blocking_client" AND ID = $client
--source include/wait_condition.inc
}
# 7. On the replica, using client connection A, rollback the pending
# transaction, leading to the following lock acquisition dependencies:
# Client B --statement required lock--> Worker 2 --commit order
# lock--> Worker 1 --statement required lock--> Client B.
ROLLBACK;
SET GTID_NEXT = AUTOMATIC;
# 8. Wait for the client connection B to receive its return packet from
# the server.
if ($mts_spco_gd_trx_blocking_client != '')
{
--source include/rpl_connection_slave1.inc
--reap
}
# 9. Wait for the coordinator to reach the
# $mts_spco_gd_wait_for_coordinator_running_state state before
# allowing it to error out, if any is defined.
if ($mts_spco_gd_wait_for_coordinator_running_state != '')
{
--let $slave_param = Slave_SQL_Running_State
--let $slave_param_value = $mts_spco_gd_wait_for_coordinator_running_state
--source include/wait_for_slave_param.inc
if ($mts_spco_gd_trx_to_client_unblocking_workers != '')
{
--source include/rpl_connection_slave1.inc
--eval $mts_spco_gd_trx_to_client_unblocking_workers
}
}
if ($mts_spco_gd_trx_assigned_worker_3 != '')
{
if ($mts_spco_gd_worker_3_only_runs_after_deadlock == 1)
{
--echo include/wait_condition.inc [Coordinator must wait for workers to stop]
--let $wait_condition = SELECT count(*) = 1 FROM information_schema.processlist WHERE STATE = "Waiting for workers to exit"
--source include/wait_condition.inc
--let $rpl_connection_name = rpl_slave_connection_3
--source include/rpl_connection.inc
ROLLBACK;
SET GTID_NEXT = AUTOMATIC;
}
}
# 10. Wait for the replica applier thread to error out with
# $mts_spco_gd_error_expected_replica, if any is defined.
if ($mts_spco_gd_error_expected_replica != 0)
{
--source include/rpl_connection_slave.inc
--let $slave_sql_errno = convert_error($mts_spco_gd_error_expected_replica)
--source include/wait_for_slave_sql_error.inc
}
if ($mts_spco_gd_trx_to_client_unblocking_workers != '')
{
--source include/rpl_connection_slave1.inc
--eval $mts_spco_gd_trx_to_client_unblocking_workers
}
if ($mts_spco_gd_trx_finishing_group != '')
{
--source include/rpl_connection_master.inc
--eval $mts_spco_gd_trx_finishing_group
}
if ($mts_spco_gd_error_expected_replica != 0)
{
--source include/rpl_connection_slave.inc
--source include/start_slave_sql.inc
}
# 11. Synchronize the replica with the source.
--source include/rpl_connection_master.inc
--source include/sync_slave_sql_with_master.inc
--source include/rpl_diff.inc
--source include/rpl_connection_master.inc
--source include/sync_slave_sql_with_master.inc
--source include/stop_slave_sql.inc
--let $mts_spco_gd_trx_blocking_worker_1 =
--let $mts_spco_gd_trx_assigned_worker_2 =
--let $mts_spco_gd_trx_assigned_worker_3 =
--let $mts_spco_gd_worker_3_only_runs_after_deadlock =
--let $mts_spco_gd_trx_blocking_client =
--let $mts_spco_gd_state_blocking_client =
--let $mts_spco_gd_wait_for_coordinator_running_state =
--let $mts_spco_gd_error_expected_replica =
--let $mts_spco_gd_trx_to_client_unblocking_workers =
--let $mts_spco_gd_trx_finishing_group =
|