Skip to content

Commit

Permalink
remove find_thread_with_thd_data_lock_callback
Browse files Browse the repository at this point in the history
let the caller take the lock if needed
  • Loading branch information
vuvova committed Feb 12, 2021
1 parent eac8341 commit 259b945
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
27 changes: 5 additions & 22 deletions sql/sql_parse.cc
Expand Up @@ -9098,24 +9098,6 @@ THD *find_thread_by_id(longlong id, bool query_id)
return arg.thd;
}

static my_bool find_thread_with_thd_data_lock_callback(THD *thd, find_thread_callback_arg *arg)
{
if (arg->id == (arg->query_id ? thd->query_id : (longlong) thd->thread_id))
{
mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete
mysql_mutex_lock(&thd->LOCK_thd_data); // XXX DELME
arg->thd= thd;
return 1;
}
return 0;
}
THD *find_thread_by_id_with_thd_data_lock(longlong id, bool query_id)
{
find_thread_callback_arg arg(id, query_id);
server_threads.iterate(find_thread_with_thd_data_lock_callback, &arg);
return arg.thd;
}

/**
kill one thread.
Expand All @@ -9132,7 +9114,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ
uint error= (type == KILL_TYPE_QUERY ? ER_NO_SUCH_QUERY : ER_NO_SUCH_THREAD);
DBUG_ENTER("kill_one_thread");
DBUG_PRINT("enter", ("id: %lld signal: %u", id, (uint) kill_signal));
tmp= find_thread_by_id_with_thd_data_lock(id, type == KILL_TYPE_QUERY);
tmp= find_thread_by_id(id, type == KILL_TYPE_QUERY);
if (!tmp)
DBUG_RETURN(error);

Expand All @@ -9159,6 +9141,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ
faster and do a harder kill than KILL_SYSTEM_THREAD;
*/

mysql_mutex_lock(&tmp->LOCK_thd_data); // for various wsrep* checks below
#ifdef WITH_WSREP
if (((thd->security_ctx->master_access & SUPER_ACL) ||
thd->security_ctx->user_matches(tmp->security_ctx)) &&
Expand All @@ -9180,8 +9163,8 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ
else
#endif /* WITH_WSREP */
{
WSREP_DEBUG("kill_one_thread %llu, victim: %llu wsrep_aborter %llu by signal %d",
thd->thread_id, id, tmp->wsrep_aborter, kill_signal);
WSREP_DEBUG("kill_one_thread %llu, victim: %llu wsrep_aborter %llu by signal %d",
thd->thread_id, id, tmp->wsrep_aborter, kill_signal);
tmp->awake_no_mutex(kill_signal);
WSREP_DEBUG("victim: %llu taken care of", id);
error= 0;
Expand All @@ -9190,9 +9173,9 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ
else
error= (type == KILL_TYPE_QUERY ? ER_KILL_QUERY_DENIED_ERROR :
ER_KILL_DENIED_ERROR);
mysql_mutex_unlock(&tmp->LOCK_thd_data);
}
mysql_mutex_unlock(&tmp->LOCK_thd_kill);
mysql_mutex_unlock(&tmp->LOCK_thd_data);
DBUG_PRINT("exit", ("%d", error));
DBUG_RETURN(error);
}
Expand Down
1 change: 0 additions & 1 deletion sql/sql_show.h
Expand Up @@ -144,7 +144,6 @@ const char* get_one_variable(THD *thd, const SHOW_VAR *variable,
/* These functions were under INNODB_COMPATIBILITY_HOOKS */
int get_quote_char_for_identifier(THD *thd, const char *name, size_t length);
THD *find_thread_by_id(longlong id, bool query_id= false);
THD *find_thread_by_id_with_thd_data_lock(longlong id, bool query_id= false);

class select_result_explain_buffer;
/*
Expand Down
6 changes: 4 additions & 2 deletions storage/innobase/handler/ha_innodb.cc
Expand Up @@ -18583,8 +18583,10 @@ static void bg_wsrep_kill_trx(void *void_arg)
trx_t *victim_trx;
bool aborting= false;

bf_thd= find_thread_by_id_with_thd_data_lock(arg->bf_thd_id);
thd= find_thread_by_id_with_thd_data_lock(arg->thd_id);
if ((bf_thd= find_thread_by_id(arg->bf_thd_id)))
wsrep_thd_LOCK(bf_thd);
if ((thd= find_thread_by_id(arg->thd_id)))
wsrep_thd_LOCK(thd);

if (!thd || !bf_thd || !(victim_trx= thd_to_trx(thd)))
goto ret0;
Expand Down

0 comments on commit 259b945

Please sign in to comment.