Commit 80075ba0 authored by Vlad Lesin's avatar Vlad Lesin

MDEV-19264 Better support MariaDB GTID for Mariabackup's --slave-info option

Parse SHOW SLAVE STATUS output for the "Using_Gtid" column. If the value
is "No", then old log file and position is backed up, otherwise gtid_slave_pos
is backed up.
parent ae8ff3a0
......@@ -1199,6 +1199,7 @@ write_slave_info(MYSQL *connection)
char *master = NULL;
char *filename = NULL;
char *gtid_executed = NULL;
char *using_gtid = NULL;
char *position = NULL;
char *gtid_slave_pos = NULL;
char *ptr;
......@@ -1209,6 +1210,7 @@ write_slave_info(MYSQL *connection)
{"Relay_Master_Log_File", &filename},
{"Exec_Master_Log_Pos", &position},
{"Executed_Gtid_Set", &gtid_executed},
{"Using_Gtid", &using_gtid},
{NULL, NULL}
};
......@@ -1249,7 +1251,8 @@ write_slave_info(MYSQL *connection)
ut_a(asprintf(&mysql_slave_position,
"master host '%s', purge list '%s'",
master, gtid_executed) != -1);
} else if (gtid_slave_pos && *gtid_slave_pos) {
} else if (gtid_slave_pos && *gtid_slave_pos &&
!(using_gtid && !strncmp(using_gtid, "No", 2))) {
/* MariaDB >= 10.0 with GTID enabled */
result = backup_file_printf(XTRABACKUP_SLAVE_INFO,
"SET GLOBAL gtid_slave_pos = '%s';\n"
......
include/master-slave.inc
[connection master]
connection slave;
###############
# If Using_Gtid != 'No', backup gtid_slave_pos
########################
include/stop_slave.inc
change master to master_use_gtid=slave_pos;
include/start_slave.inc
connection master;
CREATE TABLE t(i INT);
connection slave;
"using_gtid: Slave_Pos"
FOUND 1 /gtid_slave_pos/ in xtrabackup_slave_info
NOT FOUND /MASTER_LOG_FILE/ in xtrabackup_slave_info
###############
# If Using_Gtid != 'No' and !gtid_slave_pos, backup master position
########################
include/stop_slave.inc
SET GLOBAL gtid_slave_pos="";
NOT FOUND /gtid_slave_pos/ in xtrabackup_slave_info
FOUND 1 /MASTER_LOG_FILE/ in xtrabackup_slave_info
###############
# If Using_Gtid == 'No', backup Exec_Master_Log_Pos
########################
change master to master_use_gtid=no;
include/start_slave.inc
connection master;
INSERT INTO t VALUES(1);
connection slave;
"using_gtid: No"
NOT FOUND /gtid_slave_pos/ in xtrabackup_slave_info
FOUND 1 /MASTER_LOG_FILE/ in xtrabackup_slave_info
connection master;
DROP TABLE t;
connection slave;
include/rpl_end.inc
--source include/master-slave.inc
--connection slave
--echo ###############
--echo # If Using_Gtid != 'No', backup gtid_slave_pos
--echo ########################
--source include/stop_slave.inc
change master to master_use_gtid=slave_pos;
--source include/start_slave.inc
--connection master
CREATE TABLE t(i INT);
--sync_slave_with_master
--let $using_gtid=query_get_value(SHOW SLAVE STATUS,Using_Gtid,1)
--echo "using_gtid: $using_gtid"
--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 --slave-info --backup --target-dir=$targetdir;
--enable_result_log
--let SEARCH_FILE=$targetdir/xtrabackup_slave_info
--let SEARCH_PATTERN=gtid_slave_pos
--source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=MASTER_LOG_FILE
--source include/search_pattern_in_file.inc
rmdir $targetdir;
--echo ###############
--echo # If Using_Gtid != 'No' and !gtid_slave_pos, backup master position
--echo ########################
--source include/stop_slave.inc
SET GLOBAL gtid_slave_pos="";
--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 --slave-info --backup --target-dir=$targetdir;
--enable_result_log
--let SEARCH_FILE=$targetdir/xtrabackup_slave_info
--let SEARCH_PATTERN=gtid_slave_pos
--source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=MASTER_LOG_FILE
--source include/search_pattern_in_file.inc
rmdir $targetdir;
--echo ###############
--echo # If Using_Gtid == 'No', backup Exec_Master_Log_Pos
--echo ########################
change master to master_use_gtid=no;
--source include/start_slave.inc
--connection master
INSERT INTO t VALUES(1);
--sync_slave_with_master
--let $using_gtid=query_get_value(SHOW SLAVE STATUS,Using_Gtid,1)
--echo "using_gtid: $using_gtid"
--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 --slave-info --backup --target-dir=$targetdir;
--enable_result_log
--let SEARCH_FILE=$targetdir/xtrabackup_slave_info
--let SEARCH_PATTERN=gtid_slave_pos
--source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=MASTER_LOG_FILE
--source include/search_pattern_in_file.inc
rmdir $targetdir;
# Cleanup
--connection master
DROP TABLE t;
--sync_slave_with_master
--source include/rpl_end.inc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment