Skip to content

Commit b6385e0

Browse files
ParadoxV5Max Samoilenko
andcommitted
MDEV-7611 mysqldump --dump-slave always starts stopped slave
Store the _SLAVE_ STATUS when pausing replicas for `mariadb-dump --dump-slave`; use that (instead of a new SHOW _SLAVE_ STATUS) to resume replicas when the program ends. > When making a dump with --dump-slave option, upon completion mysqldump > starts slave threads [IO & SQL for all multi-source connections] even > if they were not stopped by mysqldump itself. > This behavior breaks delayed/manually synchronized > slaves which have not to be running all the time. > ⸺ MDEV-7611 Co-authored-by: Max Samoilenko <maxim.samoilenko@gmail.com> Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
1 parent add6a05 commit b6385e0

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

client/mysqldump.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static DYNAMIC_STRING extended_row;
184184
static DYNAMIC_STRING dynamic_where;
185185
static MYSQL_RES *get_table_name_result= NULL;
186186
static MEM_ROOT glob_root;
187-
static MYSQL_RES *routine_res, *routine_list_res;
187+
static MYSQL_RES *routine_res, *routine_list_res, *slave_status_res= NULL;
188188

189189

190190
#include <sslopt-vars.h>
@@ -1908,6 +1908,8 @@ static void free_resources()
19081908
mysql_free_result(routine_res);
19091909
if (routine_list_res)
19101910
mysql_free_result(routine_list_res);
1911+
if (slave_status_res)
1912+
mysql_free_result(slave_status_res);
19111913
if (mysql)
19121914
{
19131915
mysql_close(mysql);
@@ -6257,17 +6259,19 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
62576259

62586260
static int do_stop_slave_sql(MYSQL *mysql_con)
62596261
{
6260-
MYSQL_RES *slave;
62616262
MYSQL_ROW row;
6263+
DBUG_ASSERT(
6264+
!slave_status_res // do_stop_slave_sql() should only be called once
6265+
);
62626266

6263-
if (mysql_query_with_error_report(mysql_con, &slave,
6267+
if (mysql_query_with_error_report(mysql_con, &slave_status_res,
62646268
multi_source ?
62656269
"SHOW ALL SLAVES STATUS" :
62666270
"SHOW SLAVE STATUS"))
62676271
return(1);
62686272

62696273
/* Loop over all slaves */
6270-
while ((row= mysql_fetch_row(slave)))
6274+
while ((row= mysql_fetch_row(slave_status_res)))
62716275
{
62726276
if (row[11 + multi_source])
62736277
{
@@ -6282,13 +6286,11 @@ static int do_stop_slave_sql(MYSQL *mysql_con)
62826286

62836287
if (mysql_query_with_error_report(mysql_con, 0, query))
62846288
{
6285-
mysql_free_result(slave);
62866289
return 1;
62876290
}
62886291
}
62896292
}
62906293
}
6291-
mysql_free_result(slave);
62926294
return(0);
62936295
}
62946296

@@ -6412,32 +6414,35 @@ static int do_show_slave_status(MYSQL *mysql_con, int have_mariadb_gtid,
64126414

64136415
static int do_start_slave_sql(MYSQL *mysql_con)
64146416
{
6415-
MYSQL_RES *slave;
64166417
MYSQL_ROW row;
64176418
int error= 0;
64186419
DBUG_ENTER("do_start_slave_sql");
64196420

6420-
/* We need to check if the slave sql is stopped in the first place */
6421-
if (mysql_query_with_error_report(mysql_con, &slave,
6422-
multi_source ?
6423-
"SHOW ALL SLAVES STATUS" :
6424-
"SHOW SLAVE STATUS"))
6425-
DBUG_RETURN(1);
6421+
/*
6422+
do_start_slave_sql() should normally be called
6423+
sometime after do_stop_slave_sql() succeeds
6424+
*/
6425+
if (!slave_status_res)
6426+
DBUG_RETURN(error);
6427+
mysql_data_seek(slave_status_res, 0);
64266428

6427-
while ((row= mysql_fetch_row(slave)))
6429+
while ((row= mysql_fetch_row(slave_status_res)))
64286430
{
64296431
DBUG_PRINT("info", ("Connection: '%s' status: '%s'",
64306432
multi_source ? row[0] : "", row[11 + multi_source]));
64316433
if (row[11 + multi_source])
64326434
{
6433-
/* if SLAVE SQL is not running, we don't start it */
6434-
if (strcmp(row[11 + multi_source], "Yes"))
6435+
/*
6436+
If SLAVE_SQL was not running but is now,
6437+
we start it anyway to warn the unexpected state change.
6438+
*/
6439+
if (strcmp(row[11 + multi_source], "No"))
64356440
{
64366441
char query[160];
64376442
if (multi_source)
6438-
sprintf(query, "START SLAVE '%.80s'", row[0]);
6443+
sprintf(query, "START SLAVE '%.80s' SQL_THREAD", row[0]);
64396444
else
6440-
strmov(query, "START SLAVE");
6445+
strmov(query, "START SLAVE SQL_THREAD");
64416446

64426447
if (mysql_query_with_error_report(mysql_con, 0, query))
64436448
{
@@ -6448,7 +6453,6 @@ static int do_start_slave_sql(MYSQL *mysql_con)
64486453
}
64496454
}
64506455
}
6451-
mysql_free_result(slave);
64526456
DBUG_RETURN(error);
64536457
}
64546458

mysql-test/main/mysqldump.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5617,7 +5617,6 @@ proc
56175617
one
56185618
DROP DATABASE bug25717383;
56195619
mariadb-dump: Got error: 2005: "Unknown server host 'unknownhost'" when trying to connect
5620-
mariadb-dump: Couldn't execute 'SHOW SLAVE STATUS': Server has gone away (2006)
56215620
Usage: mariadb-dump [OPTIONS] database [tables]
56225621
OR mariadb-dump [OPTIONS] --databases DB1 [DB2 DB3...]
56235622
OR mariadb-dump [OPTIONS] --all-databases

mysql-test/suite/rpl/r/rpl_mysqldump_gtid_slave_pos.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ after initial slave got in sync
5151
include/stop_slave.inc
5252
# 3. A
5353
include/stop_slave.inc
54-
include/stop_slave.inc
5554
# 4.
5655
set statement sql_log_bin=0 for delete from mysql.gtid_slave_pos;
5756
insert into mysql.gtid_slave_pos values (99 + 2, 1, 1, 1);

mysql-test/suite/rpl/t/rpl_mysqldump_gtid_slave_pos.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ select @@global.gtid_slave_pos as "after initial slave got in sync";
7373
--echo # 3. A
7474
# Two dumps prepared to be restored in the following loop
7575
--exec $MYSQL_DUMP_SLAVE --dump-slave --gtid mysql gtid_slave_pos > $MYSQLTEST_VARDIR/tmp/dump_2.sql
76-
--source include/stop_slave.inc
7776

7877
--exec $MYSQL_DUMP_SLAVE --master-data --gtid mysql gtid_slave_pos > $MYSQLTEST_VARDIR/tmp/dump_1.sql
7978

0 commit comments

Comments
 (0)