| 1 |
# The tests verify concurrent execution of replicated (MDEV-742) |
| 2 |
# XA transactions in the parallel optimistic mode. |
| 3 |
|
| 4 |
--source include/have_innodb.inc |
| 5 |
--source include/have_perfschema.inc |
| 6 |
--source include/master-slave.inc |
| 7 |
|
| 8 |
# Tests' global declarations |
| 9 |
--let $trx = _trx_ |
| 10 |
|
| 11 |
call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); |
| 12 |
call mtr.add_suppression("WSREP: handlerton rollback failed"); |
| 13 |
#call mtr.add_suppression("Can't find record in 't1'"); |
| 14 |
CREATE VIEW v_processlist as SELECT * FROM performance_schema.threads where type = 'FOREGROUND'; |
| 15 |
|
| 16 |
--connection master |
| 17 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 18 |
--save_master_pos |
| 19 |
|
| 20 |
# Prepare to restart slave into optimistic parallel mode |
| 21 |
--connection slave |
| 22 |
--sync_with_master |
| 23 |
--source include/stop_slave.inc |
| 24 |
SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads; |
| 25 |
SET @@global.slave_parallel_threads = 7; |
| 26 |
SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode; |
| 27 |
SET @@global.slave_parallel_mode ='optimistic'; |
| 28 |
# Run the first part of the test with high batch size and see that |
| 29 |
# old rows remain in the table. |
| 30 |
SET @old_gtid_cleanup_batch_size = @@GLOBAL.gtid_cleanup_batch_size; |
| 31 |
SET @@global.gtid_cleanup_batch_size = 1000000; |
| 32 |
|
| 33 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 34 |
|
| 35 |
# LOAD GENERATOR creates XA:s interleaved in binlog when they are from |
| 36 |
# different connections. All the following block XA:s of the same connection |
| 37 |
# update the same data which challenges slave optimistic scheduler's correctness. |
| 38 |
# Slave must eventually apply such load, and correctly (checked). |
| 39 |
|
| 40 |
--connection master |
| 41 |
CREATE TABLE t0 (a int, b INT) ENGINE=InnoDB; |
| 42 |
CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; |
| 43 |
INSERT INTO t1 VALUES (1, 0); |
| 44 |
|
| 45 |
|
| 46 |
# I. Logging some sequence of XA:s by one connection. |
| 47 |
# |
| 48 |
# The slave applier's task is to successfully execute a series of |
| 49 |
# Prepare and Complete parts of a sequence of XA:s |
| 50 |
|
| 51 |
--let $trx_num = 300 |
| 52 |
--let $i = $trx_num |
| 53 |
--let $conn = master |
| 54 |
--disable_query_log |
| 55 |
while($i > 0) |
| 56 |
{ |
| 57 |
# 'decision' to commit 0, or rollback 1 |
| 58 |
--let $decision = `SELECT $i % 2` |
| 59 |
--eval XA START '$conn$trx$i' |
| 60 |
--eval UPDATE t1 SET b = 1 - 2 * $decision WHERE a = 1 |
| 61 |
--eval XA END '$conn$trx$i' |
| 62 |
--let $one_phase = `SELECT IF(floor(rand()*10)%2, "ONE PHASE", 0)` |
| 63 |
if (!$one_phase) |
| 64 |
{ |
| 65 |
--eval XA PREPARE '$conn$trx$i' |
| 66 |
--let $one_phase = |
| 67 |
} |
| 68 |
|
| 69 |
--let $term = COMMIT |
| 70 |
if ($decision) |
| 71 |
{ |
| 72 |
--let $term = ROLLBACK |
| 73 |
--let $one_phase = |
| 74 |
} |
| 75 |
--eval XA $term '$conn$trx$i' $one_phase |
| 76 |
|
| 77 |
--dec $i |
| 78 |
} |
| 79 |
--enable_query_log |
| 80 |
--source include/save_master_gtid.inc |
| 81 |
|
| 82 |
--connection slave |
| 83 |
--source include/start_slave.inc |
| 84 |
--source include/sync_with_master_gtid.inc |
| 85 |
--source include/stop_slave.inc |
| 86 |
|
| 87 |
|
| 88 |
# II. Logging XS:s from multiple connections in random interweaving manner: |
| 89 |
# |
| 90 |
# in a loop ($i) per connection |
| 91 |
# arrange an inner ($k) loop where |
| 92 |
# start and prepare an XA; |
| 93 |
# decide whether to terminate it and then continue to loop innerly |
| 94 |
# OR disconnect to break the inner loop; |
| 95 |
# the disconnected one's XA is taken care by 'master' connection |
| 96 |
# |
| 97 |
# Effectively binlog must collect a well mixed XA- prepared and terminated |
| 98 |
# groups for slave to handle. |
| 99 |
|
| 100 |
--connection master |
| 101 |
# Total # of connections |
| 102 |
--let $conn_num=53 |
| 103 |
|
| 104 |
--let $i = $conn_num |
| 105 |
--disable_query_log |
| 106 |
while($i > 0) |
| 107 |
{ |
| 108 |
--connect (master_conn$i, 127.0.0.1,root,,test,$MASTER_MYPORT,) |
| 109 |
--dec $i |
| 110 |
} |
| 111 |
--enable_query_log |
| 112 |
|
| 113 |
--let $i = $conn_num |
| 114 |
while($i > 0) |
| 115 |
{ |
| 116 |
--let $conn_i = conn$i |
| 117 |
# $i2 indexes the current connection's "own" row |
| 118 |
--let $i2 = `SELECT $i + 2` |
| 119 |
--disable_query_log |
| 120 |
--connection master_conn$i |
| 121 |
--enable_query_log |
| 122 |
--disable_query_log |
| 123 |
--let $i_conn_id = `SELECT connection_id()` |
| 124 |
|
| 125 |
--let $decision = 0 |
| 126 |
# the row id of the last connection that committed its XA |
| 127 |
--let $c_max = 1 |
| 128 |
--let $k = 0 |
| 129 |
while ($decision < 3) |
| 130 |
{ |
| 131 |
--inc $k |
| 132 |
--eval XA START '$conn_i$trx$k' |
| 133 |
# UPDATE depends on previously *committed* transactions |
| 134 |
--eval UPDATE t1 SET b = b + $k + 1 WHERE a = $c_max |
| 135 |
if (`SELECT $k % 2 = 1`) |
| 136 |
{ |
| 137 |
--eval REPLACE INTO t1 VALUES ($i2, $k) |
| 138 |
} |
| 139 |
if (`SELECT $k % 2 = 0`) |
| 140 |
{ |
| 141 |
--eval DELETE FROM t1 WHERE a = $i2 |
| 142 |
} |
| 143 |
CREATE TEMPORARY TABLE tmp LIKE t0; |
| 144 |
--eval INSERT INTO tmp SET a=$i, b= $k |
| 145 |
INSERT INTO t0 SELECT * FROM tmp; |
| 146 |
DROP TEMPORARY TABLE tmp; |
| 147 |
--eval XA END '$conn_i$trx$k' |
| 148 |
|
| 149 |
--let $term = COMMIT |
| 150 |
--let $decision = `SELECT (floor(rand()*10 % 10) + ($i+$k)) % 4` |
| 151 |
if ($decision == 1) |
| 152 |
{ |
| 153 |
--let $term = ROLLBACK |
| 154 |
} |
| 155 |
if ($decision < 2) |
| 156 |
{ |
| 157 |
--eval XA PREPARE '$conn_i$trx$k' |
| 158 |
--eval XA $term '$conn_i$trx$k' |
| 159 |
# Iteration counter is taken care *now* |
| 160 |
} |
| 161 |
if ($decision == 2) |
| 162 |
{ |
| 163 |
--eval XA COMMIT '$conn_i$trx$k' ONE PHASE |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
# $decision = 3 |
| 168 |
--eval XA PREPARE '$conn_i$trx$k' |
| 169 |
# disconnect now |
| 170 |
--disconnect master_conn$i |
| 171 |
--connection master |
| 172 |
|
| 173 |
--let $wait_condition= SELECT count(*) = 0 FROM v_processlist WHERE PROCESSLIST_ID = $i_conn_id |
| 174 |
--source include/wait_condition.inc |
| 175 |
|
| 176 |
--disable_query_log |
| 177 |
--let $decision = `SELECT ($i+$k) % 2` |
| 178 |
--let $term = COMMIT |
| 179 |
if ($decision == 1) |
| 180 |
{ |
| 181 |
--let $term = ROLLBACK |
| 182 |
} |
| 183 |
--eval XA $term '$conn_i$trx$k' |
| 184 |
--let $c_max = $i2 |
| 185 |
|
| 186 |
--dec $i |
| 187 |
} |
| 188 |
--enable_query_log |
| 189 |
--source include/save_master_gtid.inc |
| 190 |
|
| 191 |
--connection slave |
| 192 |
--source include/start_slave.inc |
| 193 |
--source include/sync_with_master_gtid.inc |
| 194 |
|
| 195 |
# |
| 196 |
# Overall consistency check |
| 197 |
# |
| 198 |
--let $diff_tables= master:t0, slave:t0 |
| 199 |
--source include/diff_tables.inc |
| 200 |
--let $diff_tables= master:t1, slave:t1 |
| 201 |
--source include/diff_tables.inc |
| 202 |
|
| 203 |
|
| 204 |
# |
| 205 |
# Clean up. |
| 206 |
# |
| 207 |
--connection slave |
| 208 |
--source include/stop_slave.inc |
| 209 |
SET GLOBAL slave_parallel_mode=@old_parallel_mode; |
| 210 |
SET GLOBAL slave_parallel_threads=@old_parallel_threads; |
| 211 |
--source include/start_slave.inc |
| 212 |
|
| 213 |
--connection master |
| 214 |
DROP VIEW v_processlist; |
| 215 |
DROP TABLE t0, t1; |
| 216 |
--source include/save_master_gtid.inc |
| 217 |
|
| 218 |
--connection slave |
| 219 |
--source include/sync_with_master_gtid.inc |
| 220 |
# Check that old rows are deleted from mysql.gtid_slave_pos. |
| 221 |
# Deletion is asynchronous, so use wait_condition.inc. |
| 222 |
# Also, there is a small amount of non-determinism in the deletion of old |
| 223 |
# rows, so it is not guaranteed that there can never be more than |
| 224 |
# @@gtid_cleanup_batch_size rows in the table; so allow a bit of slack |
| 225 |
# here. |
| 226 |
let $wait_condition= |
| 227 |
SELECT COUNT(*) <= 5*@@GLOBAL.gtid_cleanup_batch_size |
| 228 |
FROM mysql.gtid_slave_pos; |
| 229 |
--source include/wait_condition.inc |
| 230 |
eval $wait_condition; |
| 231 |
SET GLOBAL gtid_cleanup_batch_size= @old_gtid_cleanup_batch_size; |
| 232 |
|
| 233 |
--connection master |
| 234 |
--source include/rpl_end.inc |