File: galera_2primary_replica.test

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (172 lines) | stat: -rw-r--r-- 6,099 bytes parent folder | download | duplicates (2)
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
#
# 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
--let $node_3 = primary1
--let $node_4 = primary2
--source include/auto_increment_offset_save.inc

--connection replica
--echo # Galera replica changing master to primary1
SET @@default_master_connection='stream1';
--disable_query_log
--eval CHANGE MASTER 'stream1' TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_ssl_verify_server_cert=0, master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos;
--enable_query_log

--echo # Primary node changing master to primary2
SET @@default_master_connection='stream2';
--disable_query_log
--eval CHANGE MASTER 'stream2' TO master_host='127.0.0.1', master_user='repl2', master_password='repl2', master_ssl_verify_server_cert=0, 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