summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/rpl/t/rpl_parallel_temptable.test
blob: 3684763dad74e72ab20c5b2dc9b24c76b5fc9c1e (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
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
--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_binlog_format_statement.inc
# Valgrind does not work well with test that crashes the server
--source include/not_valgrind.inc
--let $rpl_topology=1->2
--source include/rpl_init.inc

--echo *** MDEV-6321: close_temporary_tables() in format description event not serialised correctly ***

--connection server_2
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
--source include/stop_slave.inc
SET GLOBAL slave_parallel_threads=5;
--source include/start_slave.inc

--connection server_1
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(100) CHARACTER SET utf8);
--save_master_pos

--connection server_2
--sync_with_master
--source include/stop_slave.inc


--connection server_1
SET gtid_domain_id= 1;
INSERT INTO t1 VALUES (1, 0);

CREATE TEMPORARY TABLE t2 (a int);

--connection default
SET gtid_domain_id= 2;
CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY);
CREATE TEMPORARY TABLE t4 (a int);
INSERT INTO t3 VALUES (100);
INSERT INTO t4 SELECT a+1 FROM t3;

--connection server_1
INSERT INTO t2 VALUES (2), (4), (6), (8), (10), (12), (14), (16), (18), (20);
INSERT INTO t2 VALUES (3), (6), (9), (12), (15), (18);
INSERT INTO t2 VALUES (4), (8), (12), (16), (20);

--connection default
INSERT INTO t3 SELECT a+2 FROM t4;
INSERT INTO t4 SELECT a+4 FROM t3;

--connection server_1
INSERT INTO t2 VALUES (5), (10), (15), (20);
INSERT INTO t2 VALUES (6), (12), (18);
INSERT INTO t2 VALUES (7), (14);
INSERT INTO t2 VALUES (8), (16);
INSERT INTO t2 VALUES (9), (18);
INSERT INTO t2 VALUES (10), (20);

--connection default
INSERT INTO t3 SELECT a+8 FROM t4;
INSERT INTO t4 SELECT a+16 FROM t3;

--connection server_1
INSERT INTO t2 VALUES (11);
INSERT INTO t2 VALUES (12);
INSERT INTO t2 VALUES (13);

--connection default
INSERT INTO t3 SELECT a+32 FROM t4;

--connection server_1
INSERT INTO t2 VALUES (14);
INSERT INTO t2 VALUES (15);
INSERT INTO t2 VALUES (16);

--connection default
INSERT INTO t4 SELECT a+64 FROM t3;

--connection server_1
INSERT INTO t2 VALUES (17);
INSERT INTO t2 VALUES (18);
INSERT INTO t2 VALUES (19);

--connection default
INSERT INTO t3 SELECT a+128 FROM t4;

--connection server_1
INSERT INTO t2 VALUES (20);

--connection default
INSERT INTO t1 SELECT a, a MOD 7 FROM t3;
INSERT INTO t1 SELECT a, a MOD 7 FROM t4;

--connection server_1
INSERT INTO t1 SELECT a, COUNT(*) FROM t2 GROUP BY a;

# Crash the master server, so that temporary tables are implicitly dropped.
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

FLUSH TABLES;
SET SESSION debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
SELECT 1;

--source include/wait_until_disconnected.inc
--connection default
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF

--connection default
--enable_reconnect
--source include/wait_until_connected_again.inc

--connection server_1
--enable_reconnect
--source include/wait_until_connected_again.inc

INSERT INTO t1 VALUES (0, 1);
--save_master_pos

--connection server_2
# Start the slave replicating the events.
# The bug was that the format description event written after the crash could
# be fetched ahead of the execution of the temporary table events and executed
# out-of-band. This would cause drop of all temporary tables and thus failure
# for execution of remaining events.

--source include/start_slave.inc
--sync_with_master

SELECT * FROM t1 WHERE a <= 20 ORDER BY a;
SELECT COUNT(*) FROM t1 WHERE a BETWEEN 100+0 AND 100+256;
SHOW STATUS LIKE 'Slave_open_temp_tables';


--echo *** Test that if master logged partial event group before crash, we finish that group correctly before executing format description event ***

--source include/stop_slave.inc

