Skip to content

Commit 94eb34d

Browse files
author
Sujatha Sivakumar
committed
Bug#24901077: RESET SLAVE ALL DOES NOT ALWAYS RESET SLAVE
Merge branch 'mysql-5.7' into mysql-trunk
2 parents 4bec40d + f19e19e commit 94eb34d

File tree

3 files changed

+204
-5
lines changed

3 files changed

+204
-5
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
[connection master]
7+
CREATE TABLE t1 (c1 INT);
8+
INSERT INTO t1 (c1) VALUES (1);
9+
include/sync_slave_sql_with_master.inc
10+
[connection slave]
11+
include/stop_slave_sql.inc
12+
[connection master]
13+
FLUSH LOGS;
14+
FLUSH LOGS;
15+
INSERT INTO t1 (c1) VALUES (2);
16+
include/sync_slave_io_with_master.inc
17+
call mtr.add_suppression("File '.*slave-relay-bin.");
18+
call mtr.add_suppression("Could not open log file");
19+
call mtr.add_suppression("Failed to open the relay log");
20+
call mtr.add_suppression("Slave failed to initialize relay log info structure");
21+
call mtr.add_suppression("Could not find target log file mentioned in relay log info in the index file");
22+
call mtr.add_suppression("Failed to initialize the relay-log-info structure");
23+
call mtr.add_suppression("Failed to initialize the master info structure");
24+
call mtr.add_suppression("Failed to create or recover replication info repositories");
25+
include/rpl_stop_server.inc [server_number=2]
26+
# Removing file(s)
27+
include/rpl_start_server.inc [server_number=2]
28+
START SLAVE;
29+
ERROR HY000: Slave failed to initialize relay log info structure from the repository
30+
START SLAVE;
31+
ERROR HY000: Slave failed to initialize relay log info structure from the repository
32+
RESET SLAVE;
33+
RESET MASTER;
34+
DROP TABLE t1;
35+
include/start_slave.inc
36+
[connection master]
37+
include/sync_slave_sql_with_master.inc
38+
include/diff_tables.inc [master:t1, slave:t1]
39+
[connection master]
40+
DROP TABLE t1;
41+
include/sync_slave_sql_with_master.inc
42+
include/rpl_end.inc
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
###############################################################################
2+
# Bug#24901077: RESET SLAVE ALL DOES NOT ALWAYS RESET SLAVE
3+
#
4+
# Problem:
5+
# =======
6+
# If you have a relay log index file that has ended up with
7+
# some relay log files that do not exists, then RESET SLAVE
8+
# ALL is not enough to get back to a clean state.
9+
###############################################################################
10+
# Remove all slave-relay-bin.0* files (do not remove slave-relay-bin.index)
11+
# During server restart rli initialization will fail as there are no
12+
# relay logs. In case of bug RESET SLAVE will not do the required clean up
13+
# as rli is not inited and subsequent START SLAVE will fail.
14+
# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found"
15+
# because it is different on Unix and Windows systems.
16+
17+
--source include/have_binlog_format_mixed.inc
18+
--source include/master-slave.inc
19+
20+
--source include/rpl_connection_master.inc
21+
CREATE TABLE t1 (c1 INT);
22+
INSERT INTO t1 (c1) VALUES (1);
23+
--source include/sync_slave_sql_with_master.inc
24+
25+
--source include/rpl_connection_slave.inc
26+
--source include/stop_slave_sql.inc
27+
--let $MYSQLD_SLAVE_DATADIR= `select @@datadir`
28+
29+
--source include/rpl_connection_master.inc
30+
# Generate more relay logs on slave.
31+
FLUSH LOGS;
32+
FLUSH LOGS;
33+
INSERT INTO t1 (c1) VALUES (2);
34+
35+
--source include/sync_slave_io_with_master.inc
36+
call mtr.add_suppression("File '.*slave-relay-bin.");
37+
call mtr.add_suppression("Could not open log file");
38+
call mtr.add_suppression("Failed to open the relay log");
39+
call mtr.add_suppression("Slave failed to initialize relay log info structure");
40+
call mtr.add_suppression("Could not find target log file mentioned in relay log info in the index file");
41+
call mtr.add_suppression("Failed to initialize the relay-log-info structure");
42+
call mtr.add_suppression("Failed to initialize the master info structure");
43+
call mtr.add_suppression("Failed to create or recover replication info repositories");
44+
45+
# Stop slave
46+
--let $rpl_server_number= 2
47+
--source include/rpl_stop_server.inc
48+
49+
# Delete file(s)
50+
--echo # Removing $remove_pattern file(s)
51+
--let $remove_pattern= slave-relay-bin.0*
52+
--remove_files_wildcard $MYSQLD_SLAVE_DATADIR $remove_pattern
53+
54+
# Start slave
55+
--let $rpl_server_number= 2
56+
--source include/rpl_start_server.inc
57+
58+
# Start slave must fail because of the removed file(s).
59+
--error ER_SLAVE_RLI_INIT_REPOSITORY
60+
START SLAVE;
61+
62+
# Try a second time, it must fail again.
63+
--error ER_SLAVE_RLI_INIT_REPOSITORY
64+
START SLAVE;
65+
66+
# Retrieve master executed position before reset slave.
67+
--let $master_exec_file= query_get_value("SHOW SLAVE STATUS", Relay_Master_Log_File, 1)
68+
--let $master_exec_pos= query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1)
69+
70+
# Reset slave.
71+
# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found"
72+
# because it is different on Unix and Windows systems.
73+
--disable_warnings
74+
RESET SLAVE;
75+
--enable_warnings
76+
RESET MASTER;
77+
DROP TABLE t1;
78+
# Start slave.
79+
--source include/start_slave.inc
80+
81+
--source include/rpl_connection_master.inc
82+
--source include/sync_slave_sql_with_master.inc
83+
# Check consistency.
84+
--let $diff_tables= master:t1, slave:t1
85+
--source include/diff_tables.inc
86+
87+
# Cleanup
88+
--source include/rpl_connection_master.inc
89+
DROP TABLE t1;
90+
--source include/sync_slave_sql_with_master.inc
91+
--source include/rpl_end.inc

