SET DEBUG_SYNC= 'reset';
DROP DATABASE IF EXISTS bup_snapshot;
#
# Setup for tests.
#
CREATE DATABASE bup_snapshot;
CREATE TABLE bup_snapshot.t1 (word CHAR(20)) ENGINE=INNODB;
INSERT INTO bup_snapshot.t1 VALUES ("01 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("02 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("03 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("04 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("05 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("06 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("07 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("08 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("09 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("10 Some data to test");
CREATE TABLE bup_snapshot.t2 (a int) ENGINE=MEMORY;
INSERT INTO bup_snapshot.t2 VALUES (1), (2), (3), (4), (5);
con1: Show that the new data doesn't exist before backup.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
10
SELECT COUNT(*) FROM bup_snapshot.t2;
COUNT(*)
5
#
# Test 1: Check for consistent read prior to open and lock tables
#
con1: Activate sync points for the backup statement.
SET DEBUG_SYNC= 'after_backup_cs_locked SIGNAL locked WAIT_FOR inserting';
con1: Backing up database. Spawn this and continue...
BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
con2: Wait for backup to have locked the transaction.
SET DEBUG_SYNC= 'now WAIT_FOR locked';
con2: Start an insert now that CS has a transaction 
con2: Activate sync points for the insert statement.
SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL inserting';
INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
con2: insert additional rows.
INSERT INTO bup_snapshot.t1 VALUES("- Yes");
INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
con2: Showing the data after inserts.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
- Dave Mathews
- Yes
- Jethro Tull
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
12
con1: retrieve backup result.
backup_id
#
# Now restore the database and then check to make sure the new rows
# were not backed up.
con1: Dropping the database
DROP TABLE bup_snapshot.t1;
con1: Restoring the database
RESTORE FROM "bup_snapshot.bak" OVERWRITE;
backup_id
#
con1: Showing the data (no new data should be here).
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
10
SELECT COUNT(*) FROM bup_snapshot.t2;
COUNT(*)
5
#
# Test 2: Check for consistent read after open and lock tables
#
con1: Activate sync points for the backup statement.
SET DEBUG_SYNC= 'when_backup_cs_reading SIGNAL reading WAIT_FOR inserting';
con1: Backing up database. Spawn this and continue...
BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
con2: Wait for backup to start reading.
SET DEBUG_SYNC= 'now WAIT_FOR reading';
con2: Start an insert now that CS has a transaction 
con2: Activate sync points for the insert statement.
SET DEBUG_SYNC= 'after_insert_locked_tables SIGNAL inserting';
INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
con2: insert additional rows.
INSERT INTO bup_snapshot.t1 VALUES("- Yes");
INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
con2: Showing the data after inserts.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
- Dave Mathews
- Yes
- Jethro Tull
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
12
con1: retrieve backup result.
backup_id
#
# Now restore the database and then check to make sure the new rows
# were not backed up.
con1: Dropping the database
DROP TABLE bup_snapshot.t1;
con1: Restoring the database
RESTORE FROM "bup_snapshot.bak" OVERWRITE;
backup_id
#
con1: Showing the data (no new data should be here).
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
10
SELECT COUNT(*) FROM bup_snapshot.t2;
COUNT(*)
5
SET DEBUG_SYNC= 'reset';
DROP DATABASE bup_snapshot;
