Skip to content

Commit e6bd476

Browse files
committed
Test case for provisioning a slave with mariabackup --no-lock
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
1 parent 167fe66 commit e6bd476

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[mysqld.1]
2+
log-slave-updates
3+
loose-innodb
4+
5+
[mysqld.2]
6+
log-slave-updates
7+
loose-innodb
8+
9+
[ENV]
10+
SERVER_MYPORT_1= @mysqld.1.port
11+
SERVER_MYSOCK_1= @mysqld.1.socket
12+
SERVER_MYPORT_2= @mysqld.2.port
13+
SERVER_MYSOCK_2= @mysqld.2.socket
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
RESET MASTER;
2+
CREATE TABLE t1(a varchar(60) PRIMARY KEY, b VARCHAR(60)) ENGINE INNODB;
3+
INSERT INTO t1 VALUES(1, NULL);
4+
CREATE TABLE t2 (val INT) ENGINE=InnoDB;
5+
INSERT INTO t2 VALUES (0);
6+
connect con1,localhost,root,,;
7+
*** Start a background load...
8+
CALL gen_load();
9+
connection default;
10+
*** Doing backup...
11+
*** Doing prepare...
12+
*** Stop the background load...
13+
UPDATE t2 SET val=1;
14+
connection con1;
15+
connection default;
16+
disconnect con1;
17+
*** Provision a new slave from the backup
18+
connect server2,127.0.0.1,root,,,$SERVER_MYPORT_2;
19+
*** Stopping provisioned server
20+
*** Removing old datadir for provisioned server
21+
*** Provision new server from backup
22+
# restart
23+
*** Configure slave position from xtrabackup_binlog_pos_innodb
24+
CREATE TABLE t3 (file VARCHAR(255), pos INT) ENGINE=InnoDB;
25+
LOAD DATA LOCAL INFILE "BASEDIR/xtrabackup_binlog_pos_innodb"
26+
INTO TABLE t3 FIELDS ESCAPED BY '' (file, pos);
27+
CHANGE MASTER TO
28+
master_port=PORT, master_host='127.0.0.1', master_user='root',
29+
master_log_file= "MASTER_FILE",
30+
master_log_pos= MASTER_POS;
31+
START SLAVE;
32+
connection default;
33+
connection server2;
34+
connection server2;
35+
STOP SLAVE;
36+
RESET SLAVE ALL;
37+
DROP PROCEDURE gen_load;
38+
DROP TABLE t1, t2, t3;
39+
connection default;
40+
DROP PROCEDURE gen_load;
41+
DROP TABLE t1, t2;
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
--source include/have_innodb.inc
2+
--source include/have_log_bin.inc
3+
4+
# Test provisioning a slave from an existing server, using mariabackup --no-lock
5+
# and the binlog position recovered from InnoDB redo log.
6+
let $basedir=$MYSQLTEST_VARDIR/tmp/backup;
7+
8+
RESET MASTER;
9+
CREATE TABLE t1(a varchar(60) PRIMARY KEY, b VARCHAR(60)) ENGINE INNODB;
10+
INSERT INTO t1 VALUES(1, NULL);
11+
CREATE TABLE t2 (val INT) ENGINE=InnoDB;
12+
INSERT INTO t2 VALUES (0);
13+
14+
--disable_query_log
15+
--delimiter //
16+
CREATE PROCEDURE gen_load()
17+
MODIFIES SQL DATA
18+
BEGIN
19+
DECLARE i INT;
20+
DECLARE flag TYPE OF t2.val;
21+
SET i = 0;
22+
load_loop: LOOP
23+
SELECT val INTO flag FROM t2;
24+
IF NOT (flag=0) THEN
25+
LEAVE load_loop;
26+
END IF;
27+
START TRANSACTION;
28+
INSERT INTO t1 VALUES (CONCAT("AbAdCaFe", LPAD(i, 6, "0")), @@SESSION.last_gtid);
29+
COMMIT;
30+
SET i = i + 1;
31+
END LOOP;
32+
END
33+
//
34+
--delimiter ;
35+
--enable_query_log
36+
37+
connect (con1,localhost,root,,);
38+
--echo *** Start a background load...
39+
send CALL gen_load();
40+
41+
--connection default
42+
--echo *** Doing backup...
43+
--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$basedir --no-lock
44+
--echo *** Doing prepare...
45+
--exec $XTRABACKUP --prepare --rollback-xa --binlog-info=1 --target-dir=$basedir
46+
47+
--echo *** Stop the background load...
48+
UPDATE t2 SET val=1;
49+
--connection con1
50+
reap;
51+
--connection default
52+
disconnect con1;
53+
--let $count_master= `SELECT COUNT(*) FROM t1`
54+
55+
--echo *** Provision a new slave from the backup
56+
--connect (server2,127.0.0.1,root,,,$SERVER_MYPORT_2)
57+
--let $datadir_2= `SELECT @@datadir`
58+
59+
--echo *** Stopping provisioned server
60+
--source include/shutdown_mysqld.inc
61+
62+
--echo *** Removing old datadir for provisioned server
63+
--rmdir $datadir_2
64+
65+
--echo *** Provision new server from backup
66+
--exec $XTRABACKUP --copy-back --datadir=$datadir_2 --target-dir=$basedir
67+
68+
--source include/start_mysqld.inc
69+
70+
--echo *** Configure slave position from xtrabackup_binlog_pos_innodb
71+
CREATE TABLE t3 (file VARCHAR(255), pos INT) ENGINE=InnoDB;
72+
--replace_result $basedir BASEDIR
73+
--disable_warnings
74+
eval LOAD DATA LOCAL INFILE "$basedir/xtrabackup_binlog_pos_innodb"
75+
INTO TABLE t3 FIELDS ESCAPED BY '' (file, pos);
76+
--enable_warnings
77+
78+
# Remove leading ./ from filename (leading .\ on windows).
79+
--let provision_master_file= `SELECT REGEXP_REPLACE(file, "^[.].", "") FROM t3`
80+
--let provision_master_pos= `SELECT pos FROM t3`
81+
82+
--replace_result $SERVER_MYPORT_1 PORT $provision_master_file MASTER_FILE $provision_master_pos MASTER_POS
83+
eval CHANGE MASTER TO
84+
master_port=$SERVER_MYPORT_1, master_host='127.0.0.1', master_user='root',
85+
master_log_file= "$provision_master_file",
86+
master_log_pos= $provision_master_pos;
87+
START SLAVE;
88+
89+
--connection default
90+
--save_master_pos
91+
92+
--connection server2
93+
--sync_with_master
94+
--let $count_slave= `SELECT COUNT(*) FROM t1`
95+
if ($count_master != $count_slave) {
96+
--echo *** ERROR: Table on master has $count_master rows, but table on provisioned slave has $count_slave rows
97+
--die Row difference on provisioned slave.
98+
}
99+
100+
# Cleanup
101+
102+
--connection server2
103+
STOP SLAVE;
104+
RESET SLAVE ALL;
105+
DROP PROCEDURE gen_load;
106+
DROP TABLE t1, t2, t3;
107+
108+
--connection default
109+
DROP PROCEDURE gen_load;
110+
DROP TABLE t1, t2;
111+
112+
rmdir $basedir;

0 commit comments

Comments
 (0)