1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-05 13:16:09 +03:00
Files
mariadb/mysql-test/suite/rpl/t/rpl_parallel_multi_domain_xa.test
Sergei Golubchik bead24b7f3 mariadb-test: wait on disconnect
Remove one of the major sources of race condiitons in mariadb-test.
Normally, mariadb_close() sends COM_QUIT to the server and immediately
disconnects. In mariadb-test it means the test can switch to another
connection and sends queries to the server before the server even
started parsing the COM_QUIT packet and these queries can see the
connection as fully active, as it didn't reach dispatch_command yet.

This is a major source of instability in tests and many - but not all,
still less than a half - tests employ workarounds. The correct one
is a pair count_sessions.inc/wait_until_count_sessions.inc.
Also very popular was wait_until_disconnected.inc, which was completely
useless, because it verifies that the connection is closed, and after
disconnect it always is, it didn't verify whether the server processed
COM_QUIT. Sadly the placebo was as widely used as the real thing.

Let's fix this by making mariadb-test `disconnect` command _to wait_ for
the server to confirm. This makes almost all workarounds redundant.

In some cases count_sessions.inc/wait_until_count_sessions.inc is still
needed, though, as only `disconnect` command is changed:

 * after external tools, like `exec $MYSQL`
 * after failed `connect` command
 * replication, after `STOP SLAVE`
 * Federated/CONNECT/SPIDER/etc after `DROP TABLE`

and also in some XA tests, because an XA transaction is dissociated from
the THD very late, after the server has closed the client connection.

Collateral cleanups: fix comments, remove some redundant statements:
 * DROP IF EXISTS if nothing is known to exist
 * DROP table/view before DROP DATABASE
 * REVOKE privileges before DROP USER
 etc
2025-07-16 09:14:33 +07:00

180 lines
4.7 KiB
Plaintext

# Similar to rpl_parallel_optimistic_xa to verify XA
# parallel execution with multiple gtid domain.
# References:
# MDEV-33668 Adapt parallel slave's round-robin scheduling to XA events
--source include/have_innodb.inc
--source include/have_perfschema.inc
--source include/master-slave.inc
# Tests' global declarations
--let $trx = _trx_
--let $slave_timeout= -1
call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");
call mtr.add_suppression("WSREP: handlerton rollback failed");
--connection master
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
--save_master_pos
# Prepare to restart slave into optimistic parallel mode
--connection slave
--sync_with_master
--source include/stop_slave.inc
# This test runs huge number of transactions independently in parallel that
# all conflict on a single row. This requires a large number of retries, as a
# transaction can repeatedly conflict/deadlock with a large number of other
# transactions (in a different domain) one by one.
SET @old_transaction_retries = @@GLOBAL.slave_transaction_retries;
SET @@global.slave_transaction_retries = 1000;
SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads;
SET @old_slave_domain_parallel_threads = @@GLOBAL.slave_domain_parallel_threads;
SET @@global.slave_parallel_threads = 5;
SET @@global.slave_domain_parallel_threads = 3;
SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode;
CHANGE MASTER TO master_use_gtid=slave_pos;
--connection master
CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 0);
--source include/save_master_gtid.inc
--connection slave
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
--source include/stop_slave.inc
--let $mode = 2
# mode = 2 is optimistic
SET @@global.slave_parallel_mode ='optimistic';
while ($mode)
{
--connection master
#
# create XA events alternating gtid domains to run them in parallel on slave.
#
--let $domain_num = 3
--let $trx_num = 777
--let $i = $trx_num
--let $conn = master
--disable_query_log
while($i > 0)
{
--let $domain_id = `SELECT $i % $domain_num`
--eval set @@gtid_domain_id = $domain_id
# 'decision' to commit 0, or rollback 1
--let $decision = `SELECT $i % 2`
--eval XA START '$conn$trx$i'
--eval UPDATE t1 SET b = 1 - 2 * $decision WHERE a = 1
--eval XA END '$conn$trx$i'
--eval XA PREPARE '$conn$trx$i'
--let $term = COMMIT
if ($decision)
{
--let $term = ROLLBACK
}
--eval XA $term '$conn$trx$i'
--dec $i
}
--enable_query_log
--source include/save_master_gtid.inc
--connection slave
if (`select $mode = 1`)
{
SET @@global.slave_parallel_mode ='conservative';
}
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
--source include/stop_slave.inc
--dec $mode
}
# Generations test.
# Create few ranges of XAP groups length of greater than
# 3 * slave_parallel_threads + 1
# terminated upon each range.
--let $iter = 3
--let $generation_len = @@global.slave_parallel_threads
--let $domain_num = 3
--disable_query_log
--connection master
while ($iter)
{
--let $k = `select 3 * 3 * $generation_len`
--let $_k = $k
while ($k)
{
--connect(con$k,localhost,root,,)
#
# create XA events alternating gtid domains to run them in parallel on slave.
#
--let $domain_id = `SELECT $k % $domain_num`
--eval set @@gtid_domain_id = $domain_id
--eval XA START '$trx$k'
--eval INSERT INTO t1 VALUES ($k + 1, $iter)
--eval XA END '$trx$k'
--eval XA PREPARE '$trx$k'
--disconnect con$k
--connection master
--dec $k
}
--connection master
--let $k = $_k
while ($k)
{
--let $term = COMMIT
--let $decision = `SELECT $k % 2`
if ($decision)
{
--let $term = ROLLBACK
}
--eval XA $term '$trx$k'
}
--dec $iter
}
--enable_query_log
--source include/save_master_gtid.inc
--connection slave
SET @@global.slave_parallel_mode = 'optimistic';
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
#
# Overall consistency check
#
--let $diff_tables= master:t1, slave:t1
--source include/diff_tables.inc
#
# Clean up.
#
--connection slave
--source include/stop_slave.inc
SET @@global.slave_parallel_mode = @old_parallel_mode;
SET @@global.slave_parallel_threads = @old_parallel_threads;
SET @@global.slave_domain_parallel_threads = @old_slave_domain_parallel_threads;
SET @@global.slave_transaction_retries = @old_transaction_retries;
--source include/start_slave.inc
--connection master
DROP TABLE t1;
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--connection master
--source include/rpl_end.inc