Commit 0f8cb3c3 authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV-7615: Remove --galera-sst-mode option from mysqldump

Removed 'galera-sst-mode' option from mysqldump and added logic
in wsrep_sst_mysqldump script to retrieve gtid_binlog_state from
donor node and send it to the joiner node.
parent 4c191de3
......@@ -114,7 +114,6 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
opt_slave_apply= 0,
opt_include_master_host_port= 0,
opt_events= 0, opt_comments_used= 0,
opt_galera_sst_mode= 0,
opt_alltspcs=0, opt_notspcs= 0, opt_logging;
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
static ulong opt_max_allowed_packet, opt_net_buffer_length;
......@@ -351,14 +350,6 @@ static struct my_option my_long_options[] =
{"force", 'f', "Continue even if we get an SQL error.",
&ignore_errors, &ignore_errors, 0, GET_BOOL, NO_ARG,
0, 0, 0, 0, 0, 0},
{"galera-sst-mode", 0,
"This mode should normally be used in mysqldump snapshot state transfer "
"(SST) in a Galera cluster. If enabled, mysqldump additionally dumps "
"commands to turn off binary logging and SET global gtid_binlog_state "
"with the current value. Note: RESET MASTER needs to be executed on the "
"server receiving the resulting dump.",
&opt_galera_sst_mode, &opt_galera_sst_mode, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"gtid", 0, "Used together with --master-data=1 or --dump-slave=1."
"When enabled, the output from those options will set the GTID position "
"instead of the binlog file and offset; the file/offset will appear only as "
......@@ -4909,43 +4900,6 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
} /* dump_selected_tables */
/**
Add the following statements to the generated dump:
a) SET @@session.sql_log_bin=OFF;
b) SET @@global.gtid_binlog_state='[N-N-N,...]'
*/
static int wsrep_set_sst_cmds(MYSQL *mysql) {
MYSQL_RES *res;
MYSQL_ROW row;
if (mysql_get_server_version(mysql) < 100005) {
/* @@gtid_binlog_state does not exist. */
return 0;
}
if (mysql_query_with_error_report(mysql, &res, "SELECT "
"@@global.gtid_binlog_state"))
return 1;
if (mysql_num_rows(res) != 1)
/* No entry for @@global.gtid_binlog_state, nothing needs to be done. */
return 0;
if (!(row= mysql_fetch_row(res)) || !(char *)row[0])
return 1;
/* first, add a command to turn off binary logging, */
fprintf(md_result_file, "SET @@session.sql_log_bin=OFF;\n");
/* followed by, a command to set global gtid_binlog_state. */
fprintf(md_result_file, "SET @@global.gtid_binlog_state='%s';\n",
(char*)row[0]);
mysql_free_result(res);
return 0;
}
static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
int have_mariadb_gtid, int use_gtid)
{
......@@ -5942,9 +5896,6 @@ int main(int argc, char **argv)
if (opt_slave_apply && add_stop_slave())
goto err;
if (opt_galera_sst_mode && wsrep_set_sst_cmds(mysql))
goto err;
if (opt_master_data && do_show_master_status(mysql, consistent_binlog_pos,
have_mariadb_gtid, opt_use_gtid))
goto err;
......
#
# Test for mysqldump's galera-sst-mode option
#
#
# MDEV-6490: mysqldump unknown option --galera-sst-mode
#
CREATE DATABASE bug6490;
USE bug6490;
CREATE TABLE t1(c1 INT);
INSERT INTO t1 values (1);
INSERT INTO t1 values (2);
# Save the current gtid_binlog_state.
# Take a dump of bug6490 database
DROP TABLE t1;
# Load the dump
RESET MASTER;
SELECT * from t1;
c1
1
2
# Compare the two gtid_binlog_state's
# Cleanup
DROP DATABASE bug6490;
# End of test
# Embedded server doesn't support external clients
--source include/not_embedded.inc
# Binlog is required
--source include/have_log_bin.inc
--echo #
--echo # Test for mysqldump's galera-sst-mode option
--echo #
--echo #
--echo # MDEV-6490: mysqldump unknown option --galera-sst-mode
--echo #
CREATE DATABASE bug6490;
USE bug6490;
CREATE TABLE t1(c1 INT);
INSERT INTO t1 values (1);
INSERT INTO t1 values (2);
--echo # Save the current gtid_binlog_state.
--let $before= `SELECT @@global.gtid_binlog_state`
--echo # Take a dump of bug6490 database
--exec $MYSQL_DUMP --galera-sst-mode bug6490 > $MYSQLTEST_VARDIR/tmp/bug6490.sql
DROP TABLE t1;
--echo # Load the dump
RESET MASTER;
--exec $MYSQL -uroot bug6490 < $MYSQLTEST_VARDIR/tmp/bug6490.sql
SELECT * from t1;
--echo # Compare the two gtid_binlog_state's
--let $after= `SELECT @@global.gtid_binlog_state`
if (`SELECT STRCMP($before, $after)`)
{
--die ERROR: The two gtid_binlog_state's did not match.
}
--echo # Cleanup
--remove_file $MYSQLTEST_VARDIR/tmp/bug6490.sql
DROP DATABASE bug6490;
--echo # End of test
......@@ -17,10 +17,14 @@
# This is a reference script for mysqldump-based state snapshot tansfer
# This variable is not used in mysqldump sst, so better initialize it
# to avoid shell's "parameter not set" message.
WSREP_SST_OPT_CONF=""
. $(dirname $0)/wsrep_sst_common
PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
EINVAL=22
PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
local_ip()
{
......@@ -70,12 +74,6 @@ if test -n "$WSREP_SST_OPT_PSWD"; then AUTH="$AUTH -p$WSREP_SST_OPT_PSWD"; fi
STOP_WSREP="SET wsrep_on=OFF;"
# NOTE: we don't use --routines here because we're dumping mysql.proc table
MYSQLDUMP="mysqldump $AUTH -S$WSREP_SST_OPT_SOCKET \
--add-drop-database --add-drop-table --skip-add-locks --create-options \
--disable-keys --extended-insert --skip-lock-tables --quick --set-charset \
--skip-comments --flush-privileges --all-databases"
# mysqldump cannot restore CSV tables, fix this issue
CSV_TABLES_FIX="
set sql_mode='';
......@@ -98,9 +96,48 @@ DROP PREPARE stmt;"
SET_START_POSITION="SET GLOBAL wsrep_start_position='$WSREP_SST_OPT_GTID';"
# Retrieve the donor's @@global.gtid_binlog_state.
GTID_BINLOG_STATE=$(echo "SHOW GLOBAL VARIABLES LIKE 'gtid_binlog_state'" |\
mysql $AUTH -S$WSREP_SST_OPT_SOCKET --disable-reconnect --connect_timeout=10 |\
tail -1 | awk -F ' ' '{ print $2 }')
MYSQL="mysql $AUTH -h$WSREP_SST_OPT_HOST -P$WSREP_SST_OPT_PORT "\
"--disable-reconnect --connect_timeout=10"
# Check if binary logging is enabled on the joiner node.
# Note: SELECT cannot be used at this point.
LOG_BIN=$(echo "SHOW VARIABLES LIKE 'log_bin'" | $MYSQL |\
tail -1 | awk -F ' ' '{ print $2 }')
# Check the joiner node's server version.
SERVER_VERSION=$(echo "SHOW VARIABLES LIKE 'version'" | $MYSQL |\
tail -1 | awk -F ' ' '{ print $2 }')
RESET_MASTER=""
SET_GTID_BINLOG_STATE=""
SQL_LOG_BIN_OFF=""
# Safety check
if echo $SERVER_VERSION | grep '^10.0' > /dev/null
then
# If binary logging is enabled on the joiner node, we need to copy donor's
# gtid_binlog_state to joiner. In order to do that, a RESET MASTER must be
# executed to erase binary logs (if any). Binary logging should also be
# turned off for the session so that gtid state does not get altered while
# the dump gets replayed on joiner.
if [[ "$LOG_BIN" == 'ON' ]]; then
RESET_MASTER="RESET MASTER;"
SET_GTID_BINLOG_STATE="SET @@global.gtid_binlog_state='$GTID_BINLOG_STATE';"
SQL_LOG_BIN_OFF="SET @@session.sql_log_bin=OFF;"
fi
fi
# NOTE: we don't use --routines here because we're dumping mysql.proc table
MYSQLDUMP="mysqldump $AUTH -S$WSREP_SST_OPT_SOCKET \
--add-drop-database --add-drop-table --skip-add-locks --create-options \
--disable-keys --extended-insert --skip-lock-tables --quick --set-charset \
--skip-comments --flush-privileges --all-databases"
# need to disable logging when loading the dump
# reason is that dump contains ALTER TABLE for log tables, and
# this causes an error if logging is enabled
......@@ -113,12 +150,14 @@ $MYSQL -e"$STOP_WSREP SET GLOBAL SLOW_QUERY_LOG=OFF"
RESTORE_GENERAL_LOG="SET GLOBAL GENERAL_LOG=$GENERAL_LOG_OPT;"
RESTORE_SLOW_QUERY_LOG="SET GLOBAL SLOW_QUERY_LOG=$SLOW_LOG_OPT;"
if [ $WSREP_SST_OPT_BYPASS -eq 0 ]
then
(echo $STOP_WSREP && $MYSQLDUMP && echo $CSV_TABLES_FIX \
&& echo $RESTORE_GENERAL_LOG && echo $RESTORE_SLOW_QUERY_LOG \
&& echo $SET_START_POSITION \
|| echo "SST failed to complete;") | $MYSQL
(echo $STOP_WSREP && echo $RESET_MASTER && \
echo $SET_GTID_BINLOG_STATE && echo $SQL_LOG_BIN_OFF && \
echo $STOP_WSREP && $MYSQLDUMP && echo $CSV_TABLES_FIX && \
echo $RESTORE_GENERAL_LOG && echo $RESTORE_SLOW_QUERY_LOG && \
echo $SET_START_POSITION || echo "SST failed to complete;") | $MYSQL
else
wsrep_log_info "Bypassing state dump."
echo $SET_START_POSITION | $MYSQL
......
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