Skip to content

Commit 4ebaa80

Browse files
committed
Failed change master could leave around old relay log files
The reason was that there where no cleanup after a failed 'change master'. Fixed by doing a cleanup of created relay log files in remove_master_info()
1 parent 0629711 commit 4ebaa80

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
RESET MASTER;
2+
connect slave,127.0.0.1,root,,,$SERVER_MYPORT_3;
3+
change master 'abc1' to relay_log_file='';
4+
ERROR HY000: Failed initializing relay log position: Could not find target log during relay log initialization
5+
change master 'abc1' to relay_log_file='';
6+
ERROR HY000: Failed initializing relay log position: Could not find target log during relay log initialization
7+
disconnect slave;
8+
connection default;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--source include/not_embedded.inc
2+
3+
RESET MASTER;
4+
5+
--connect (slave,127.0.0.1,root,,,$SERVER_MYPORT_3)
6+
7+
--error ER_RELAY_LOG_INIT
8+
change master 'abc1' to relay_log_file='';
9+
--error ER_RELAY_LOG_INIT
10+
change master 'abc1' to relay_log_file='';
11+
--disconnect slave
12+
--connection default
13+

sql/rpl_mi.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,11 +1453,32 @@ bool Master_info_index::add_master_info(Master_info *mi, bool write_to_file)
14531453
atomic
14541454
*/
14551455

1456-
bool Master_info_index::remove_master_info(Master_info *mi)
1456+
bool Master_info_index::remove_master_info(Master_info *mi, bool clear_log_files)
14571457
{
1458+
char tmp_name[FN_REFLEN];
14581459
DBUG_ENTER("remove_master_info");
14591460
mysql_mutex_assert_owner(&LOCK_active_mi);
14601461

1462+
if (clear_log_files)
1463+
{
1464+
/* This code is only executed when change_master() failes to create a new master info */
1465+
1466+
// Delete any temporary relay log files that could have been created by change_master()
1467+
mi->rli.relay_log.reset_logs(current_thd, 0, (rpl_gtid*) 0, 0, 0);
1468+
/* Delete master-'connection'.info */
1469+
create_logfile_name_with_suffix(tmp_name,
1470+
sizeof(tmp_name),
1471+
master_info_file, 0,
1472+
&mi->cmp_connection_name);
1473+
my_delete(tmp_name, MYF(0));
1474+
/* Delete relay-log-'connection'.info */
1475+
create_logfile_name_with_suffix(tmp_name,
1476+
sizeof(tmp_name),
1477+
relay_log_info_file, 0,
1478+
&mi->cmp_connection_name);
1479+
my_delete(tmp_name, MYF(0));
1480+
}
1481+
14611482
// Delete Master_info and rewrite others to file
14621483
if (!my_hash_delete(&master_info_hash, (uchar*) mi))
14631484
{

sql/rpl_mi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class Master_info_index
385385
bool check_duplicate_master_info(LEX_CSTRING *connection_name,
386386
const char *host, uint port);
387387
bool add_master_info(Master_info *mi, bool write_to_file);
388-
bool remove_master_info(Master_info *mi);
388+
bool remove_master_info(Master_info *mi, bool clear_log_files);
389389
Master_info *get_master_info(const LEX_CSTRING *connection_name,
390390
Sql_condition::enum_warning_level warning);
391391
bool start_all_slaves(THD *thd);

sql/sql_parse.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4137,7 +4137,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
41374137
If new master was not added, we still need to free mi.
41384138
*/
41394139
if (master_info_added)
4140-
master_info_index->remove_master_info(mi);
4140+
master_info_index->remove_master_info(mi, 1);
41414141
else
41424142
delete mi;
41434143
}

sql/sql_reload.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options,
403403
/* If not default connection and 'all' is used */
404404
mi->release();
405405
mysql_mutex_lock(&LOCK_active_mi);
406-
if (master_info_index->remove_master_info(mi))
406+
if (master_info_index->remove_master_info(mi, 0))
407407
result= 1;
408408
mysql_mutex_unlock(&LOCK_active_mi);
409409
}

0 commit comments

Comments
 (0)