File: galera_restart_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 (286 lines) | stat: -rw-r--r-- 10,430 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#
# Test Galera as a replica to a MariaDB async replication
#
#   MariaDB
#    primary ---async replication--->galera node_2 (replica)<----galera replication---> galera node1
#
#  Test outline:
#
#  - Create user for async replication
#  - Create table and some data in primary
#  - 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
#  - Verify that we can shutdown and restart Galera replica (node #2)
#  - Verify that gtid_slave_pos, gtid_binlog_pos and gtid_current_pos are
#    same in all Galera nodes
#  - Verify that mysql.gtid_slave_pos table has limited amount of rows
#  - Veruft that ddl works (drop table)
#
#  Similar test is done so that new rows are added to table in
#  primary while async replica (node #2) is down.
#
# The galera/galera_2node_slave.cnf describes the setup of the nodes
#
--source include/force_restart.inc
--source include/galera_cluster.inc
--source include/have_innodb.inc

# In this test we mark node #2 as replica
--connect replica, 127.0.0.1, root, , test, $NODE_MYPORT_2

# As node #3 is not a Galera node, and galera_cluster.inc does not open connetion to it
# we open the primary connection her
--connect primary, 127.0.0.1, root, , test, $NODE_MYPORT_3

create user repl@'%' identified by 'repl';
grant all on *.* to  repl@'%';
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;

--let $node_1 = node_1
--let $node_2 = replica
--let $node_3 = primary
--source include/auto_increment_offset_save.inc

--connection replica
--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_3, master_use_gtid=slave_pos;
--enable_query_log
START SLAVE;

--connection primary
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 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

--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--connection node_1
--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

--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--connection replica
--echo # Verify that graceful shutdown succeeds in replica.
--source include/shutdown_mysqld.inc
--echo # Force SST
--remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat

--connection node_1
--echo # Waiting until replica is not part of cluster anymore
--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status';
--source include/wait_condition.inc

--connection replica
--echo # Start replica again
--source include/start_mysqld.inc

--echo # Wait until replica is back on cluster
--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status';
--source include/wait_condition.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready';
--source include/wait_condition.inc

--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--connection node_1
--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--connection primary
SELECT COUNT(*) AS EXPECT_1000 FROM t1;

#
# Cleanup
#
drop table t1;

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

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

#
# Case 2 : While slave is down add writes to master
#

--connection primary
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 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

--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_1000 FROM t1;

--connection node_1
--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

--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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 replica
--echo # Verify that graceful shutdown succeeds in replica.
--source include/shutdown_mysqld.inc
--echo # Force SST
--remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat

--connection node_1
--echo # Waiting until replica is not part of cluster anymore
--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status';
--source include/wait_condition.inc

--echo # Add writes to primary
--connection primary
--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 replica
--echo # Start replica again
--source include/start_mysqld.inc

--echo # Wait until replica is back on cluster
--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status';
--source include/wait_condition.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready';
--source include/wait_condition.inc

--let $wait_condition = SELECT COUNT(*) = 2000 FROM t1;
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_2000 FROM t1;

--connection node_1
--let $wait_condition = SELECT COUNT(*) = 2000 FROM t1;
--source include/wait_condition.inc
--let $wait_condition = SELECT COUNT(*) < 1000 FROM mysql.gtid_slave_pos;
--source include/wait_condition.inc
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;
SELECT COUNT(*) AS EXPECT_2000 FROM t1;

--connection primary
SELECT COUNT(*) AS EXPECT_2000 FROM t1;

#
# Cleanup
#
drop table t1;

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

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

--connection replica
STOP SLAVE;
RESET SLAVE ALL;

--connection primary
RESET MASTER;

--source include/auto_increment_offset_restore.inc

--connection node_1
--disconnect primary
--disconnect replica

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