Skip to content

Commit 6b13a95

Browse files
author
Anirudh Mangipudi
committed
Bug #17076131 MYSQLDUMP FAILS WHEN ERR LOG ON RUNNING SERVER IS DELETED ON WINDOWS
Problem: As the title mentions, on windows mysqldump tool is creating the dump file without the content (tables, views etc) of a database that is dumped when the error log file is deleted (by the user). Similar behaviour is not happening on Linux flavours. The difference is due to the difference in handling of the deleted files. In Windows, the line "if (flush_logs || opt_delete_master_logs)" in main.c of mysqldump is returning error whereas on linux this line is passing Solution: The core problem is that, in Windows, the new error log file is being created but the old file descriptor which is associated with both stdout and stderr stream is not being closed by the program. So a retry logic has been implemented where we close the error log's file descriptor (associated open fds of stderr and stdout) in the first attempt and open a new file and associating it with stdout/stderr streams.
1 parent 4a966cc commit 6b13a95

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

mysql-test/r/bug17076131.result

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Bug#17076131 MYSQLDUMP FAILS WHEN ERR LOG ON RUNNING SERVER IS
3+
# DELETED ON WINDOWS
4+
#
5+
# Creating file aliases.
6+
# Executing mysqldump normally.
7+
# Removing Error_log file.
8+
# Executing mysqldump after deleting error_log file.
9+
# Checking diff of the 2 dumps.
10+
# No Difference found.
11+
# Clean Up.
12+
# End of Test.

mysql-test/t/bug17076131-master.opt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--no-console
2+
--log-error=$MYSQLTEST_VARDIR/tmp/mysql.err

mysql-test/t/bug17076131.test

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--echo #
2+
--echo # Bug#17076131 MYSQLDUMP FAILS WHEN ERR LOG ON RUNNING SERVER IS
3+
--echo # DELETED ON WINDOWS
4+
--echo #
5+
6+
--source include/not_embedded.inc
7+
8+
--echo # Creating file aliases.
9+
let $dump_with_err_log=$MYSQLTEST_VARDIR/tmp/bug17076131_with_err_log.sql;
10+
let $dump_without_err_log=$MYSQLTEST_VARDIR/tmp/bug17076131_without_err_log.sql;
11+
12+
--echo # Executing mysqldump normally.
13+
--exec $MYSQL_DUMP --extended-insert --flush-logs --add-drop-database --add-drop-table --force --databases --skip-dump-date mysql > $dump_with_err_log
14+
15+
--echo # Removing Error_log file.
16+
--remove_file $MYSQLTEST_VARDIR/tmp/mysql.err
17+
18+
--echo # Executing mysqldump after deleting error_log file.
19+
--exec $MYSQL_DUMP --extended-insert --flush-logs --add-drop-database --add-drop-table --force --databases --skip-dump-date mysql > $dump_without_err_log
20+
21+
--echo # Checking diff of the 2 dumps.
22+
--diff_files $dump_with_err_log $dump_without_err_log
23+
--echo # No Difference found.
24+
25+
--echo # Clean Up.
26+
--remove_file $dump_with_err_log
27+
--remove_file $dump_without_err_log
28+
--echo # End of Test.

mysys/my_fopen.c

+3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ static FILE *my_win_freopen(const char *path, const char *mode, FILE *stream)
120120
FILE_SHARE_DELETE, NULL,
121121
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
122122
NULL)) == INVALID_HANDLE_VALUE)
123+
{
124+
_close(fd);
123125
return NULL;
126+
}
124127

125128
if ((handle_fd= _open_osfhandle((intptr_t)osfh,
126129
_O_APPEND | _O_TEXT)) == -1)

sql/log.cc

+12-2
Original file line numberDiff line numberDiff line change
@@ -2206,10 +2206,20 @@ void sql_perror(const char *message)
22062206
extern "C" my_bool reopen_fstreams(const char *filename,
22072207
FILE *outstream, FILE *errstream)
22082208
{
2209+
int retries= 2, errors= 0;
2210+
2211+
do
2212+
{
2213+
errors= 0;
22092214
if (errstream && !my_freopen(filename, "a", errstream))
2210-
return true;
2215+
errors++;
22112216
if (outstream && !my_freopen(filename, "a", outstream))
2212-
return true;
2217+
errors++;
2218+
}
2219+
while (retries-- && errors);
2220+
2221+
if (errors)
2222+
return true;
22132223

22142224
/* The error stream must be unbuffered. */
22152225
if (errstream)

0 commit comments

Comments
 (0)