summaryrefslogtreecommitdiff
path: root/mysql-test/suite/rpl/t/rpl_mdev12179.test
blob: 962ce3f0135fcee3cc491eb25f72f629e3157a70 (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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
--source include/have_innodb.inc
--let $rpl_topology=1->2
--source include/rpl_init.inc
--source include/no_valgrind_without_big.inc

--connection server_2
call mtr.add_suppression("The automatically created table.*name may not be entirely in lowercase");

--error ER_SLAVE_MUST_STOP
SET GLOBAL gtid_pos_auto_engines="innodb";
--source include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=slave_pos;

# Test the @@gtid_pos_auto_engines sysvar.
SELECT @@gtid_pos_auto_engines;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT @@SESSION.gtid_pos_auto_engines;
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL gtid_pos_auto_engines= NULL;
SET GLOBAL gtid_pos_auto_engines="innodb";
SELECT @@gtid_pos_auto_engines;
SET GLOBAL gtid_pos_auto_engines="myisam,innodb";
SELECT @@gtid_pos_auto_engines;
SET GLOBAL gtid_pos_auto_engines="innodb,myisam";
SELECT @@gtid_pos_auto_engines;
SET GLOBAL gtid_pos_auto_engines="innodb,innodb,myisam,innodb,myisam,myisam,innodb";
SELECT @@gtid_pos_auto_engines;
SET GLOBAL gtid_pos_auto_engines=DEFAULT;
SELECT @@gtid_pos_auto_engines;
SET GLOBAL gtid_pos_auto_engines="";
SELECT @@gtid_pos_auto_engines;

--source include/start_slave.inc

--connection server_1
CREATE TABLE t1 (a INT PRIMARY KEY);
INSERT INTO t1 VALUES (1);
SELECT * FROM t1 ORDER BY a;
--save_master_pos

--connection server_2
--sync_with_master
SELECT * FROM t1 ORDER BY a;
--source include/stop_slave.inc
SET sql_log_bin=0;
# Reset storage engine for mysql.gtid_slave_pos in case an earlier test
# might have changed it to InnoDB.
ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria;
CREATE TABLE mysql.gtid_slave_pos_innodb LIKE mysql.gtid_slave_pos;
ALTER TABLE mysql.gtid_slave_pos_innodb ENGINE=InnoDB;
INSERT INTO mysql.gtid_slave_pos_innodb SELECT * FROM mysql.gtid_slave_pos;
TRUNCATE mysql.gtid_slave_pos;
SET sql_log_bin=1;

# Restart the slave mysqld server, and verify that the GTID position is
# read correctly from the new mysql.gtid_slave_pos_innodb table.

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
--shutdown_server
--source include/wait_until_disconnected.inc

--connection server_1
INSERT INTO t1 VALUES (2);
INSERT INTO t1 VALUES (3);
SELECT * FROM t1 ORDER BY a;
--source include/save_master_gtid.inc

# Let the slave mysqld server start again.
# As we are restarting, also take the opportunity to test --gtid-pos-auto-engines
--echo *** Restart server with --gtid-pos-auto-engines=innodb,myisam ***
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0 --gtid-pos-auto-engines=innodb,myisam
EOF

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

--source include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a;

--echo *** Verify no new gtid_slave_pos* tables are created ***
SELECT table_name, engine FROM information_schema.tables
 WHERE table_schema='mysql' AND table_name LIKE 'gtid_slave_pos%'
 ORDER BY table_name;

SELECT @@gtid_pos_auto_engines;
--source include/stop_slave.inc
SET sql_log_bin=0;
INSERT INTO mysql.gtid_slave_pos_innodb SELECT * FROM mysql.gtid_slave_pos;
DROP TABLE mysql.gtid_slave_pos;
RENAME TABLE mysql.gtid_slave_pos_innodb TO mysql.gtid_slave_pos;
SET sql_log_bin=1;

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
--shutdown_server
--source include/wait_until_disconnected.inc

--connection server_1
CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (4);
INSERT INTO t2 VALUES (1);
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;
--source include/save_master_gtid.inc

--echo *** Restart server with --gtid-pos-auto-engines=myisam,innodb ***
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0 --gtid-pos-auto-engines=myisam,innodb
EOF

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

--source include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;

--echo *** Verify that no new gtid_slave_pos* tables are auto-created ***
SELECT table_name, engine FROM information_schema.tables
 WHERE table_schema='mysql' AND table_name LIKE 'gtid_slave_pos%'
 ORDER BY table_name;


--source include/stop_slave.inc
SET sql_log_bin=0;
ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria;
SET sql_log_bin=1;

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
--shutdown_server
--source include/wait_until_disconnected.inc

--connection server_1
INSERT INTO t1 VALUES (5);
INSERT INTO t2 VALUES (2);
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;
--source include/save_master_gtid.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
--echo *** Restart server with --gtid-pos-auto-engines=innodb ***
restart: --skip-slave-start=0 --gtid-pos-auto-engines=innodb
EOF

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

--source include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;

--echo *** Verify that mysql.gtid_slave_pos_InnoDB is auto-created ***
# Note, the create happens asynchronously, so wait for it.
let $wait_condition=
  SELECT EXISTS (SELECT * FROM information_schema.tables
                  WHERE table_schema='mysql' AND table_name='gtid_slave_pos_InnoDB');
--source include/wait_condition.inc
# MDEV-15373 lowercases 'table_name' to satisfy --lower-case-table-names options
SELECT lower(table_name), engine FROM information_schema.tables
 WHERE table_schema='mysql' AND table_name LIKE 'gtid_slave_pos%'
 ORDER BY table_name;


--source include/stop_slave.inc
SET sql_log_bin=0;
INSERT INTO mysql.gtid_slave_pos SELECT * FROM mysql.gtid_slave_pos_InnoDB;
DROP TABLE mysql.gtid_slave_pos_InnoDB;
SET sql_log_bin=1;

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
--shutdown_server
--source include/wait_until_disconnected.inc

--connection server_1
INSERT INTO t1 VALUES (6);
INSERT INTO t2 VALUES (3);
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;
--source include/save_master_gtid.inc

--echo *** Restart server without --gtid-pos-auto-engines ***
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

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

--source include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;

--echo *** Verify that no mysql.gtid_slave_pos* table is auto-created ***
SELECT table_name, engine FROM information_schema.tables
 WHERE table_schema='mysql' AND table_name LIKE 'gtid_slave_pos%'
 ORDER BY table_name;
SELECT domain_id, max(seq_no) FROM mysql.gtid_slave_pos GROUP BY domain_id;

--source include/stop_slave.inc
SET GLOBAL gtid_pos_auto_engines="innodb";
--source include/start_slave.inc

--connection server_1
INSERT INTO t1 VALUES (7);
INSERT INTO t2 VALUES (4);
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;
--source include/save_master_gtid.inc

--connection server_2
--source include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a;
SELECT * FROM t2 ORDER BY a;

--echo *** Verify that mysql.gtid_slave_pos_InnoDB is auto-created ***
let $wait_condition=
  SELECT EXISTS (SELECT * FROM information_schema.tables
                  WHERE table_schema='mysql' AND table_name='gtid_slave_pos_InnoDB');
--source include/wait_condition.inc
SELECT lower(table_name), engine FROM information_schema.tables
 WHERE table_schema='mysql' AND table_name LIKE 'gtid_slave_pos%'
 ORDER BY table_name;
SELECT domain_id, max(seq_no) FROM mysql.gtid_slave_pos GROUP BY domain_id;

# Check that the auto-created InnoDB table starts being used without
# needing slave restart. The auto-create happens asynchronously, so it
# is non-deterministic when it will start being used. But we can wait
# for it to happen.

--let $count=300
--let $done=0
--let $old_silent= $keep_include_silent
--let $keep_include_silent= 1
--disable_query_log
while (!$done)
{
  --connection server_1
  INSERT INTO t2(a) SELECT 1+MAX(a) FROM t2;
  --source include/save_master_gtid.inc

  --connection server_2
  --source include/sync_with_master_gtid.inc
  --let $done=`SELECT COUNT(*) > 0 FROM mysql.gtid_slave_pos_InnoDB`
  if (!$done)
  {
    dec $count;
    if (!$count)
    {
      SELECT * FROM mysql.gtid_slave_pos_InnoDB;
      --die Timeout waiting for mysql.gtid_slave_pos_InnoDB to be used
    }
    real_sleep 0.1;
  }
}
--enable_query_log
--let $keep_include_silent=$old_silent
# Note that at this point, the contents of table t2, as well as the GTID
# position, is non-deterministic.

# MDEV-15373 engine gtid_slave_pos table name disobeys lower-case-table-names
# This snippet verifies that engine gtid_slave_pos table is found,
# its data are up-to-date.
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
--connection server_2
--shutdown_server
--source include/wait_until_disconnected.inc

--echo *** Restart the slave server to prove 'gtid_slave_pos_innodb' autodiscovery ***
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

--connection server_2
--enable_reconnect
--source include/wait_until_connected_again.inc
SELECT max(seq_no) FROM mysql.gtid_slave_pos_InnoDB into @seq_no;

--connection server_1
INSERT INTO t2(a) SELECT 1+MAX(a) FROM t2;
--source include/save_master_gtid.inc

--connection server_2
--source include/sync_with_master_gtid.inc
if (`SELECT  max(seq_no) <> @seq_no + 1  FROM mysql.gtid_slave_pos_InnoDB`)
{
  SELECT * FROM mysql.gtid_slave_pos_InnoDB;
  --die Inconsistent table
}
#
# end of MDEV-15373

#--connection server_2
--source include/stop_slave.inc
SET GLOBAL gtid_pos_auto_engines="";
SET sql_log_bin=0;
DROP TABLE mysql.gtid_slave_pos_InnoDB;
SET sql_log_bin=1;
--source include/start_slave.inc

--connection server_1
DROP TABLE t1, t2;

--source include/rpl_end.inc