@@ -184,7 +184,7 @@ static DYNAMIC_STRING extended_row;
184
184
static DYNAMIC_STRING dynamic_where ;
185
185
static MYSQL_RES * get_table_name_result = NULL ;
186
186
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 ;
188
188
189
189
190
190
#include <sslopt-vars.h>
@@ -1908,6 +1908,8 @@ static void free_resources()
1908
1908
mysql_free_result (routine_res );
1909
1909
if (routine_list_res )
1910
1910
mysql_free_result (routine_list_res );
1911
+ if (slave_status_res )
1912
+ mysql_free_result (slave_status_res );
1911
1913
if (mysql )
1912
1914
{
1913
1915
mysql_close (mysql );
@@ -6257,17 +6259,19 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
6257
6259
6258
6260
static int do_stop_slave_sql (MYSQL * mysql_con )
6259
6261
{
6260
- MYSQL_RES * slave ;
6261
6262
MYSQL_ROW row ;
6263
+ DBUG_ASSERT (
6264
+ !slave_status_res // do_stop_slave_sql() should only be called once
6265
+ );
6262
6266
6263
- if (mysql_query_with_error_report (mysql_con , & slave ,
6267
+ if (mysql_query_with_error_report (mysql_con , & slave_status_res ,
6264
6268
multi_source ?
6265
6269
"SHOW ALL SLAVES STATUS" :
6266
6270
"SHOW SLAVE STATUS" ))
6267
6271
return (1 );
6268
6272
6269
6273
/* Loop over all slaves */
6270
- while ((row = mysql_fetch_row (slave )))
6274
+ while ((row = mysql_fetch_row (slave_status_res )))
6271
6275
{
6272
6276
if (row [11 + multi_source ])
6273
6277
{
@@ -6282,13 +6286,11 @@ static int do_stop_slave_sql(MYSQL *mysql_con)
6282
6286
6283
6287
if (mysql_query_with_error_report (mysql_con , 0 , query ))
6284
6288
{
6285
- mysql_free_result (slave );
6286
6289
return 1 ;
6287
6290
}
6288
6291
}
6289
6292
}
6290
6293
}
6291
- mysql_free_result (slave );
6292
6294
return (0 );
6293
6295
}
6294
6296
@@ -6412,32 +6414,35 @@ static int do_show_slave_status(MYSQL *mysql_con, int have_mariadb_gtid,
6412
6414
6413
6415
static int do_start_slave_sql (MYSQL * mysql_con )
6414
6416
{
6415
- MYSQL_RES * slave ;
6416
6417
MYSQL_ROW row ;
6417
6418
int error = 0 ;
6418
6419
DBUG_ENTER ("do_start_slave_sql" );
6419
6420
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 );
6426
6428
6427
- while ((row = mysql_fetch_row (slave )))
6429
+ while ((row = mysql_fetch_row (slave_status_res )))
6428
6430
{
6429
6431
DBUG_PRINT ("info" , ("Connection: '%s' status: '%s'" ,
6430
6432
multi_source ? row [0 ] : "" , row [11 + multi_source ]));
6431
6433
if (row [11 + multi_source ])
6432
6434
{
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" ))
6435
6440
{
6436
6441
char query [160 ];
6437
6442
if (multi_source )
6438
- sprintf (query , "START SLAVE '%.80s'" , row [0 ]);
6443
+ sprintf (query , "START SLAVE '%.80s' SQL_THREAD " , row [0 ]);
6439
6444
else
6440
- strmov (query , "START SLAVE" );
6445
+ strmov (query , "START SLAVE SQL_THREAD " );
6441
6446
6442
6447
if (mysql_query_with_error_report (mysql_con , 0 , query ))
6443
6448
{
@@ -6448,7 +6453,6 @@ static int do_start_slave_sql(MYSQL *mysql_con)
6448
6453
}
6449
6454
}
6450
6455
}
6451
- mysql_free_result (slave );
6452
6456
DBUG_RETURN (error );
6453
6457
}
6454
6458
0 commit comments