Skip to content

Commit

Permalink
MDEV-6490: mysqldump unknown option --galera-sst-mode
Browse files Browse the repository at this point in the history
* Merged patches pushed to 10.0.
* Additional fix in wsrep_sst_mysqldump.sh to control use
  of RESET MASTER and mysqldump's galera-sst-mode option based
  on joiner's @@log-bin value.
  • Loading branch information
Nirbhay Choubey committed Aug 7, 2014
1 parent 746c755 commit f842099
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 26 deletions.
2 changes: 0 additions & 2 deletions client/client_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ enum options_client
OPT_REPORT_PROGRESS,
OPT_SKIP_ANNOTATE_ROWS_EVENTS,
OPT_SSL_CRL, OPT_SSL_CRLPATH,
#ifdef WITH_WSREP
OPT_GALERA_SST_MODE,
#endif
OPT_MAX_CLIENT_OPTION /* should be always the last */
};

Expand Down
24 changes: 9 additions & 15 deletions client/mysqldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ 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,
#ifdef WITH_WSREP
opt_galera_sst_mode= 0,
#endif
opt_alltspcs=0, opt_notspcs= 0;
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;
Expand Down Expand Up @@ -349,14 +347,14 @@ 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},
#ifdef WITH_WSREP
{"galera-sst-mode", OPT_GALERA_SST_MODE, "This mode is normally used "
"in mysqldump snapshot-state transfer in a Galera cluster. If enabled, "
"mysqldump additionally emits statements to turn off binary logging and "
"set global gtid_binlog_state with the current value.",
{"galera-sst-mode", OPT_GALERA_SST_MODE,
"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},
#endif
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, "
Expand Down Expand Up @@ -4810,13 +4808,12 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
} /* dump_selected_tables */


#ifdef WITH_WSREP
/**
Additionally emit the following statements :
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_add_sst_mode_cmds(MYSQL *mysql) {
static int wsrep_set_sst_cmds(MYSQL *mysql) {
MYSQL_RES *res;
MYSQL_ROW row;

Expand Down Expand Up @@ -4846,7 +4843,6 @@ static int wsrep_add_sst_mode_cmds(MYSQL *mysql) {
mysql_free_result(res);
return 0;
}
#endif

static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos)
{
Expand Down Expand Up @@ -5793,10 +5789,8 @@ int main(int argc, char **argv)
if (opt_slave_apply && add_stop_slave())
goto err;

#ifdef WITH_WSREP
if (opt_galera_sst_mode && wsrep_add_sst_mode_cmds(mysql))
if (opt_galera_sst_mode && wsrep_set_sst_cmds(mysql))
goto err;
#endif

if (opt_master_data && do_show_master_status(mysql, consistent_binlog_pos))
goto err;
Expand Down
24 changes: 24 additions & 0 deletions mysql-test/r/galera_sst_mode.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# 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
43 changes: 43 additions & 0 deletions mysql-test/t/galera_sst_mode.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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
42 changes: 33 additions & 9 deletions scripts/wsrep_sst_mysqldump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,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 --galera-sst-mode"

# mysqldump cannot restore CSV tables, fix this issue
CSV_TABLES_FIX="
set sql_mode='';
Expand All @@ -106,6 +100,39 @@ SET_START_POSITION="SET GLOBAL wsrep_start_position='$WSREP_SST_OPT_GTID';"
MYSQL="mysql $AUTH -h$WSREP_SST_OPT_HOST -P$WSREP_SST_OPT_PORT "\
"--disable-reconnect --connect_timeout=10"

RESET_MASTER=""
OPT_GALERA_SST_MODE=""
# 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)
LOG_BIN=$(echo $LOG_BIN | awk -F ' ' '{ print $4 }')

# Check the joiner node's server version.
SERVER_VERSION=$(echo "SHOW VARIABLES LIKE 'version'" | $MYSQL)
SERVER_VERSION=$(echo $SERVER_VERSION | awk -F ' ' '{ print $4 }')

# Safety check
if echo $SERVER_VERSION | grep '^10.0' > /dev/null
then
# Check if binary logging is enabled on the Joiner node. If it is enabled,
# RESET MASTER needs to be executed on the Joiner node. Also, mysqldump
# should be executed with additional 'galera-sst-mode' option so that it
# adds a command to set gtid_binlog_state with that of Donor node in the
# dump, to be executed on the Joiner.
if [[ "$LOG_BIN" == 'ON' ]]; then
# Reset master for 10.0 to clear gtid state.
RESET_MASTER="RESET MASTER;"
# Set the galera-sst-mode option for mysqldump.
OPT_GALERA_SST_MODE="--galera-sst-mode"
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 $OPT_GALERA_SST_MODE"

# 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
Expand All @@ -118,9 +145,6 @@ $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;"

# reset master for 10.0 to clear gtid state
RESET_MASTER="RESET MASTER;"


if [ $WSREP_SST_OPT_BYPASS -eq 0 ]
then
Expand Down

0 comments on commit f842099

Please sign in to comment.