summaryrefslogtreecommitdiff
path: root/mysql-test/main/backup_stages.result
blob: 823e5d7e4625c514bfcc5f5d202bc652f43856b0 (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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#-----------------------------------------------------------------------
# Multi-threaded tests
#-----------------------------------------------------------------------
# Show that only one connection can hold the backup lock.
connection default;
BACKUP STAGE START;
connect con1,localhost,root,,;
SET STATEMENT lock_wait_timeout=0 FOR BACKUP STAGE START;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
BACKUP STAGE START;
connection default;
# Show that the connection con1 has to wait for the backup lock and the
# corresponding representation within the processlist.
SET @con1_id = <con1_id>;
SELECT ID, USER, COMMAND, STATE, INFO, STAGE, MAX_STAGE, INFO_BINARY
FROM information_schema.processlist WHERE id = @con1_id;
ID	USER	COMMAND	STATE	INFO	STAGE	MAX_STAGE	INFO_BINARY
<con1_id>	root	Query	Waiting for backup lock	BACKUP STAGE START	0	0	BACKUP STAGE START
BACKUP STAGE END;
connection con1;
# The connection default has removed the backup lock.
# And so the current connection con1 can reap for its BACKUP STAGE START
SELECT LOCK_MODE, LOCK_TYPE, TABLE_SCHEMA, TABLE_NAME FROM information_schema.metadata_lock_info;
LOCK_MODE	LOCK_TYPE	TABLE_SCHEMA	TABLE_NAME
MDL_BACKUP_START	Backup lock		
connect con2,localhost,root,,;
# The connection con2 cannot continue the work of con1 by setting the
# next BACKUP STAGE FLUSH.
BACKUP STAGE FLUSH;
ERROR HY000: You must start backup with "BACKUP STAGE START"
BACKUP STAGE START;
connection default;
SET @con2_id = <con2_id>;
# Connection con2 waits for the backup lock held by con1.
SELECT ID, USER, COMMAND, STATE, INFO, STAGE, MAX_STAGE, INFO_BINARY
FROM information_schema.processlist WHERE id = @con2_id;
ID	USER	COMMAND	STATE	INFO	STAGE	MAX_STAGE	INFO_BINARY
<con2_id>	root	Query	Waiting for backup lock	BACKUP STAGE START	0	0	BACKUP STAGE START
disconnect con1;
connection con2;
# Connection con1 frees the backup lock held by disconnecting.
# So connection con2 gets the backup lock.
connect con3,localhost,root,,;
BACKUP STAGE START;
connection default;
SET @con3_id = <con3_id>;
# Connection con3 waits for the backup lock held by con2.
SELECT ID, USER, COMMAND, STATE, INFO, STAGE, MAX_STAGE, INFO_BINARY
FROM information_schema.processlist WHERE id = @con3_id;
ID	USER	COMMAND	STATE	INFO	STAGE	MAX_STAGE	INFO_BINARY
<con3_id>	root	Query	Waiting for backup lock	BACKUP STAGE START	0	0	BACKUP STAGE START
KILL CONNECTION @con2_id;
connection con3;
# Connection con2 frees the backup lock held by getting killed.
# So connection con3 gets the backup lock.
BACKUP STAGE END;
disconnect con3;
connection default;
CREATE TABLE t_permanent_innodb (col1 INT) ENGINE = InnoDB;
INSERT INTO t_permanent_innodb SET col1 = 1;
CREATE TABLE t_permanent_myisam (col1 INT) ENGINE = MyISAM;
INSERT INTO t_permanent_myisam SET col1 = 1;
connect backup,localhost,root,,;
connect con11,localhost,root,,;
SET AUTOCOMMIT = 0;
set session lock_wait_timeout=1;
connect con12,localhost,root,,;
SET AUTOCOMMIT = 1;
# Between (connection default) BACKUP STAGE START and FLUSH
# no restrictions for concurrent sessions regarding DDL or DML
# affecting transactional/non transactional permanent tables.
connection backup;
BACKUP STAGE START;
connection con11;
UPDATE t_permanent_innodb SET col1 = 2;
UPDATE t_permanent_myisam SET col1 = 2;
SELECT COUNT(*) FROM t_permanent_innodb;
COUNT(*)
1
HANDLER t_permanent_innodb OPEN;
HANDLER t_permanent_innodb READ FIRST;
col1
2
HANDLER t_permanent_innodb CLOSE;
SELECT COUNT(*) FROM t_permanent_myisam;
COUNT(*)
1
HANDLER t_permanent_myisam OPEN;
HANDLER t_permanent_myisam READ FIRST;
col1
2
HANDLER t_permanent_myisam CLOSE;
CREATE TABLE t_con1_innodb (col1 INT) ENGINE = InnoDB;
CREATE TABLE t_con1_myisam (col1 INT) ENGINE = InnoDB;
ALTER TABLE t_permanent_innodb ADD COLUMN col2 INT;
ALTER TABLE t_permanent_myisam ADD COLUMN col2 INT;
CREATE OR REPLACE VIEW v_some_view AS SELECT * FROM t_permanent_innodb;
CREATE OR REPLACE VIEW v_some_view AS SELECT * FROM t_permanent_myisam;
connection con12;
UPDATE t_permanent_innodb SET col1 = 3;
UPDATE t_permanent_myisam SET col1 = 3;
# Between (connection default) BACKUP STAGE FLUSH and BLOCK_DDL
# concurrent sessions
# - can change transactional permanent tables with DDL and DML
# - can run DROP/CREATE transactional/non transactional TABLE
# - cannot modify non transactional permanent tables with DDL or DML
connection backup;
BACKUP STAGE FLUSH;
connection con11;
UPDATE t_permanent_innodb SET col1 = 4;
SET STATEMENT lock_wait_timeout=0 FOR UPDATE t_permanent_myisam SET col1 = 4;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SELECT COUNT(*) FROM t_permanent_innodb;
COUNT(*)
1
HANDLER t_permanent_innodb OPEN;
HANDLER t_permanent_innodb READ FIRST;
col1	col2
4	NULL
HANDLER t_permanent_innodb CLOSE;
SELECT COUNT(*) FROM t_permanent_myisam;
COUNT(*)
1
HANDLER t_permanent_myisam OPEN;
HANDLER t_permanent_myisam READ FIRST;
col1	col2
3	NULL
HANDLER t_permanent_myisam CLOSE;
DROP TABLE t_con1_innodb;
DROP TABLE t_con1_myisam;
CREATE TABLE t_con1_innodb (col1 INT) ENGINE = InnoDB;
CREATE TABLE t_con1_myisam (col1 INT) ENGINE = InnoDB;
ALTER TABLE t_permanent_innodb ADD COLUMN col3 INT;
SET STATEMENT lock_wait_timeout=0 FOR ALTER TABLE t_permanent_myisam ADD COLUMN col3 INT;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
CREATE OR REPLACE VIEW v_some_view AS SELECT * FROM t_permanent_innodb;
CREATE OR REPLACE VIEW v_some_view AS SELECT * FROM t_permanent_myisam;
connection con12;
UPDATE t_permanent_innodb SET col1 = 5;
# Between (connection default) BACKUP STAGE BLOCK_DDL and BLOCK_COMMIT
# concurrent sessions
# - can change transactional permanent tables with DML
# - cannot run DDL
# - cannot change non transactional permanent tables with DML
connection backup;
BACKUP STAGE BLOCK_DDL;
connection con11;
UPDATE t_permanent_innodb SET col1 = 6;
UPDATE t_permanent_myisam SET col1 = 6;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SELECT COUNT(*) FROM t_permanent_innodb;
COUNT(*)
1
HANDLER t_permanent_innodb OPEN;
HANDLER t_permanent_innodb READ FIRST;
col1	col2	col3
6	NULL	NULL
HANDLER t_permanent_innodb CLOSE;
SELECT COUNT(*) FROM t_permanent_myisam;
COUNT(*)
1
HANDLER t_permanent_myisam OPEN;
HANDLER t_permanent_myisam READ FIRST;
col1	col2
3	NULL
HANDLER t_permanent_myisam CLOSE;
DROP TABLE t_con1_innodb;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
CREATE TABLE throw_away (col1 INT) ENGINE = InnoDB;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
ALTER TABLE t_permanent_innodb ADD COLUMN col4 INT;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
CREATE OR REPLACE VIEW v_some_view AS SELECT * FROM t_permanent_innodb;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
CREATE OR REPLACE VIEW v_some_view AS SELECT * FROM t_permanent_myisam;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
connection con12;
UPDATE t_permanent_innodb SET col1 = 7;
# Between (connection default) BACKUP STAGE BLOCK_COMMIT and END
# concurrent sessions
# - can change transactional permanent tables with DML
# - cannot run DDL
# - cannot change non transactional permanent tables with DML
connection backup;
BACKUP STAGE BLOCK_COMMIT;
connection con11;
UPDATE t_permanent_innodb SET col1 = 8;
UPDATE t_permanent_myisam SET col1 = 8;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
SELECT COUNT(*) FROM t_permanent_innodb;
COUNT(*)
1
HANDLER t_permanent_innodb OPEN;
HANDLER t_permanent_innodb READ FIRST;
col1	col2	col3
8	NULL	NULL
HANDLER t_permanent_innodb CLOSE;
SELECT COUNT(*) FROM t_permanent_myisam;
COUNT(*)
1
HANDLER t_permanent_myisam OPEN;
HANDLER t_permanent_myisam READ FIRST;
col1	col2
3	NULL
HANDLER t_permanent_myisam CLOSE;
DROP TABLE t_con1_innodb;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
DROP TABLE t_con1_myisam;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
connection con12;
SET STATEMENT lock_wait_timeout=1 FOR UPDATE t_permanent_innodb SET col1 = 9;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
connection backup;
BACKUP STAGE END;
connection con11;
COMMIT;
SELECT * FROM t_permanent_innodb ORDER BY col1;
col1	col2	col3
7	NULL	NULL
SELECT * FROM t_permanent_myisam ORDER BY col1;
col1	col2
3	NULL
SET AUTOCOMMIT = 0;
SET GLOBAL tx_read_only = 1;
connection con12;
BACKUP STAGE START;
BACKUP STAGE END;
SET GLOBAL tx_read_only = 0;
DROP VIEW v_some_view;
DROP TABLE t_con1_innodb;
DROP TABLE t_con1_myisam;
# Connection backup holds the backup log and is on some stage.
# Connection con11 tries to LOCK TABLEs or to set read_only.
connection backup;
BACKUP STAGE START;
connection con11;
# Between BACKUP STAGE START and FLUSH:
# No restrictions for other connection around LOCK TABLES or read-only.
LOCK TABLES t_permanent_innodb READ;
LOCK TABLES t_permanent_myisam READ;
LOCK TABLES t_permanent_innodb WRITE;
LOCK TABLES t_permanent_myisam WRITE;
UNLOCK TABLES;
SET GLOBAL tx_read_only = 1;
SET GLOBAL tx_read_only = 0;
connection backup;
BACKUP STAGE FLUSH;
connection con11;
# Between BACKUP STAGE FLUSH and BLOCK_COMMIT:
# Connection con11 not holding the backup lock cannot
# LOCK WRITE non transactional table.
LOCK TABLES t_permanent_innodb READ;
LOCK TABLES t_permanent_myisam READ;
LOCK TABLES t_permanent_innodb WRITE;
LOCK TABLES t_permanent_myisam WRITE;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
UNLOCK TABLES;
SET GLOBAL tx_read_only = 1;
SET GLOBAL tx_read_only = 0;
connection backup;
BACKUP STAGE BLOCK_DDL;
connection con11;
# Between BACKUP STAGE FLUSH and BLOCK_COMMIT:
# Connection con11 not holding the backup lock cannot
# LOCK WRITE transactional or non transactional table.
LOCK TABLES t_permanent_innodb READ;
LOCK TABLES t_permanent_myisam READ;
LOCK TABLES t_permanent_innodb WRITE;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
LOCK TABLES t_permanent_myisam WRITE;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
UNLOCK TABLES;
SET GLOBAL tx_read_only = 1;
SET GLOBAL tx_read_only = 0;
connection backup;
BACKUP STAGE BLOCK_COMMIT;
connection con11;
# Between BACKUP BLOCK_COMMIT FLUSH and END:
# Connection con11 not holding the backup lock cannot
# LOCK WRITE transactional or non transactional table.
LOCK TABLES t_permanent_innodb READ;
LOCK TABLES t_permanent_myisam READ;
LOCK TABLES t_permanent_innodb WRITE;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
LOCK TABLES t_permanent_myisam WRITE;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
UNLOCK TABLES;
SET GLOBAL tx_read_only = 1;
SET GLOBAL tx_read_only = 0;
connection backup;
BACKUP STAGE END;
DROP TABLE t_permanent_innodb;
DROP TABLE t_permanent_myisam;
#
# Log tables
#
connection backup;
SET @old_general_log = @@general_log;
SET @old_slow_query_log = @@slow_query_log;
SET @old_log_output = @@log_output;
SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = ON;
SET GLOBAL slow_query_log = ON;
connection con11;
SET @old_long_query_time = @@SESSION.long_query_time;
SET SESSION long_query_time = 0;
connection backup;
BACKUP STAGE START;
BACKUP STAGE FLUSH;
BACKUP STAGE BLOCK_DDL;
BACKUP STAGE BLOCK_COMMIT;
connection con11;
SELECT 1;
1
1
connection backup;
SELECT 1;
1
1
connection con11;
SET SESSION long_query_time = @old_long_query_time;
connection backup;
BACKUP STAGE END;
SET GLOBAL log_output = @old_log_output;
SET GLOBAL slow_query_log = @old_slow_query_log;
SET GLOBAL general_log = @old_general_log;
#-----------------------------------------------------------------------
# Cleanup
#-----------------------------------------------------------------------
SET GLOBAL lock_wait_timeout = <old_lock_wait_timeout>;
disconnect con2;
disconnect con11;
disconnect con12;
disconnect backup;
connection default;