2
# This test is for the consistent snapshot online backup driver
2
# This test is for the consistent snapshot online backup driver.
3
3
# The test is designed to show that a consistent snapshot
4
4
# backup can be taken while data is being inserted and deleted.
6
6
# The test is testing the driver to ensure it is entering a
7
7
# consistent read state during the backup. There are several
8
# breakpoints in the code that can be used. The two most
8
# synchronization points in the code that can be used.
9
# The two most useful ones are:
11
# backup_cs_unlock - occurs after consistent read
11
# after_backup_cs_locked - occurs after consistent read
12
12
# transaction has been started and before the open and
15
# backup_cs_reading - occurs after the open and lock
15
# when_backup_cs_reading - occurs after the open and lock
16
16
# tables during the read tables portion.
18
18
# The following tests test these conditions.
21
# You must use a dedicated connection for getting and releasing locks.
22
# Do not issue a get_lock() or release_lock() in the same connection
23
# (thread) as code that calls BACKUP_BREAKPOINT(). Using the same connection
24
# to get/release locks and run code that issues BACKUP_BREAKPOINTs will result
25
# in an assertion using DEBUG_ASSERT(thd->ull == NULL) from debug_sync_point()
29
21
--source include/have_innodb.inc
30
--source include/have_debug.inc
22
--source include/have_debug_sync.inc
31
23
--source include/not_embedded.inc
26
# Preparative cleanup.
29
SET DEBUG_SYNC= 'reset';
34
30
DROP DATABASE IF EXISTS bup_snapshot;
36
32
--remove_file $MYSQLTEST_VARDIR/master-data/bup_snapshot.bak;
39
CREATE DATABASE bup_snapshot;
36
--echo # Setup for tests.
41
39
connect (con1,localhost,root,,);
42
40
connect (con2,localhost,root,,);
43
connect (con3,localhost,root,,);
47
# Setup the server to use the backup breakpoints
48
SET GLOBAL debug="d,backup_debug:d,backup";
44
CREATE DATABASE bup_snapshot;
54
46
# Create a table and load it with lots of data.
55
47
CREATE TABLE bup_snapshot.t1 (word CHAR(20)) ENGINE=INNODB;
74
66
SELECT COUNT(*) FROM bup_snapshot.t1;
75
67
SELECT COUNT(*) FROM bup_snapshot.t2;
80
# Test 1: Check for consistent read prior to open and lock tables
83
--echo con3: Getting lock on driver.
84
SELECT get_lock("backup_cs_locked", 100);
70
--echo # Test 1: Check for consistent read prior to open and lock tables
86
72
# While a consistent snapshot backup is executed,
87
73
# no external inserts should be visible to the transaction.
75
--echo con1: Activate sync points for the backup statement.
76
SET DEBUG_SYNC= 'after_backup_cs_locked SIGNAL locked WAIT_FOR inserting';
91
78
--echo con1: Backing up database. Spawn this and continue...
92
79
send BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
96
# Wait for lock to be acquired and execution to reach breakpoint
97
--echo con3: Checking locks.
98
let $wait_condition = SELECT state = "debug_sync_point: backup_cs_locked"
99
FROM INFORMATION_SCHEMA.PROCESSLIST
100
WHERE info LIKE "BACKUP DATABASE %";
101
--source include/wait_condition.inc
103
# Start an insert now that CS has a transaction
83
--echo con2: Wait for backup to have locked the transaction.
84
SET DEBUG_SYNC= 'now WAIT_FOR locked';
86
--echo con2: Start an insert now that CS has a transaction
104
87
# The commit blocker will block this until the read lock of
105
88
# the backup is released.
109
send INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
113
# Wait for lock to be acquired and execution to reach breakpoint
114
--echo con3: Checking locks.
115
let $wait_condition = SELECT count(*) = 1
116
FROM INFORMATION_SCHEMA.PROCESSLIST
117
WHERE info LIKE "INSERT INTO bup_snapshot.t1%";
118
--source include/wait_condition.inc
120
--echo con3: Release lock on driver.
121
SELECT release_lock("backup_cs_locked");
90
--echo con2: Activate sync points for the insert statement.
91
SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL inserting';
93
# Insert will wait in wait_if_global_read_lock() until backup is done.
94
INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
96
--echo con2: insert additional rows.
130
97
INSERT INTO bup_snapshot.t1 VALUES("- Yes");
131
98
INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
132
99
DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
135
102
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
136
103
SELECT COUNT(*) FROM bup_snapshot.t1;
138
# Now restore the database and then check to make sure the new rows
139
# were not backed up.
107
--echo con1: retrieve backup result.
111
--echo # Now restore the database and then check to make sure the new rows
112
--echo # were not backed up.
143
114
--echo con1: Dropping the database
144
115
DROP TABLE bup_snapshot.t1;
155
126
remove_file $MYSQLTEST_VARDIR/master-data/bup_snapshot.bak;
158
# Test 2: Check for consistent read after open and lock tables
163
--echo con3: Getting lock on driver.
164
SELECT get_lock("backup_cs_reading", 100);
129
--echo # Test 2: Check for consistent read after open and lock tables
166
131
# While a consistent snapshot backup is executed,
167
132
# no external inserts should be visible to the transaction.
134
--echo con1: Activate sync points for the backup statement.
135
SET DEBUG_SYNC= 'when_backup_cs_reading SIGNAL reading WAIT_FOR inserting';
171
137
--echo con1: Backing up database. Spawn this and continue...
172
138
send BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
176
# Wait for lock to be acquired and execution to reach breakpoint
177
--echo con3: Checking locks.
178
let $wait_condition = SELECT state = "debug_sync_point: backup_cs_reading"
179
FROM INFORMATION_SCHEMA.PROCESSLIST
180
WHERE info LIKE "BACKUP DATABASE%";
181
--source include/wait_condition.inc
183
# Start an insert now that CS has a transaction
142
--echo con2: Wait for backup to start reading.
143
SET DEBUG_SYNC= 'now WAIT_FOR reading';
145
--echo con2: Start an insert now that CS has a transaction
184
146
# The commit blocker will block this until the read lock of
185
147
# the backup is released.
189
send INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
193
# Wait for lock to be acquired and execution to reach breakpoint
194
--echo con3: Checking locks.
195
let $wait_condition = SELECT count(*) = 1
196
FROM INFORMATION_SCHEMA.PROCESSLIST
197
WHERE info LIKE "INSERT INTO bup_snapshot.t1%";
198
--source include/wait_condition.inc
200
--echo con3: Release lock on driver.
201
SELECT release_lock("backup_cs_reading");
149
--echo con2: Activate sync points for the insert statement.
150
SET DEBUG_SYNC= 'after_insert_locked_tables SIGNAL inserting';
152
# Insert will wait in wait_if_global_read_lock() until backup is done.
153
INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
155
--echo con2: insert additional rows.
206
156
INSERT INTO bup_snapshot.t1 VALUES("- Yes");
207
157
INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
208
158
DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
212
162
SELECT COUNT(*) FROM bup_snapshot.t1;
166
--echo con1: retrieve backup result.
215
167
--replace_column 1 #
218
# Now restore the database and then check to make sure the new rows
219
# were not backed up.
170
--echo # Now restore the database and then check to make sure the new rows
171
--echo # were not backed up.
221
173
--echo con1: Dropping the database
222
174
DROP TABLE bup_snapshot.t1;