Index: sql/binlog.cc =================================================================== --- sql/binlog.cc (revision 6700) +++ sql/binlog.cc (working copy) @@ -62,7 +62,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; @@ -6868,30 +6868,46 @@ /* Stage #2: Syncing binary log file to disk */ - bool need_LOCK_log= (get_sync_period() == 1); + uint sync_period= (get_sync_period()); + bool need_LOCK_log= (sync_period == 1); + bool skip_sync_stage= ((!opt_binlog_order_commits) && opt_binlog_skip_sync_stage && + (sync_period == 0 || (sync_counter<(sync_period-1)))); + THD* final_queue= NULL; + mysql_mutex_t* last_lock= NULL; /* LOCK_log is not released when sync_binlog is 1. It guarantees that the events are not be replicated by dump threads before they are synced to disk. */ - if (change_stage(thd, Stage_manager::SYNC_STAGE, wait_queue, - need_LOCK_log ? NULL : &LOCK_log, &LOCK_sync)) + if (!skip_sync_stage) { - DBUG_PRINT("return", ("Thread ID: %lu, commit_error: %d", - thd->thread_id, thd->commit_error)); - DBUG_RETURN(finish_commit(thd)); - } - THD *final_queue= stage_manager.fetch_queue_for(Stage_manager::SYNC_STAGE); - if (flush_error == 0 && total_bytes > 0) + if (change_stage(thd, Stage_manager::SYNC_STAGE, wait_queue, + need_LOCK_log ? NULL : &LOCK_log, &LOCK_sync)) + { + DBUG_PRINT("return", ("Thread ID: %lu, commit_error: %d", + thd->thread_id, thd->commit_error)); + DBUG_RETURN(finish_commit(thd)); + } + + last_lock= (&LOCK_sync); + 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 (need_LOCK_log) + mysql_mutex_unlock(&LOCK_log); + } else { - DEBUG_SYNC(thd, "before_sync_binlog_file"); - std::pair result= sync_binlog_file(false); - flush_error= result.first; + if (sync_period) + sync_counter++; + + final_queue= wait_queue; + last_lock= (&LOCK_log); } - - if (need_LOCK_log) - mysql_mutex_unlock(&LOCK_log); - /* Stage #3: Commit all transactions in order. @@ -6904,7 +6920,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)); @@ -6923,7 +6939,7 @@ final_queue= commit_queue; } else - mysql_mutex_unlock(&LOCK_sync); + mysql_mutex_unlock(last_lock); /* Commit done so signal all waiting threads */ stage_manager.signal_done(final_queue); Index: sql/binlog.h =================================================================== --- sql/binlog.h (revision 6700) +++ sql/binlog.h (working copy) @@ -712,7 +712,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 opt_bin_logname or opt_relay_logname. Index: sql/sys_vars.cc =================================================================== --- sql/sys_vars.cc (revision 6700) +++ sql/sys_vars.cc (working copy) @@ -937,6 +937,12 @@ GLOBAL_VAR(opt_binlog_order_commits), CMD_LINE(OPT_ARG), DEFAULT(TRUE)); +static Sys_var_mybool Sys_binlog_skip_sync_stage( + "binlog_skip_sync_stage", + "enter into sync stage only when needed.", + GLOBAL_VAR(opt_binlog_skip_sync_stage), + CMD_LINE(OPT_ARG), DEFAULT(FALSE)); + static Sys_var_ulong Sys_bulk_insert_buff_size( "bulk_insert_buffer_size", "Size of tree cache used in bulk " "insert optimisation. Note that this is a limit per thread!",