Minor simplifications of the binlog code to make it easier to maintain: - Use distinct naming rather than subtle overloading for conceptually different methods. - Eliminate unnecessary boolean flags for functions that needlessly obscure the control flow. === modified file 'sql/log.cc' --- sql/log.cc | 30 ++++++++++++++---------------- sql/log.h | 6 ++++-- 2 files changed, 18 insertions(+), 18 deletions(-) Index: sql/log.cc =================================================================== --- sql/log.cc.orig 2010-06-09 11:30:52.000000000 +0200 +++ sql/log.cc 2010-06-09 11:54:12.000000000 +0200 @@ -1447,8 +1447,7 @@ binlog_end_trans(THD *thd, binlog_trx_da were, we would have to ensure that we're not ending a statement inside a stored function. */ - error= mysql_bin_log.write(thd, &trx_data->trans_log, end_ev, - trx_data->has_incident()); + error= mysql_bin_log.write_transaction_to_binlog(thd, trx_data, end_ev); trx_data->reset(); /* @@ -4575,18 +4574,14 @@ uint MYSQL_BIN_LOG::next_file_id() SYNOPSIS write_cache() cache Cache to write to the binary log - lock_log True if the LOCK_log mutex should be aquired, false otherwise - sync_log True if the log should be flushed and sync:ed DESCRIPTION Write the contents of the cache to the binary log. The cache will be reset as a READ_CACHE to be able to read the contents from it. */ -int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log) +int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache) { - Mutex_sentry sentry(lock_log ? &LOCK_log : NULL); - if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0)) return ER_ERROR_ON_WRITE; uint length= my_b_bytes_in_cache(cache), group, carry, hdr_offs; @@ -4704,9 +4699,6 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE DBUG_ASSERT(carry == 0); - if (sync_log) - flush_and_sync(); - return 0; // All OK } @@ -4786,8 +4778,9 @@ bool MYSQL_BIN_LOG::write_incident(THD * 'cache' needs to be reinitialized after this functions returns. */ -bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, - bool incident) +bool MYSQL_BIN_LOG::write_transaction_to_binlog(THD *thd, + binlog_trx_data *trx_data, + Log_event *commit_event) { DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)"); VOID(pthread_mutex_lock(&LOCK_log)); @@ -4798,6 +4791,8 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_C DBUG_ASSERT(is_open()); if (likely(is_open())) // Should always be true { + IO_CACHE *cache= &trx_data->trans_log; + /* We only bother to write to the binary log if there is anything to write. @@ -4824,20 +4819,23 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_C DBUG_EXECUTE_IF("crash_before_writing_xid", { - if ((write_error= write_cache(cache, false, true))) + if ((write_error= write_cache(cache))) DBUG_PRINT("info", ("error writing binlog cache: %d", write_error)); + else + flush_and_sync(); + DBUG_PRINT("info", ("crashing before writing xid")); abort(); }); - if ((write_error= write_cache(cache, false, false))) + if ((write_error= write_cache(cache))) goto err; if (commit_event && commit_event->write(&log_file)) goto err; - if (incident && write_incident(thd, FALSE)) + if (trx_data->has_incident() && write_incident(thd, FALSE)) goto err; if (flush_and_sync()) @@ -5909,7 +5907,7 @@ void TC_LOG_BINLOG::unlog(ulong cookie, pthread_cond_signal(&COND_prep_xids); } pthread_mutex_unlock(&LOCK_prep_xids); - rotate_and_purge(0); // as ::write() did not rotate + rotate_and_purge(0); // as ::write_transaction_to_binlog() did not rotate } int TC_LOG_BINLOG::recover(IO_CACHE *log, Format_description_log_event *fdle) Index: sql/log.h =================================================================== --- sql/log.h.orig 2010-06-09 11:30:52.000000000 +0200 +++ sql/log.h 2010-06-09 11:54:12.000000000 +0200 @@ -227,6 +227,7 @@ private: time_t last_time; }; +class binlog_trx_data; class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG { private: @@ -362,10 +363,11 @@ public: void new_file(); bool write(Log_event* event_info); // binary log write - bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event, bool incident); + bool write_transaction_to_binlog(THD *thd, binlog_trx_data *trx_data, + Log_event *commit_event); bool write_incident(THD *thd, bool lock); - int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync); + int write_cache(IO_CACHE *cache); void set_write_error(THD *thd); bool check_write_error(THD *thd);