mariadb/storage
sjaakola ef2dbb8dbc MDEV-23328 Server hang due to Galera lock conflict resolution
Mutex order violation when wsrep bf thread kills a conflicting trx,
the stack is

          wsrep_thd_LOCK()
          wsrep_kill_victim()
          lock_rec_other_has_conflicting()
          lock_clust_rec_read_check_and_lock()
          row_search_mvcc()
          ha_innobase::index_read()
          ha_innobase::rnd_pos()
          handler::ha_rnd_pos()
          handler::rnd_pos_by_record()
          handler::ha_rnd_pos_by_record()
          Rows_log_event::find_row()
          Update_rows_log_event::do_exec_row()
          Rows_log_event::do_apply_event()
          Log_event::apply_event()
          wsrep_apply_events()

and mutexes are taken in the order

          lock_sys->mutex -> victim_trx->mutex -> victim_thread->LOCK_thd_data

When a normal KILL statement is executed, the stack is

          innobase_kill_query()
          kill_handlerton()
          plugin_foreach_with_mask()
          ha_kill_query()
          THD::awake()
          kill_one_thread()

        and mutexes are

          victim_thread->LOCK_thd_data -> lock_sys->mutex -> victim_trx->mutex

This patch is the plan D variant for fixing potetial mutex locking
order exercised by BF aborting and KILL command execution.

In this approach, KILL command is replicated as TOI operation.
This guarantees total isolation for the KILL command execution
in the first node: there is no concurrent replication applying
and no concurrent DDL executing. Therefore there is no risk of
BF aborting to happen in parallel with KILL command execution
either. Potential mutex deadlocks between the different mutex
access paths with KILL command execution and BF aborting cannot
therefore happen.

TOI replication is used, in this approach,  purely as means
to provide isolated KILL command execution in the first node.
KILL command should not (and must not) be applied in secondary
nodes. In this patch, we make this sure by skipping KILL
execution in secondary nodes, in applying phase, where we
bail out if applier thread is trying to execute KILL command.
This is effective, but skipping the applying of KILL command
could happen much earlier as well.

This also fixed unprotected calls to wsrep_thd_abort
that will use wsrep_abort_transaction. This is fixed
by holding THD::LOCK_thd_data while we abort transaction.

Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
2021-10-29 20:40:35 +02:00
..
archive Merge 10.4 into 10.5 2021-04-21 09:01:01 +03:00
blackhole Merge 10.3 into 10.4 2020-11-03 14:49:17 +02:00
cassandra Merge branch 'bb-10.4-release' into bb-10.5-release 2021-02-15 16:43:15 +01:00
columnstore columnstore-5.6.3-2 2021-10-29 12:19:34 +02:00
connect Merge branch '10.4' into 10.5 2021-10-29 10:21:52 +02:00
csv Merge branch 'bb-10.4-release' into bb-10.5-release 2021-02-15 16:43:15 +01:00
example remove mysql_declare_plugin declaration from some plugins 2020-07-04 01:44:47 +02:00
federated Fix various spelling errors still found in code 2021-03-22 18:10:39 +11:00
federatedx MDEV-22775: Merge 10.4 into 10.5 2021-04-08 08:08:53 +03:00
heap Merge 10.4 into 10.5 2021-06-08 16:03:53 +03:00
innobase MDEV-23328 Server hang due to Galera lock conflict resolution 2021-10-29 20:40:35 +02:00
maria Merge 10.4 into 10.5 2021-10-28 08:48:36 +03:00
mroonga Merge 10.4 into 10.5 2021-10-21 15:26:25 +03:00
myisam Merge 10.4 into 10.5 2021-10-13 12:33:56 +03:00
myisammrg Added 'final' to some classes to improve generated code 2020-08-04 17:27:32 +02:00
oqgraph Merge branch '10.4' into 10.5 2021-07-31 23:19:51 +02:00
perfschema perfschema: use correct type for left shifts 2021-09-12 15:42:49 +02:00
rocksdb Merge 10.4 into 10.5 2021-10-28 08:48:36 +03:00
sequence Merge branch 'bb-10.4-release' into bb-10.5-release 2021-02-15 16:43:15 +01:00
sphinx Merge branch 'bb-10.4-release' into bb-10.5-release 2021-02-15 16:43:15 +01:00
spider MDEV-26158 SIGSEGV in spider_free_mem from ha_spider::open on INSERT 2021-10-19 19:04:05 +09:00
test_sql_discovery Merge 10.4 into 10.5 2021-10-28 08:48:36 +03:00
tokudb Merge branch '10.4' into 10.5 2021-10-29 10:21:52 +02:00