Index: sql/binlog.cc =================================================================== --- sql/binlog.cc (revision 6927) +++ sql/binlog.cc (working copy) @@ -66,6 +66,7 @@ static handlerton *binlog_hton; bool opt_binlog_order_commits= true; +bool opt_binlog_skip_sync_stage= false; const char *log_bin_index= 0; const char *log_bin_basename= 0; @@ -5372,8 +5373,18 @@ if (flush_io_cache(&log_file)) return 1; - std::pair result= sync_binlog_file(force); + uint sync_period= get_sync_period(); + bool do_sync= false; + if (force + || (sync_period + && ++sync_counter >= sync_period)) + { + sync_counter= 0; + do_sync= true; + } + std::pair result= sync_binlog_file(do_sync); + return result.first; } @@ -7129,10 +7140,8 @@ MYSQL_BIN_LOG::sync_binlog_file(bool force) { bool synced= false; - unsigned int sync_period= get_sync_period(); - if (force || (sync_period && ++sync_counter >= sync_period)) + if (force) { - sync_counter= 0; if (mysql_file_sync(log_file.file, MYF(MY_WME))) return std::make_pair(true, synced); synced= true; @@ -7350,8 +7359,16 @@ if (flush_error == 0 && total_bytes > 0) flush_error= flush_cache_to_file(&flush_end_pos); - bool update_binlog_end_pos_after_sync= (get_sync_period() == 1); + /* Calculate if need to enter into sync stage */ + uint sync_period= get_sync_period(); + bool force= (sync_period && ++sync_counter >= sync_period); + bool skip_sync_stage= ((!opt_binlog_order_commits) + && opt_binlog_skip_sync_stage + && !force); + + bool update_binlog_end_pos_after_sync= (sync_period == 1); + /* If the flush finished successfully, we can call the after_flush hook. Being invoked here, we have the guarantee that the hook is @@ -7374,23 +7391,36 @@ DBUG_EXECUTE_IF("crash_commit_after_log", DBUG_SUICIDE();); } - /* - Stage #2: Syncing binary log file to disk - */ + THD* final_queue= NULL; + mysql_mutex_t* last_lock= NULL; + if (!skip_sync_stage) + { + /* All changes to sync_counter under the protection of LOCK_log */ + if (force) + sync_counter= 0; + /* + Stage #2: Syncing binary log file to disk + */ - if (change_stage(thd, Stage_manager::SYNC_STAGE, wait_queue, &LOCK_log, &LOCK_sync)) + if (change_stage(thd, Stage_manager::SYNC_STAGE, wait_queue, &LOCK_log, &LOCK_sync)) + { + DBUG_PRINT("return", ("Thread ID: %lu, commit_error: %d", + thd->thread_id, thd->commit_error)); + DBUG_RETURN(finish_commit(thd)); + } + final_queue= stage_manager.fetch_queue_for(Stage_manager::SYNC_STAGE); + if (flush_error == 0 && total_bytes > 0) + { + DEBUG_SYNC(thd, "before_sync_binlog_file"); + std::pair result= sync_binlog_file(force); + flush_error= result.first; + } + last_lock= (&LOCK_sync); + } else { - DBUG_PRINT("return", ("Thread ID: %lu, commit_error: %d", - thd->thread_id, thd->commit_error)); - DBUG_RETURN(finish_commit(thd)); + final_queue= wait_queue; + last_lock= (&LOCK_log); } - THD *final_queue= stage_manager.fetch_queue_for(Stage_manager::SYNC_STAGE); - if (flush_error == 0 && total_bytes > 0) - { - DEBUG_SYNC(thd, "before_sync_binlog_file"); - std::pair result= sync_binlog_file(false); - flush_error= result.first; - } if (update_binlog_end_pos_after_sync) { @@ -7418,7 +7448,7 @@ if (opt_binlog_order_commits) { if (change_stage(thd, Stage_manager::COMMIT_STAGE, - final_queue, &LOCK_sync, &LOCK_commit)) + final_queue, last_lock, &LOCK_commit)) { DBUG_PRINT("return", ("Thread ID: %lu, commit_error: %d", thd->thread_id, thd->commit_error)); @@ -7442,7 +7472,7 @@ } else { - mysql_mutex_unlock(&LOCK_sync); + mysql_mutex_unlock(last_lock); if (flush_error == 0) call_after_sync_hook(final_queue); } Index: sql/binlog.h =================================================================== --- sql/binlog.h (revision 6927) +++ sql/binlog.h (working copy) @@ -854,6 +854,7 @@ extern const char *log_bin_index; extern const char *log_bin_basename; extern bool opt_binlog_order_commits; +extern bool opt_binlog_skip_sync_stage; /** Turns a relative log binary log path into a full path, based on the Index: sql/sys_vars.cc =================================================================== --- sql/sys_vars.cc (revision 6927) +++ sql/sys_vars.cc (working copy) @@ -4940,3 +4940,11 @@ ON_CHECK(0), ON_UPDATE(update_session_track_state_change)); + +static Sys_var_mybool Sys_binlog_skip_sync_stage( + "binlog_skip_sync_stage", + "Skip the sync stage of group commit if we don't need to do" + " a binlog sync operation. This option takes affect only when" + " binlog_order_commits is turned off.", + GLOBAL_VAR(opt_binlog_skip_sync_stage), + CMD_LINE(OPT_ARG),DEFAULT(FALSE));