~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to mysql-test/t/backup_lock_myisam.test

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This test was created to ensure appropriate locks are obtained on the myisam
 
3
# tables during a myisam native driver restore. See BUG#36749.
 
4
#
 
5
# The test uses two connections and debug synchronization to ensure the restore
 
6
# in the middle of processing when a trigger attempts to insert data.
 
7
#
 
8
 
 
9
--source include/not_embedded.inc
 
10
--source include/have_innodb.inc
 
11
--source include/have_debug_sync.inc
 
12
 
 
13
SET DEBUG_SYNC= 'RESET';
 
14
 
 
15
connect(con1, localhost, root,,);
 
16
connect(con2, localhost, root,,);
 
17
connect(breakpoints, localhost, root,,);
 
18
 
 
19
--echo From con1:
 
20
--connection con1
 
21
 
 
22
--disable_warnings
 
23
DROP DATABASE IF EXISTS db1;
 
24
DROP DATABASE IF EXISTS db2;
 
25
DROP DATABASE IF EXISTS db3;
 
26
--enable_warnings
 
27
 
 
28
--error 0, 1
 
29
--remove_file $MYSQLTEST_VARDIR/master-data/db1.bak
 
30
 
 
31
--error 0, 1
 
32
--remove_file $MYSQLTEST_VARDIR/master-data/db3.bak
 
33
 
 
34
--echo Create database 1 and a table then populate it
 
35
CREATE DATABASE db1;
 
36
CREATE TABLE db1.t1 (a INT) ENGINE=MYISAM;
 
37
 
 
38
INSERT INTO db1.t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);
 
39
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
40
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
41
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
42
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
43
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
44
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
45
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
46
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
47
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
48
 
 
49
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
50
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
51
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
52
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
53
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
54
INSERT INTO db1.t1 SELECT * FROM db1.t1;
 
55
 
 
56
CREATE TABLE db1.t2 (a int) ENGINE=MEMORY;
 
57
 
 
58
INSERT INTO db1.t2 VALUES (1),(2),(3),(4),(5);
 
59
 
 
60
CREATE TABLE db1.t3 (a int) ENGINE=INNODB;
 
61
 
 
62
INSERT INTO db1.t3 VALUES (11),(12),(13);
 
63
 
 
64
--echo Show initial count of table
 
65
SELECT COUNT(*) FROM db1.t1;
 
66
 
 
67
SELECT COUNT(*) FROM db1.t2;
 
68
 
 
69
SELECT COUNT(*) FROM db1.t3;
 
70
 
 
71
--echo From con2:
 
72
--connection con2
 
73
 
 
74
--echo Create database 2 and a table then populate it and add a trigger
 
75
--echo that updates the table in database 1
 
76
 
 
77
CREATE DATABASE db2;
 
78
CREATE TABLE db2.t2 (A INT);
 
79
 
 
80
DELIMITER |;
 
81
 
 
82
CREATE TRIGGER db2.trg AFTER INSERT ON db2.t2 FOR EACH ROW
 
83
BEGIN
 
84
  INSERT INTO db1.t1 VALUES ('99');
 
85
END|
 
86
 
 
87
delimiter ;|
 
88
 
 
89
--echo From con1:
 
90
--connection con1
 
91
 
 
92
--echo Now do the backup 
 
93
--replace_column 1 #
 
94
BACKUP DATABASE db1 TO 'db1.bak';
 
95
 
 
96
DROP DATABASE db1;
 
97
 
 
98
--echo now start the restore and while the restore is running, fire the trigger
 
99
--echo activate synchronization points for restore.
 
100
SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
 
101
--send RESTORE FROM 'db1.bak'
 
102
 
 
103
--echo From breakpoints:
 
104
--connection breakpoints
 
105
--echo Wait for restore to reach its synchronization point.
 
106
SET DEBUG_SYNC= 'now WAIT_FOR wait_for_restore';
 
107
 
 
108
--echo breakpoints: Show process list.
 
109
--replace_column 1 #
 
110
query_vertical SELECT id, command, state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 
111
WHERE info LIKE "RESTORE%";
 
112
 
 
113
--echo From con2:
 
114
--connection con2
 
115
--echo Now do the insert while restore is running.
 
116
send INSERT INTO db2.t2 VALUES (0);
 
117
 
 
118
--echo From breakpoints:
 
