Commit 18f88d6d authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-7943 - pthread_getspecific() takes 0.76% in OLTP RO

Avoid calling current_thd from thd_kill_level(). This reduces number of
pthread_getspecific() calls from 776 to 354.

Also thd_kill_level(NULL) is not permitted anymore: this saves one condition.
parent f8cacd03
...@@ -635,7 +635,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, ...@@ -635,7 +635,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
(int)is_on()); (int)is_on());
} }
while (is_on() && !thd_killed(NULL)) while (is_on() && !thd_killed(current_thd))
{ {
if (reply_file_name_inited_) if (reply_file_name_inited_)
{ {
...@@ -747,7 +747,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, ...@@ -747,7 +747,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
At this point, the binlog file and position of this transaction At this point, the binlog file and position of this transaction
must have been removed from ActiveTranx. must have been removed from ActiveTranx.
*/ */
assert(thd_killed(NULL) || assert(thd_killed(current_thd) ||
!active_tranxs_->is_tranx_end_pos(trx_wait_binlog_name, !active_tranxs_->is_tranx_end_pos(trx_wait_binlog_name,
trx_wait_binlog_pos)); trx_wait_binlog_pos));
......
...@@ -4205,23 +4205,30 @@ extern "C" int thd_killed(const MYSQL_THD thd) ...@@ -4205,23 +4205,30 @@ extern "C" int thd_killed(const MYSQL_THD thd)
/* /*
return thd->killed status to the client, return thd->killed status to the client,
mapped to the API enum thd_kill_levels values. mapped to the API enum thd_kill_levels values.
@note Since this function is called quite frequently thd_kill_level(NULL) is
forbidden for performance reasons (saves one conditional branch). If your ever
need to call thd_kill_level() when THD is not available, you options are (most
to least preferred):
- try to pass THD through to thd_kill_level()
- add current_thd to some service and use thd_killed(current_thd)
- add thd_killed_current() function to kill statement service
- add if (!thd) thd= current_thd here
*/ */
extern "C" enum thd_kill_levels thd_kill_level(const MYSQL_THD thd) extern "C" enum thd_kill_levels thd_kill_level(const MYSQL_THD thd)
{ {
THD* current= current_thd; DBUG_ASSERT(thd);
if (!thd)
thd= current;
if (thd == current)
{
Apc_target *apc_target= (Apc_target*)&thd->apc_target;
if (apc_target->have_apc_requests())
apc_target->process_apc_requests();
}
if (likely(thd->killed == NOT_KILLED)) if (likely(thd->killed == NOT_KILLED))
{
Apc_target *apc_target= (Apc_target*) &thd->apc_target;
if (unlikely(apc_target->have_apc_requests()))
{
if (thd == current_thd)
apc_target->process_apc_requests();
}
return THD_IS_NOT_KILLED; return THD_IS_NOT_KILLED;
}
return thd->killed & KILL_HARD_BIT ? THD_ABORT_ASAP : THD_ABORT_SOFTLY; return thd->killed & KILL_HARD_BIT ? THD_ABORT_ASAP : THD_ABORT_SOFTLY;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment