1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error

when generating new name.
      
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
                  
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
                  
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.

mysql-test/include/restart_mysqld.inc:
  Refactored restart_mysqld so that it is not hardcoded for
  mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
  The error on open of index and binary log on new_file_impl 
  is now caught. Thence the user will get an error message. 
  We need to accomodate this change in the test case for the
  failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
  Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
  Added some test cases for asserting that the error is found 
  and reported.
sql/handler.cc:
  Catching error now returned by unlog (in ha_commit_trans) and 
  returning it.
sql/log.cc:
  Propagating errors from new_file_impl upwards. The errors that
  new_file_impl catches now are:
  - error on generate_new_name
  - error on writing the rotate event
  - error when opening the index or the binary log file.
sql/log.h:
  Changing declaration of:
  - rotate_and_purge
  - new_file
  - new_file_without_locking
  - new_file_impl
  - unlog
  They now return int instead of void.
sql/mysql_priv.h:
  Change signature of reload_acl_and_cache so that write_to_binlog
  is an int instead of bool.
sql/mysqld.cc:
  Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
  Changes to catch the return from rotate_and_purge.
sql/slave.cc:
  Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
  Changes to rotate_relay_log declaration (now returns int 
  instead of void).
sql/sql_load.cc:
  In SBR, some logging of LOAD DATA events goes through
  IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
  IO_CACHE implementation is ignoring the return value for from
  these callbacks (pre_read and post_read), so we need to find out
  at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
  Catching the rotate_relay_log and rotate_and_purge return values.
  Semantic change in reload_acl_and_cache so that we report errors
  in binlog interactions through the write_to_binlog output parameter.
  If there was any failure while rotating the binary log, we should
  then report the error to the client when handling SQLCOMM_FLUSH.
This commit is contained in:
Luis Soares
2010-11-30 23:32:51 +00:00
parent cd504e49bc
commit 647c619393
17 changed files with 958 additions and 73 deletions

View File

@@ -1474,7 +1474,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
#endif
case COM_REFRESH:
{
bool not_used;
int not_used;
status_var_increment(thd->status_var.com_stat[SQLCOM_FLUSH]);
ulong options= (ulong) (uchar) packet[0];
if (check_global_access(thd,RELOAD_ACL))
@@ -3227,7 +3227,11 @@ end_with_restore_list:
{
Incident_log_event ev(thd, incident);
(void) mysql_bin_log.write(&ev); /* error is ignored */
mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
if (mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE))
{
res= 1;
break;
}
}
DBUG_PRINT("debug", ("Just after generate_incident()"));
}
@@ -4051,7 +4055,7 @@ end_with_restore_list:
lex->no_write_to_binlog= 1;
case SQLCOM_FLUSH:
{
bool write_to_binlog;
int write_to_binlog;
if (check_global_access(thd,RELOAD_ACL))
goto error;
@@ -4068,12 +4072,22 @@ end_with_restore_list:
/*
Presumably, RESET and binlog writing doesn't require synchronization
*/
if (!lex->no_write_to_binlog && write_to_binlog)
if (write_to_binlog > 0) // we should write
{
if (!lex->no_write_to_binlog)
res= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
} else if (write_to_binlog < 0)
{
if ((res= write_bin_log(thd, FALSE, thd->query(), thd->query_length())))
break;
}
my_ok(thd);
/*
We should not write, but rather report error because
reload_acl_and_cache binlog interactions failed
*/
res= 1;
}
if (!res)
my_ok(thd);
}
break;
@@ -6862,7 +6876,10 @@ void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
@param thd Thread handler (can be NULL!)
@param options What should be reset/reloaded (tables, privileges, slave...)
@param tables Tables to flush (if any)
@param write_to_binlog True if we can write to the binlog.
@param write_to_binlog < 0 if there was an error while interacting with the binary log inside
reload_acl_and_cache,
0 if we should not write to the binary log,
> 0 if we can write to the binlog.
@note Depending on 'options', it may be very bad to write the
query to the binlog (e.g. FLUSH SLAVE); this is a
@@ -6876,11 +6893,11 @@ void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
*/
bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
bool *write_to_binlog)
int *write_to_binlog)
{
bool result=0;
select_errors=0; /* Write if more errors */
bool tmp_write_to_binlog= 1;
int tmp_write_to_binlog= *write_to_binlog= 1;
DBUG_ASSERT(!thd || !thd->in_sub_stmt);
@@ -6943,12 +6960,16 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
tmp_write_to_binlog= 0;
if( mysql_bin_log.is_open() )
{
mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
if (mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE))
*write_to_binlog= -1;
}
#ifdef HAVE_REPLICATION
int rotate_error= 0;
pthread_mutex_lock(&LOCK_active_mi);
rotate_relay_log(active_mi);
rotate_error= rotate_relay_log(active_mi);
pthread_mutex_unlock(&LOCK_active_mi);
if (rotate_error)
*write_to_binlog= -1;
#endif
/* flush slow and general logs */
@@ -7059,7 +7080,8 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
#endif
if (options & REFRESH_USER_RESOURCES)
reset_mqh((LEX_USER *) NULL, 0); /* purecov: inspected */
*write_to_binlog= tmp_write_to_binlog;
if (*write_to_binlog != -1)
*write_to_binlog= tmp_write_to_binlog;
/*
If the query was killed then this function must fail.
*/