119
--connection breakpoints
 
120
--echo breakpoints: Sending finish signal to wake restore.
 
121
SET DEBUG_SYNC= 'now SIGNAL finish';
 
122
 
 
123
--echo Reattach to connection 2 and finish.
 
124
--connection con2
 
125
--reap
 
126
 
 
127
--echo Reattach to connection 1 and finish.
 
128
--connection con1
 
129
--replace_column 1 #
 
130
--reap
 
131
 
 
132
--echo Show the count for t1. It should be 1 more than before restore.
 
133
SELECT COUNT(*) FROM db1.t1;
 
134
 
 
135
SELECT * FROM db1.t2;
 
136
 
 
137
SELECT * FROM db1.t3;
 
138
 
 
139
SET DEBUG_SYNC= 'RESET';
 
140
 
 
141
#
 
142
# BUG#36778 - Data loss during select at time of restore.
 
143
#
 
144
 
 
145
DELETE FROM db2.t2;
 
146
 
 
147
--echo now start the restore and while the restore is running, fire the trigger
 
148
--echo activate synchronization points for restore.
 
149
SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
 
150
--send RESTORE FROM 'db1.bak'
 
151
 
 
152
--echo From breakpoints:
 
153
--connection breakpoints
 
154
--echo Wait for restore to reach its synchronization point.
 
155
SET DEBUG_SYNC= 'now WAIT_FOR wait_for_restore';
 
156
 
 
157
--echo breakpoints: Show process list.
 
158
--replace_column 1 #
 
159
query_vertical SELECT id, command, state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 
160
WHERE info LIKE "RESTORE%";
 
161
 
 
162
--echo From con2:
 
163
--connection con2
 
164
--echo Now do the select while restore is running.
 
165
send SELECT * FROM db1.t1 limit 10;
 
166
 
 
167
--echo From breakpoints:
 
168
--connection breakpoints
 
169
--echo breakpoints: Sending finish signal to wake restore.
 
170
SET DEBUG_SYNC= 'now SIGNAL finish';
 
171
 
 
172
--echo Reattach to connection 2 and finish.
 
173
--connection con2
 
174
--reap
 
175
 
 
176
--echo Reattach to connection 1 and finish.
 
177
--connection con1
 
178
--replace_column 1 #
 
179
--reap
 
180
 
 
181
--echo Show the count for t1. It should be the same as before restore.
 
182
SELECT COUNT(*) FROM db1.t1;
 
183
 
 
184
SELECT * FROM db1.t2;
 
185
 
 
186
SELECT * FROM db1.t3;
 
187
 
 
188
SET DEBUG_SYNC= 'RESET';
 
189
 
 
190
#
 
191
# BUG#36782 - Data loss with restore of view.
 
192
#
 
193
 
 
194
--echo Create a database with a table and a view using the MyISAM engine.
 
195
CREATE DATABASE db3;
 
196
CREATE TABLE db3.t1(name CHAR(10)) ENGINE=MYISAM;
 
197
INSERT INTO db3.t1 VALUES('A'),('B'),('C'),('D');
 
198
CREATE VIEW db3.v1 AS SELECT * FROM db3.t1;
 
199
 
 
200
--echo Show the data before backup
 
201
SELECT * FROM db3.t1;
 
202
SELECT * FROM db3.v1;
 
203
 
 
204
--echo Backup the database.
 
205
--replace_column 1 #
 
206
BACKUP DATABASE db3 TO 'db3.bak';
 
207
 
 
208
--echo Now drop then restore the database.
 
209
DROP DATABASE db3;
 
210
--replace_column 1 #
 
211
RESTORE FROM 'db3.bak';
 
212
 
 
213
--echo Show the table and view.
 
214
SHOW FULL TABLES FROM db3;
 
215
 
 
216
--echo Show the data after restore.
 
217
SELECT * FROM db3.v1;
 
218
SELECT * FROM db3.t1;
 
219
 
 
220
--echo cleanup
 
221
DROP DATABASE db1;
 
222
DROP DATABASE db2;
 
223
DROP DATABASE db3;
 
224
 
 
225
--error 0, 1
 
226
--remove_file $MYSQLTEST_VARDIR/master-data/db1.bak
 
227
 
 
228
--error 0, 1
 
229
--remove_file $MYSQLTEST_VARDIR/master-data/db3.bak