Skip to content

Commit 78fa270

Browse files
abhinav04sharmaFacebook Github Bot
authored andcommitted
Delete crash safe index file if index file exists
Summary: Crash safe index file is created when any change is made to the index file. The index file is first copied over to the crash safe one and then stuff is added/removed from the crash safe index file. Finally, the old index file is deleted and crash safe index file is renamed to the index file. There might be a scenario where mysql crashes after stuff is changed in the crash safe file but before the old index file is deleted. In this case we should delete the crash safe index file at restart. If we don't delete it subsequent changes to the index file can corrupt it because it can be copied to the old crash safe file which already has some data in it. Closes #433 Reviewed By: santoshbanda Differential Revision: D4198274 Pulled By: abhinav04sharma fbshipit-source-id: a6f8993
1 parent 4a1823a commit 78fa270

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

sql/binlog.cc

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,18 +2750,35 @@ bool MYSQL_BIN_LOG::open_index_file(const char *index_file_name_arg,
27502750
return TRUE;
27512751
}
27522752

2753-
/*
2754-
We need move crash_safe_index_file to index_file if the index_file
2755-
does not exist and crash_safe_index_file exists when mysqld server
2756-
restarts.
2757-
*/
2758-
if (my_access(index_file_name, F_OK) &&
2759-
!my_access(crash_safe_index_file_name, F_OK) &&
2760-
my_rename(crash_safe_index_file_name, index_file_name, MYF(MY_WME)))
2753+
// case: crash_safe_index_file exists
2754+
if (!my_access(crash_safe_index_file_name, F_OK))
27612755
{
2762-
sql_print_error("MYSQL_BIN_LOG::open_index_file failed to "
2763-
"move crash_safe_index_file to index file.");
2764-
return TRUE;
2756+
/*
2757+
We need move crash_safe_index_file to index_file if the index_file
2758+
does not exist or delete it if the index_file exists when mysqld server
2759+
restarts.
2760+
*/
2761+
2762+
// case: index_file does not exist
2763+
if (my_access(index_file_name, F_OK))
2764+
{
2765+
if (my_rename(crash_safe_index_file_name, index_file_name, MYF(MY_WME)))
2766+
{
2767+
sql_print_error("MYSQL_BIN_LOG::open_index_file failed to "
2768+
"move crash_safe_index_file to index_file.");
2769+
return TRUE;
2770+
}
2771+
2772+
}
2773+
else
2774+
{
2775+
if (my_delete(crash_safe_index_file_name, MYF(MY_WME)))
2776+
{
2777+
sql_print_error("MYSQL_BIN_LOG::open_index_file failed to "
2778+
"delete crash_safe_index_file.");
2779+
return TRUE;
2780+
}
2781+
}
27652782
}
27662783

27672784
if ((index_file_nr= mysql_file_open(m_key_file_log_index,

0 commit comments

Comments
 (0)