--connection server_1
CALL mtr.add_suppression("Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them");
SET gtid_domain_id= 1;
DELETE FROM t1;
ALTER TABLE t1 ENGINE=InnoDB;
CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY);
INSERT INTO t2 VALUES (1);
INSERT INTO t2 VALUES (2);

--connection default
SET gtid_domain_id= 2;
CREATE TEMPORARY TABLE t3 (a INT PRIMARY KEY);
INSERT INTO t3 VALUES (10);
INSERT INTO t3 VALUES (20);

--connection server_1
INSERT INTO t1 SELECT a, 'server_1' FROM t2;

--connection default
INSERT INTO t1 SELECT a, 'default' FROM t3;

--connection server_1
INSERT INTO t1 SELECT a+2, '+server_1' FROM t2;

# Crash the master server in the middle of writing an event group.
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

FLUSH TABLES;
SET SESSION debug_dbug="+d,crash_before_writing_xid";
--error 2006,2013
INSERT INTO t1 SELECT a+4, '++server_1' FROM t2;

--source include/wait_until_disconnected.inc
--connection default
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF

--connection default
--enable_reconnect
--source include/wait_until_connected_again.inc

--connection server_1
--enable_reconnect
--source include/wait_until_connected_again.inc

INSERT INTO t1 VALUES (0, 1);
#--save_master_pos
--source include/save_master_gtid.inc

--connection server_2
# Start the slave replicating the events.
# The main thing to test here is that the slave will know that it
# needs to abort the partially received event group, so that the
# execution of format_description event will not wait infinitely
# for a commit of the incomplete group that never happens.

# Apart from the suppression, MDEV-27697 refinement to the original test needs
# an allowance to one time accept malformed event group.
set @@sql_log_bin=0;
call mtr.add_suppression("Unexpected break of being relay-logged GTID 1-1-32 event group by the current GTID event 0-1-4");
set @@sql_log_bin=1;
set @@global.debug_dbug="+d,slave_discard_xid_for_gtid_0_x_1000";
--source include/start_slave.inc
#--sync_with_master
--source include/sync_with_master_gtid.inc
set @@global.debug_dbug="";

SELECT * FROM t1 ORDER BY a;
SHOW STATUS LIKE 'Slave_open_temp_tables';

--connection server_1
# This FLUSH can be removed once MDEV-6608 is fixed.
FLUSH LOGS;


--echo *** MDEV-7936: Assertion `!table || table->in_use == _current_thd()' failed on parallel replication in optimistic mode ***

--connection server_1
CREATE TEMPORARY TABLE t4 (a INT PRIMARY KEY) ENGINE=InnoDB;
SET @old_dbug= @@SESSION.debug_dbug;
SET SESSION debug_dbug="+d,binlog_force_commit_id";
SET @commit_id= 10000;
INSERT INTO t4 VALUES (30);
INSERT INTO t4 VALUES (31);
SET SESSION debug_dbug= @old_dbug;
INSERT INTO t1 SELECT a, "conservative" FROM t4;
DROP TEMPORARY TABLE t4;
SELECT * FROM t1 WHERE a >= 30 ORDER BY a;
--source include/save_master_gtid.inc

--connection server_2
--source include/sync_with_master_gtid.inc

SELECT * FROM t1 WHERE a >= 30 ORDER BY a;

--source include/stop_slave.inc
SET @old_mode= @@GLOBAL.slave_parallel_mode;
SET GLOBAL slave_parallel_mode=optimistic;

--connection server_1
CREATE TEMPORARY TABLE t4 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t4 VALUES (32);
INSERT INTO t4 VALUES (33);
INSERT INTO t1 SELECT a, "optimistic" FROM t4;
DROP TEMPORARY TABLE t4;

SELECT * FROM t1 WHERE a >= 30 ORDER BY a;
--source include/save_master_gtid.inc

--connection server_2
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc

SELECT * FROM t1 WHERE a >= 30 ORDER BY a;

--source include/stop_slave.inc
SET GLOBAL slave_parallel_mode=@old_mode;
--source include/start_slave.inc


# Clean up.

--connection server_2
--source include/stop_slave.inc
SET GLOBAL slave_parallel_threads=@old_parallel_threads;
--source include/start_slave.inc

--connection server_1
DROP TABLE t1;

--source include/rpl_end.inc