sql/rpl_rli.cc

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,25 @@ int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
12041204
const char** errmsg, bool delete_only)
12051205
{
12061206
int error=0;
1207+
const char *ln;
1208+
/* name of the index file if opt_relaylog_index_name is set*/
1209+
const char* log_index_name;
1210+
/*
1211+
Buffer to add channel name suffix when relay-log-index option is
1212+
provided
1213+
*/
1214+
char relay_bin_index_channel[FN_REFLEN];
1215+
1216+
const char *ln_without_channel_name;
1217+
/*
1218+
Buffer to add channel name suffix when relay-log option is provided.
1219+
*/
1220+
char relay_bin_channel[FN_REFLEN];
1221+
1222+
char buffer[FN_REFLEN];
1223+
1224+
mysql_mutex_t *log_lock= relay_log.get_log_lock();
1225+
12071226
DBUG_ENTER("Relay_log_info::purge_relay_logs");
12081227

12091228
/*
@@ -1235,12 +1254,58 @@ int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
12351254
if (!inited)
12361255
{
12371256
DBUG_PRINT("info", ("inited == 0"));
1238-
DBUG_RETURN(0);
1239-
}
1257+
if (error_on_rli_init_info)
1258+
{
1259+
ln_without_channel_name= relay_log.generate_name(opt_relay_logname,
1260+
"-relay-bin", buffer);
1261+
1262+
ln= add_channel_to_relay_log_name(relay_bin_channel, FN_REFLEN,
1263+
ln_without_channel_name);
1264+
if (opt_relaylog_index_name)
1265+
{
1266+
char index_file_withoutext[FN_REFLEN];
1267+
relay_log.generate_name(opt_relaylog_index_name,"",
1268+
index_file_withoutext);
12401269

1241-
DBUG_ASSERT(slave_running == 0);
1242-
DBUG_ASSERT(mi->slave_running == 0);
1270+
log_index_name= add_channel_to_relay_log_name(relay_bin_index_channel,
1271+
FN_REFLEN,
1272+
index_file_withoutext);
1273+
}
1274+
else
1275+
log_index_name= 0;
12431276

1277+
if (relay_log.open_index_file(log_index_name, ln, TRUE))
1278+
{
1279+
sql_print_error("Unable to purge relay log files. Failed to open relay "
1280+
"log index file:%s.", relay_log.get_index_fname());
1281+
DBUG_RETURN(1);
1282+
}
1283+
mysql_mutex_lock(&mi->data_lock);
1284+
mysql_mutex_lock(log_lock);
1285+
if (relay_log.open_binlog(ln, 0,
1286+
(max_relay_log_size ? max_relay_log_size :
1287+
max_binlog_size), true,
1288+
true/*need_lock_index=true*/,
1289+
true/*need_sid_lock=true*/,
1290+
mi->get_mi_description_event()))
1291+
{
1292+
mysql_mutex_unlock(log_lock);
1293+
mysql_mutex_unlock(&mi->data_lock);
1294+
sql_print_error("Unable to purge relay log files. Failed to open relay "
1295+
"log file:%s.", relay_log.get_log_fname());
1296+
DBUG_RETURN(1);
1297+
}
1298+
mysql_mutex_unlock(log_lock);
1299+
mysql_mutex_unlock(&mi->data_lock);
1300+
}
1301+
else
1302+
DBUG_RETURN(0);
1303+
}
1304+
else
1305+
{
1306+
DBUG_ASSERT(slave_running == 0);
1307+
DBUG_ASSERT(mi->slave_running == 0);
1308+
}
12441309
/* Reset the transaction boundary parser and clear the last GTID queued */
12451310
mi->transaction_parser.reset();
12461311
mi->clear_last_gtid_queued();
@@ -1290,7 +1355,8 @@ int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
12901355
error= init_relay_log_pos(group_relay_log_name,
12911356
group_relay_log_pos,
12921357
false/*need_data_lock=false*/, errmsg, 0);
1293-
1358+
if (!inited && error_on_rli_init_info)
1359+
relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
12941360
err:
12951361
#ifndef DBUG_OFF
12961362
char buf[22];

0 commit comments

Comments
 (0)