Skip to content

Commit 9e6c628

Browse files
author
Sujatha Sivakumar
committed
Bug#24901077: RESET SLAVE ALL DOES NOT ALWAYS RESET SLAVE
Merge branch 'mysql-5.5' into mysql-5.6
2 parents ab90254 + e619295 commit 9e6c628

File tree

3 files changed

+169
-4
lines changed

3 files changed

+169
-4
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
include/rpl_stop_server.inc [server_number=2]
25+
# Removing file(s)
26+
include/rpl_start_server.inc [server_number=2]
27+
START SLAVE;
28+
ERROR HY000: Slave failed to initialize relay log info structure from the repository
29+
START SLAVE;
30+
ERROR HY000: Slave failed to initialize relay log info structure from the repository
31+
RESET SLAVE;
32+
RESET MASTER;
33+
DROP TABLE t1;
34+
include/start_slave.inc
35+
[connection master]
36+
include/sync_slave_sql_with_master.inc
37+
include/diff_tables.inc [master:t1, slave:t1]
38+
[connection master]
39+
DROP TABLE t1;
40+
include/sync_slave_sql_with_master.inc
41+
include/rpl_end.inc
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
44+
# Stop slave
45+
--let $rpl_server_number= 2
46+
--source include/rpl_stop_server.inc
47+
48+
# Delete file(s)
49+
--echo # Removing $remove_pattern file(s)
50+
--let $remove_pattern= slave-relay-bin.0*
51+
--remove_files_wildcard $MYSQLD_SLAVE_DATADIR $remove_pattern
52+
53+
# Start slave
54+
--let $rpl_server_number= 2
55+
--source include/rpl_start_server.inc
56+
57+
# Start slave must fail because of the removed file(s).
58+
--error ER_SLAVE_RLI_INIT_REPOSITORY
59+
START SLAVE;
60+
61+
# Try a second time, it must fail again.
62+
--error ER_SLAVE_RLI_INIT_REPOSITORY
63+
START SLAVE;
64+
65+
# Retrieve master executed position before reset slave.
66+
--let $master_exec_file= query_get_value("SHOW SLAVE STATUS", Relay_Master_Log_File, 1)
67+
--let $master_exec_pos= query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1)
68+
69+
# Reset slave.
70+
# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found"
71+
# because it is different on Unix and Windows systems.
72+
--disable_warnings
73+
RESET SLAVE;
74+
--enable_warnings
75+
RESET MASTER;
76+
DROP TABLE t1;
77+
# Start slave.
78+
--source include/start_slave.inc
79+
80+
--source include/rpl_connection_master.inc
81+
--source include/sync_slave_sql_with_master.inc
82+
# Check consistency.
83+
--let $diff_tables= master:t1, slave:t1
84+
--source include/diff_tables.inc
85+
86+
# Cleanup
87+
--source include/rpl_connection_master.inc
88+
DROP TABLE t1;
89+
--source include/sync_slave_sql_with_master.inc
90+
--source include/rpl_end.inc

sql/rpl_rli.cc

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
10851085
const char** errmsg)
10861086
{
10871087
int error=0;
1088+
const char *ln;
1089+
char name_buf[FN_REFLEN];
10881090
DBUG_ENTER("Relay_log_info::purge_relay_logs");
10891091

10901092
/*
@@ -1109,11 +1111,40 @@ int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
11091111
if (!inited)
11101112
{
11111113
DBUG_PRINT("info", ("inited == 0"));
1112-
DBUG_RETURN(0);
1113-
}
1114+
if (error_on_rli_init_info)
1115+
{
1116+
ln= relay_log.generate_name(opt_relay_logname, "-relay-bin",
1117+
1, name_buf);
1118+
if (relay_log.open_index_file(opt_relaylog_index_name, ln, TRUE))
1119+
{
1120+
sql_print_error("Unable to purge relay log files. Failed to open relay "
1121+
"log index file:%s.", relay_log.get_index_fname());
11141122

1115-
DBUG_ASSERT(slave_running == 0);
1116-
DBUG_ASSERT(mi->slave_running == 0);
1123+
DBUG_RETURN(1);
1124+
}
1125+
mysql_mutex_lock(&mi->data_lock);
1126+
if (relay_log.open_binlog(ln, 0, SEQ_READ_APPEND,
1127+
(max_relay_log_size ? max_relay_log_size :
1128+
max_binlog_size), true,
1129+
true/*need_lock_index=true*/,
1130+
true/*need_sid_lock=true*/,
1131+
mi->get_mi_description_event()))
1132+
{
1133+
sql_print_error("Unable to purge relay log files. Failed to open relay "
1134+
"log file:%s.", relay_log.get_log_fname());
1135+
mysql_mutex_unlock(&mi->data_lock);
1136+
DBUG_RETURN(1);
1137+
}
1138+
mysql_mutex_unlock(&mi->data_lock);
1139+
}
1140+
else
1141+
DBUG_RETURN(0);
1142+
}
1143+
else
1144+
{
1145+
DBUG_ASSERT(slave_running == 0);
1146+
DBUG_ASSERT(mi->slave_running == 0);
1147+
}
11171148

11181149
slave_skip_counter= 0;
11191150
mysql_mutex_lock(&data_lock);
@@ -1154,6 +1185,9 @@ int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
11541185
group_relay_log_pos,
11551186
false/*need_data_lock=false*/, errmsg, 0);
11561187

1188+
if (!inited && error_on_rli_init_info)
1189+
relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
1190+
11571191
err:
11581192
#ifndef DBUG_OFF
11591193
char buf[22];

0 commit comments

Comments
 (0)