mariadb/mysql-test/suite/galera/t/galera_2primary_replica.test
Jan Lindström 133e26fd7d MDEV-34924 : gtid_slave_pos table neven been deleted on non replica nodes (wsrep_gtid_mode = 1)
Problem was caused by MDEV-31413 commit 277968aa where
mysql.gtid_slave_pos table was replicated by Galera.
However, as not all nodes in Galera cluster are replica
nodes, rows were not deleted from table.

In this fix this is corrected so that mysql.gtid_slave_pos
table is not replicated by Galera. Instead when Galera
node receives GTID event and wsrep_gtid_mode=1, this event
is stored to mysql.gtid_slave_pos table.

Added test case galera_2primary_replica for 2 async
primaries replicating to galera cluster.

Added test case galera_circular_replication where
async primary replicates to galera cluster and
one of the galera cluster nodes is master
to async replica.

Modified test case galera_restart_replica to monitor
gtid positions and rows in mysql.gtid_pos_table.
2025-01-13 19:14:26 +01:00

170 lines
5.8 KiB
Text

#
# Test two primary nodes async replication to Galera cluster
#
# primary1 primary2
# #3 #4
# | |
# | async replication v
# +-------------------+ +----------------+
# | |
# v v
# galera replica <------galera replication-------->galera node_2
# #1 #2
#
# Test outline
#
# - Create user for async replication and table with rows in both primaries
# - Verify that tables and rows are replicated to all Galera nodes
# - Verify that gtid position is same in all Galera nodes
#
# The galera/galera_2nodes_as_replica_2primary.cnf describes the setup of the nodes
#
--source include/force_restart.inc
--source include/galera_cluster.inc
--source include/have_innodb.inc
# As node #3 and #4 are not a Galera node, and galera_cluster.inc does not open connetion to it
# we open the connections here
--connect primary1, 127.0.0.1, root, , test, $NODE_MYPORT_3
--connect primary2, 127.0.0.1, root, , test, $NODE_MYPORT_4
--connection primary1
--echo # Primary1 creating user for replication
create user repl@'%' identified by 'repl';
grant all on *.* to repl@'%';
--connection primary2
--echo # Primary2 creating user for replication
create user repl2@'%' identified by 'repl2';
grant all on *.* to repl2@'%';
--connect replica, 127.0.0.1, root, , test, $NODE_MYPORT_1
--let $node_1 = replica
--let $node_2 = node_2
--source include/auto_increment_offset_save.inc
--connection replica
--echo # Galera replica changing master to primary1
--disable_query_log
SET @@default_master_connection='stream1';
--eval CHANGE MASTER 'stream1' TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos;
--enable_query_log
SET @@default_master_connection='stream2';
--echo # Primary node changing master to primary2
--disable_query_log
--eval CHANGE MASTER 'stream2' TO master_host='127.0.0.1', master_user='repl2', master_password='repl2', master_port=$NODE_MYPORT_4, master_use_gtid=slave_pos;
--enable_query_log
START ALL SLAVES;
--connection primary1
--echo # Primary 1: Creating table and populating it with data
CREATE TABLE t1 (id bigint auto_increment primary key, msg varchar(100)) engine=innodb;
--disable_query_log
--echo # Intentionally generate 1k GTID-events
--let $inserts=1000
--let $count=0
--disable_query_log
while($count < $inserts)
{
--eval insert into t1 values (NULL,'test1')
--inc $count
}
--enable_query_log
SELECT COUNT(*) AS EXPECT_1000 FROM t1;
--connection primary2
--echo # Primary 2: Creating table and populating it with data
CREATE TABLE t2 (id bigint auto_increment primary key, msg varchar(100)) engine=innodb;
--echo # Intentionally generate 1k GTID-events
--let $inserts=1000
--let $count=0
--disable_query_log
while($count < $inserts)
{
--eval insert into t2 values (NULL,'test1')
--inc $count
}
--enable_query_log
SELECT COUNT(*) AS EXPECT_1000 FROM t2;
--connection replica
--echo # Waiting for data to replicate to node_1
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--let $wait_condition_on_error_output = SHOW ALL SLAVES STATUS;
--source include/wait_condition_with_debug.inc
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2';
--let $wait_condition_on_error_output = SHOW ALL SLAVES STATUS;
--source include/wait_condition_with_debug.inc
--let $wait_condition = SELECT COUNT(*) = 1000 FROM t1;
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 1000 FROM t2;
--source include/wait_condition.inc
SELECT COUNT(*) AS EXPECT_1000 FROM t1;
SELECT COUNT(*) AS EXPECT_1000 FROM t2;
SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos;
SELECT COUNT(*) < 1000 AS EXPECT_1 FROM mysql.gtid_slave_pos;
SELECT @@gtid_slave_pos,@@gtid_binlog_pos,@@gtid_current_pos;
--connection node_2
--echo # Waiting for data to replicate to node_2
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2';
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 1000 FROM t1;
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 1000 FROM t2;
--source include/wait_condition.inc
SELECT COUNT(*) AS EXPECT_1000 FROM t1;
SELECT COUNT(*) AS EXPECT_1000 FROM t2;
SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos;
SELECT COUNT(*) < 1000 AS EXPECT_1 FROM mysql.gtid_slave_pos;
SELECT @@gtid_slave_pos,@@gtid_binlog_pos,@@gtid_current_pos;
#
# Cleanup
#
--connection primary1
drop table t1;
--connection primary2
drop table t2;
--echo # Wait until drop table is replicated on Galera
--connection replica
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2';
--source include/wait_condition.inc
--connection node_2
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2';
--source include/wait_condition.inc
--connection replica
STOP ALL SLAVES;
RESET SLAVE ALL;
--connection primary1
RESET MASTER;
--connection primary2
RESET MASTER;
--source include/auto_increment_offset_restore.inc
--connection node_1
--disconnect primary1
--disconnect primary2
--disconnect replica
--source include/galera_end.inc
--echo # End of test