summaryrefslogtreecommitdiff
path: root/client/mysqlbinlog.cc
diff options
context:
space:
mode:
authorunknown <bar@mysql.com/bar.intranet.mysql.r18.ru>2006-12-14 14:05:25 +0400
committerunknown <bar@mysql.com/bar.intranet.mysql.r18.ru>2006-12-14 14:05:25 +0400
commite653222d3051095da3c1c7ff4777ba2dbe12cf32 (patch)
treecb1b6927cef501ed5a2b98c1a599db28f8e03a2e /client/mysqlbinlog.cc
parent9ef60daf784a8a1962306c997b16a2cb81a362d9 (diff)
downloadmariadb-git-e653222d3051095da3c1c7ff4777ba2dbe12cf32.tar.gz
Bug#17642 mysqlbinlog: Restore from row-based binlog fails
Problem: mysqlbinlog_base64 failed sporadically. Reason: Missing "flush logs" before running $MYSQL_BINLOG, which could start dumping the log file before server has finished writting into it. Fix: - implementing --force-if-open option to "mysqlbinlog" - adding --disable-force-if-open to make $MYSQL_BINLOG fail on non-closed log files, to garantee that nobody will forget "flush logs" in the future. - adding "flush logs" into all affected tests. client/mysqlbinlog.cc: Implementing --force-if-open option with TRUE by default mysql-test/mysql-test-run.pl: Using --disable-force-if-open for all tests to avoid sporadic test failures because of running "mysqlbinlog" on a non-flushed binlog files. mysql-test/r/binlog_row_mix_innodb_myisam.result: FLush log before running dumping. mysql-test/r/binlog_stm_mix_innodb_myisam.result: FLush log before running dumping. mysql-test/r/mysqlbinlog.result: FLush log before running dumping. mysql-test/r/mysqlbinlog2.result: FLush log before running dumping. mysql-test/r/mysqlbinlog_base64.result: FLush log before running dumping. mysql-test/r/user_var-binlog.result: FLush log before running dumping. mysql-test/t/binlog_row_mix_innodb_myisam.test: FLush log before running dumping. mysql-test/t/binlog_stm_mix_innodb_myisam.test: FLush log before running dumping. mysql-test/t/mysqlbinlog.test: FLush log before running dumping. Adding new tests: - checking that $MYSQL_BINLOG returns an error on a non-closed binlog file because of --disable-force-if-open - checking that it does not return an error with --force-if-open mysql-test/t/mysqlbinlog2.test: FLush log before running dumping. mysql-test/t/mysqlbinlog_base64.test: FLush log before running dumping. mysql-test/t/user_var-binlog.test: FLush log before running dumping.
Diffstat (limited to 'client/mysqlbinlog.cc')
-rw-r--r--client/mysqlbinlog.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index d1dcaa9f538..e3a49adf7dd 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -67,6 +67,7 @@ static bool opt_hexdump= 0;
static bool opt_base64_output= 0;
static const char* database= 0;
static my_bool force_opt= 0, short_form= 0, remote_opt= 0, info_flag;
+static my_bool force_if_open_opt= 1;
static ulonglong offset = 0;
static const char* host = 0;
static int port= 0;
@@ -86,6 +87,7 @@ static short binlog_flags = 0;
static MYSQL* mysql = NULL;
static const char* dirname_for_local_load= 0;
static bool stop_passed= 0;
+static my_bool file_not_closed_error= 0;
/*
check_header() will set the pointer below.
@@ -648,6 +650,12 @@ Create_file event for file_id: %u\n",exv->file_id);
later.
*/
ev= 0;
+ if (!force_if_open_opt &&
+ (description_event->flags & LOG_EVENT_BINLOG_IN_USE_F))
+ {
+ file_not_closed_error= 1;
+ DBUG_RETURN(1);
+ }
break;
case BEGIN_LOAD_QUERY_EVENT:
ev->print(result_file, print_event_info);
@@ -727,6 +735,9 @@ static struct my_option my_long_options[] =
"already have. NOTE: you will need a SUPER privilege to use this option.",
(gptr*) &disable_log_bin, (gptr*) &disable_log_bin, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"force-if-open", 'F', "Force if binlog was not closed properly.",
+ (gptr*) &force_if_open_opt, (gptr*) &force_if_open_opt, 0, GET_BOOL, NO_ARG,
+ 1, 0, 0, 0, 0, 0},
{"force-read", 'f', "Force reading unknown binlog events.",
(gptr*) &force_opt, (gptr*) &force_opt, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
@@ -1564,6 +1575,16 @@ int main(int argc, char** argv)
my_free_open_file_info();
/* We cannot free DBUG, it is used in global destructors after exit(). */
my_end((info_flag ? MY_CHECK_ERROR : 0) | MY_DONT_FREE_DBUG);
+
+ if (file_not_closed_error)
+ {
+ fprintf(stderr,
+"\nError: attempting to dump binlog '%s' which was not closed properly.\n"
+"Most probably mysqld is still writting it, or crashed.\n"
+"Your current options specify --disable-force-if-open\n"
+"which means to abort on this problem.\n"
+"You can rerun using --force-if-open to ignore this problem.\n\n", argv[-1]);
+ }
exit(exit_value);
DBUG_RETURN(exit_value); // Keep compilers happy
}