summaryrefslogtreecommitdiff
path: root/mysql-test/suite/galera/t/galera_var_slave_threads.test
blob: 12d8006db4bc6ad41b5d3356a22c705b13943f4c (plain)
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
#
# This tests the very basic operations around wsrep-slave-threads
# More complex scenarios will be tested separately in the context of
# parallel replication
#

--source include/galera_cluster.inc
--source include/have_innodb.inc
--let $wsrep_slave_threads_orig = `SELECT @@wsrep_slave_threads`

# Save original auto_increment_offset values.
--let $node_1=node_1
--let $node_2=node_2
--source include/auto_increment_offset_save.inc

--connection node_1
CREATE TABLE t1 (f1 INT PRIMARY KEY) Engine=InnoDB;
CREATE TABLE t2 (f1 INT AUTO_INCREMENT PRIMARY KEY) Engine=InnoDB;

--connection node_2
CALL mtr.add_suppression("WSREP: Refusing exit for the last slave thread.");
# Setting wsrep_slave_threads to zero triggers a warning
SET GLOBAL wsrep_slave_threads = 0;
SHOW WARNINGS;
SELECT @@wsrep_slave_threads = 1;

SET GLOBAL wsrep_slave_threads = 1;
# There is a separate wsrep_aborter thread at all times
SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND COMMAND != 'Daemon';
SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE LIKE '%wsrep aborter%';

#
# Increase the number of slave threads. The change takes effect immediately
#

SET GLOBAL wsrep_slave_threads = 64;

--connection node_1
INSERT INTO t1 VALUES (1);

--connection node_2
SELECT COUNT(*) FROM t1;

#
# note, in wsrep API #26, we have 2 rollbacker threads, counted as system user's
#

SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE LIKE '%wsrep aborter%';

--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc

#
# Reduce the number of slave threads. The change is not immediate -- a thread will only exit after a replication event
#

SET GLOBAL wsrep_slave_threads = 1;

--connection node_1

--disable_result_log
--disable_query_log
# Generate 64 replication events
--let $count = 64
while ($count)
{
  INSERT INTO t2 VALUES (DEFAULT);
  --dec $count
}
--enable_query_log
--enable_result_log

--connection node_2
SELECT COUNT(*) FROM t2;

SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND STATE LIKE '%wsrep aborter%';

--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc

--let $wsrep_cluster_address_node2 = `SELECT @@wsrep_cluster_address`
--let $wsrep_provider_node2 = `SELECT @@wsrep_provider`

SET GLOBAL wsrep_slave_threads = 5;

--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc

SET GLOBAL wsrep_slave_threads = 1;

#
# test phase for bug https://github.com/codership/mysql-wsrep/issues/319
#

# shutdown node 2
--connection node_2
--echo Shutting down server ...
--source include/shutdown_mysqld.inc

# wait until node_1 is ready as one node cluster
--connection node_1

--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc
show status like 'wsrep_cluster_size';

# step up slave threads to 6, and make sure all appliers and rollbacker thread are running
SET GLOBAL wsrep_slave_threads = 6;
--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc

# change to invalid cluster address
SET GLOBAL wsrep_slave_threads = 1;
SET GLOBAL wsrep_cluster_address='';

# join back to single node cluster
SET GLOBAL wsrep_cluster_address='gcomm://';
--source include/wait_until_connected_again.inc

# we should have 1 applier thread now
--let $wait_condition = SELECT COUNT(*) = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND COMMAND != 'Daemon'
--source include/wait_condition.inc

# test if we can increase applier count now (fails in bug #319)
SET GLOBAL wsrep_slave_threads = 10;
--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc

# restart node 2
--connection node_2
--source include/start_mysqld.inc
--source include/wait_until_connected_again.inc

SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'system user' AND COMMAND != 'Daemon';

# 
#
# cleanup to original state
#
--connection node_1
--eval SET GLOBAL wsrep_slave_threads = $wsrep_slave_threads_orig

--connection node_2
--eval SET GLOBAL wsrep_slave_threads = $wsrep_slave_threads_orig


--disable_result_log
--disable_query_log
# Generate 64 replication events, to help node 1 to purge excessive applier threads
--let $count = 64
while ($count)
{
  INSERT INTO t2 VALUES (DEFAULT);
  --dec $count
}
--enable_query_log
--enable_result_log

--connection node_1
--disable_result_log
--disable_query_log
# Generate 64 replication events, to help node 2 to purge excessive applier threads
--let $count = 64
while ($count)
{
  INSERT INTO t2 VALUES (DEFAULT);
  --dec $count
}
--enable_query_log
--enable_result_log

--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc


--connection node_2
--let $wait_condition = SELECT VARIABLE_VALUE = @@wsrep_slave_threads + 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_thread_count';
--source include/wait_condition.inc

SELECT COUNT(*) FROM t1;
SELECT COUNT(*) FROM t2;

--connection node_1

SELECT COUNT(*) FROM t1;
SELECT COUNT(*) FROM t2;

DROP TABLE t1;
DROP TABLE t2;

# Restore original auto_increment_offset values.
--source include/auto_increment_offset_restore.inc

--echo # End of tests