File: galera_circular_replication.test

package info (click to toggle)
mariadb 1%3A11.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 765,428 kB
  • sloc: ansic: 2,382,827; cpp: 1,803,532; asm: 378,315; perl: 63,176; sh: 46,496; pascal: 40,776; java: 39,363; yacc: 20,428; python: 19,506; sql: 17,864; xml: 12,463; ruby: 8,544; makefile: 6,059; cs: 5,855; ada: 1,700; lex: 1,193; javascript: 1,039; objc: 80; tcl: 73; awk: 46; php: 22
file content (235 lines) | stat: -rw-r--r-- 7,650 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
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
#
# Test circular replication where galera cluster is async replica and master
#
#      mariadb #4                  galera                             galera
#       primary1
#       replica2
#         ---async replication-->replica1 #1 <--galera replication--> node_2 #2
#         ^                                                          ^
#         |                                                          | galera replication
#         |                                                          v
#         +<------------------async replication----------------------primary2 (galera) #3
#
# Test outline:
#
#  - Create user for async replication in primary1
#  - Create user for async replication in primary2
#  - Create table and some data in primary1
#  - Verify that table and data is replicated to galera nodes
#  - Verify that mysql.gtid_slave_pos has some rows in all Galera nodes
#  - Verify that gtid_slave_pos, gtid_binlog_pos and gtid_current_pos are
#    same in all Galera nodes and primary1
#  - Verify that writes on Galera nodes are replicated to all nodes
#    and to primary1
#
# The galera/galera_3nodes_as_slave.cnf describes the setup of the nodes
#
--source include/force_restart.inc
--source include/galera_cluster.inc
--source include/have_innodb.inc

--connect replica1, 127.0.0.1, root, , test, $NODE_MYPORT_1
--connect primary2, 127.0.0.1, root, , test, $NODE_MYPORT_3

# As node #4 is not a Galera node, and galera_cluster.inc does not open connetion to it
# because it is both primary and replica we open both connections here
--connect primary1, 127.0.0.1, root, , test, $NODE_MYPORT_4
--connect replica2, 127.0.0.1, root, , test, $NODE_MYPORT_4

--connection primary1
--echo # Primary1 node creating user for replication
create user repl@'%' identified by 'repl';
grant all on *.* to  repl@'%';
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;

--let $node_1 = replica1
--let $node_2 = node_2
--let $node_3 = primary2
--let $node_4 = primary1
--source include/auto_increment_offset_save.inc

--connection replica1
--echo # Galera replica changing master to primary1
--disable_query_log
--eval CHANGE MASTER TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_ssl_verify_server_cert=0, master_port=$NODE_MYPORT_4, master_use_gtid=slave_pos;
--enable_query_log
START SLAVE;

--connection primary2
--echo # Primary2 creating user for replication
create user repl2@'%' identified by 'repl2';
grant all on *.* to  repl2@'%';

--connection replica2
--echo # replica2 changing master to primary2
--disable_query_log
--eval CHANGE MASTER TO master_host='127.0.0.1', master_user='repl2', master_password='repl2', master_ssl_verify_server_cert=0, master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos;
--enable_query_log
START SLAVE;

--connection primary1
--echo # Primary1: Creating table and populating it with data
CREATE TABLE t1 (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 t1 values (NULL,'test1')
  --inc $count
}
--enable_query_log

SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--connection replica1
--echo # Waiting for data to replicate to replica
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc

--let $wait_condition = SELECT COUNT(*) = 1000 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--echo # Writing more data to table
--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_2000 FROM t1;

--connection node_2
--echo # Waiting for data to replicate to Galera 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(*) = 2000 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) AS EXPECT_2000 FROM t1;

--echo # Writing more data to table
--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_3000 FROM t1;

--connection primary2
--echo # Waiting for data to replicate to primary2
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc

--let $wait_condition = SELECT COUNT(*) = 3000 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) AS EXPECT_3000 FROM t1;

--echo # Writing more data to table
--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_4000 FROM t1;

--connection primary1
--echo # Waiting for data to replicate to primary1
--let $wait_condition = SELECT COUNT(*) = 4000 FROM t1;
--let $wait_condition_on_error_output = SHOW SLAVE STATUS;
--source include/wait_condition_with_debug.inc

SELECT COUNT(*) AS EXPECT_4000 FROM t1;
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 replica1
--echo # Waiting for data to replicate to replica
--let $wait_condition = SELECT COUNT(*) = 4000 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) AS EXPECT_4000 FROM t1;
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(*) = 4000 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) AS EXPECT_4000 FROM t1;
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 primary2
--echo # Waiting for data to replicate to node_3
--let $wait_condition = SELECT COUNT(*) = 4000 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) AS EXPECT_4000 FROM t1;
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;

--echo # Wait until drop table is replicated on Galera
--connection replica1
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--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

--connection primary2
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
--source include/wait_condition.inc

--connection replica1
STOP SLAVE;
RESET SLAVE ALL;

--connection replica2
STOP SLAVE;
RESET SLAVE ALL;
RESET MASTER;

--source include/auto_increment_offset_restore.inc

--connection node_1
--disconnect primary1
--disconnect replica1
--disconnect primary2
--disconnect replica2

--source include/galera_end.inc
--echo # End of test