Do not use MEM_ROOT in set_killed_no_mutex()

The reason for this change are the following:
- If we call set_killed() from one thread to kill another thread with
  a message, there may be concurrent usage of the MEM_ROOT which is
  not supported (this could cause memory corruption).
  We do not currently have code that does this, but the API allows this
  and it is better to be fix the issue before it happens.
- The per thread memory tracking does not work if one thread uses
  another threads MEM_ROOT.
- set_killed() can be called if a MEM_ROOT allocation fails.  In this case
  it is not good to try to allocate more memory from potentially the same
  MEM_ROOT.

Fix is to use my_malloc() instead of mem_root for killed messages.
This commit is contained in:
Monty 2023-11-23 16:59:21 +02:00
commit dc1165419a
3 changed files with 14 additions and 2 deletions

View file

@ -485,6 +485,7 @@ void wsrep_backup_kill_for_commit(THD *thd)
thd->wsrep_trx().state() != wsrep::transaction::s_must_replay)
{
thd->wsrep_abort_by_kill= thd->killed;
my_free(thd->wsrep_abort_by_kill_err);
thd->wsrep_abort_by_kill_err= thd->killed_err;
thd->killed= NOT_KILLED;
thd->killed_err= 0;
@ -497,6 +498,7 @@ void wsrep_restore_kill_after_commit(THD *thd)
DBUG_ASSERT(WSREP(thd));
mysql_mutex_assert_owner(&thd->LOCK_thd_kill);
thd->killed= thd->wsrep_abort_by_kill;
my_free(thd->killed_err);
thd->killed_err= thd->wsrep_abort_by_kill_err;
thd->wsrep_abort_by_kill= NOT_KILLED;
thd->wsrep_abort_by_kill_err= 0;