|
| 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