Skip to content

Commit

Permalink
Bug #17076131 MYSQLDUMP FAILS WHEN ERR LOG ON RUNNING SERVER IS DELET…
Browse files Browse the repository at this point in the history
…ED 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 falvours. 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.
  • Loading branch information
Anirudh Mangipudi committed May 26, 2014
1 parent a3654cc commit 820ecb0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
12 changes: 12 additions & 0 deletions mysql-test/r/bug17076131.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Bug#17076131 MYSQLDUMP FAILS WHEN ERR LOG ON RUNNING SERVER IS
# DELETED ON WINDOWS
#
# Creating file aliases.
# Executing mysqldump normally.
# Removing Error_log file.
# Executing mysqldump after deleting error_log file.
# Checking diff of the 2 dumps.
# No Difference found.
# Clean Up.
# End of Test.
2 changes: 2 additions & 0 deletions mysql-test/t/bug17076131-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--no-console
--log-error=$MYSQLTEST_VARDIR/tmp/mysql.err
28 changes: 28 additions & 0 deletions mysql-test/t/bug17076131.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--echo #
--echo # Bug#17076131 MYSQLDUMP FAILS WHEN ERR LOG ON RUNNING SERVER IS
--echo # DELETED ON WINDOWS
--echo #

--source include/not_embedded.inc

--echo # Creating file aliases.
let $dump_with_err_log=$MYSQLTEST_VARDIR/tmp/bug17076131_with_err_log.sql;
let $dump_without_err_log=$MYSQLTEST_VARDIR/tmp/bug17076131_without_err_log.sql;

--echo # Executing mysqldump normally.
--exec $MYSQL_DUMP --extended-insert --flush-logs --add-drop-database --add-drop-table --force --databases --skip-dump-date mysql > $dump_with_err_log

--echo # Removing Error_log file.
--move_file $MYSQLTEST_VARDIR/tmp/mysql.err $MYSQLTEST_VARDIR/tmp/mysql-temp.err

--echo # Executing mysqldump after deleting error_log file.
--exec $MYSQL_DUMP --extended-insert --flush-logs --add-drop-database --add-drop-table --force --databases --skip-dump-date mysql > $dump_without_err_log

--echo # Checking diff of the 2 dumps.
--diff_files $dump_with_err_log $dump_without_err_log
--echo # No Difference found.

--echo # Clean Up.
--remove_file $dump_with_err_log
--remove_file $dump_without_err_log
--echo # End of Test.
2 changes: 2 additions & 0 deletions mysys/my_fopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ static FILE *my_win_freopen(const char *path, const char *mode, FILE *stream)

fd= _fileno(stream);
}
else
_close(fd);

if ((osfh= CreateFile(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE |
Expand Down
17 changes: 13 additions & 4 deletions sql/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2206,11 +2206,20 @@ void sql_perror(const char *message)
extern "C" my_bool reopen_fstreams(const char *filename,
FILE *outstream, FILE *errstream)
{
if (outstream && !my_freopen(filename, "a", outstream))
return TRUE;
int retries= 2, errors= 0;

if (errstream && !my_freopen(filename, "a", errstream))
return TRUE;
do
{
errors= 0;
if (errstream && !my_freopen(filename, "a", errstream))
errors++;
if (outstream && !my_freopen(filename, "a", outstream))
errors++;
}
while(retries-- && errors);

if(errors)
return true;

/* The error stream must be unbuffered. */
if (errstream)
Expand Down

0 comments on commit 820ecb0

Please sign in to comment.