diff options
author | unknown <knielsen@knielsen-hq.org> | 2011-03-23 15:29:20 +0100 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2011-03-23 15:29:20 +0100 |
commit | ca5ca4b968297ac4dc5d0850752306b92570b6a1 (patch) | |
tree | 56115abfda488804535ac91643347be6f1e1396d /sql/log.cc | |
parent | a2d921be3634ceff4ab4c67f57b27a481d4a28df (diff) | |
download | mariadb-git-ca5ca4b968297ac4dc5d0850752306b92570b6a1.tar.gz |
MWL#116: group commit
Implement binlog_optimize_thread_scheduling option to allow benchmarking the
effect of running commit_ordered() for multiple transactions all in one
thread.
Diffstat (limited to 'sql/log.cc')
-rw-r--r-- | sql/log.cc | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/sql/log.cc b/sql/log.cc index d18ded1f24e..c1e13452733 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2510,7 +2510,8 @@ const char *MYSQL_LOG::generate_name(const char *log_name, MYSQL_BIN_LOG::MYSQL_BIN_LOG() :bytes_written(0), prepared_xids(0), file_id(1), open_count(1), need_start_event(TRUE), - group_commit_queue(0), num_commits(0), num_group_commits(0), + group_commit_queue(0), group_commit_queue_busy(FALSE), + num_commits(0), num_group_commits(0), is_relay_log(0), description_event_for_exec(0), description_event_for_queue(0) { @@ -2567,6 +2568,7 @@ void MYSQL_BIN_LOG::init_pthread_objects() (void) my_pthread_mutex_init(&LOCK_index, MY_MUTEX_INIT_SLOW, "LOCK_index", MYF_NO_DEADLOCK_DETECTION); (void) pthread_cond_init(&update_cond, 0); + (void) pthread_cond_init(&COND_queue_busy, 0); } @@ -3989,6 +3991,7 @@ err: } +static my_bool opt_optimize_thread_scheduling= TRUE; #ifndef DBUG_OFF static ulong opt_binlog_dbug_fsync_sleep= 0; #endif @@ -4925,6 +4928,32 @@ MYSQL_BIN_LOG::write_transaction_to_binlog_events(group_commit_entry *entry) else trx_group_commit_leader(entry); + if (!opt_optimize_thread_scheduling) + { + /* For the leader, trx_group_commit_leader() already took the lock. */ + if (orig_queue != NULL) + pthread_mutex_lock(&LOCK_commit_ordered); + + DEBUG_SYNC(entry->thd, "commit_loop_entry_commit_ordered"); + ++num_commits; + if (entry->trx_data->using_xa && !entry->error) + run_commit_ordered(entry->thd, entry->all); + + group_commit_entry *next= entry->next; + if (!next) + { + group_commit_queue_busy= FALSE; + pthread_cond_signal(&COND_queue_busy); + DEBUG_SYNC(entry->thd, "commit_after_group_run_commit_ordered"); + } + pthread_mutex_unlock(&LOCK_commit_ordered); + + if (next) + { + next->thd->signal_wakeup_ready(); + } + } + if (!entry->error) return 0; @@ -5088,6 +5117,24 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) DEBUG_SYNC(leader->thd, "commit_after_release_LOCK_log"); ++num_group_commits; + if (!opt_optimize_thread_scheduling) + { + /* + If we want to run commit_ordered() each in the transaction's own thread + context, then we need to mark the queue reserved; we need to finish all + threads in one group commit before the next group commit can be allowed + to proceed, and we cannot unlock a simple pthreads mutex in a different + thread from the one that locked it. + */ + + while (group_commit_queue_busy) + pthread_cond_wait(&COND_queue_busy, &LOCK_commit_ordered); + group_commit_queue_busy= TRUE; + + /* Note that we return with LOCK_commit_ordered locked! */ + DBUG_VOID_RETURN; + } + /* Wakeup each participant waiting for our group commit, first calling the commit_ordered() methods for any transactions doing 2-phase commit. @@ -6578,6 +6625,16 @@ static SHOW_VAR binlog_status_vars_top[]= { {NullS, NullS, SHOW_LONG} }; +static MYSQL_SYSVAR_BOOL( + optimize_thread_scheduling, + opt_optimize_thread_scheduling, + PLUGIN_VAR_READONLY, + "Run fast part of group commit in a single thread, to optimize kernel\n" + "thread scheduling", + NULL, + NULL, + 1); + #ifndef DBUG_OFF static MYSQL_SYSVAR_ULONG( dbug_fsync_sleep, @@ -6590,13 +6647,16 @@ static MYSQL_SYSVAR_ULONG( 0, ULONG_MAX, 0); +#endif static struct st_mysql_sys_var *binlog_sys_vars[]= { + MYSQL_SYSVAR(optimize_thread_scheduling), +#ifndef DBUG_OFF MYSQL_SYSVAR(dbug_fsync_sleep), +#endif NULL }; -#endif /* @@ -6634,11 +6694,7 @@ mysql_declare_plugin(binlog) NULL, /* Plugin Deinit */ 0x0100 /* 1.0 */, binlog_status_vars_top, /* status variables */ -#ifndef DBUG_OFF binlog_sys_vars, /* system variables */ -#else - NULL, /* system variables */ -#endif NULL /* config options */ } mysql_declare_plugin_end; |