• sjaakola's avatar
    MDEV-21910 Deadlock between BF abort and manual KILL command · 7bffe468
    sjaakola authored
    When high priority replication slave applier encounters lock conflict in innodb,
    it will force the conflicting lock holder transaction (victim) to rollback.
    This is a must in multi-master sychronous replication model to avoid cluster lock-up.
    This high priority victim abort (aka "brute force" (BF) abort), is started
    from innodb lock manager while holding the victim's transaction's (trx) mutex.
    Depending on the execution state of the victim transaction, it may happen that the
    BF abort will call for THD::awake() to wake up the victim transaction for the rollback.
    Now, if BF abort requires THD::awake() to be called, then the applier thread executed
    locking protocol of: victim trx mutex -> victim THD::LOCK_thd_data
    
    If, at the same time another DBMS super user issues KILL command to abort the same victim,
    it will execute locking protocol of: victim THD::LOCK_thd_data  -> victim trx mutex.
    These two locking protocol acquire mutexes in opposite order, hence unresolvable mutex locking
    deadlock may occur.
    
    The fix in this commit adds THD::wsrep_aborter flag to synchronize who can kill the victim
    This flag is set both when BF is called for from innodb and by KILL command.
    Either path of victim killing will bail out if victim's wsrep_killed is already
    set to avoid mutex conflicts with the other aborter execution. THD::wsrep_aborter
    records the aborter THD's ID. This is needed to preserve the right to kill
    the victim from different locations for the same aborter thread.
    It is also good error logging, to see who is reponsible for the abort.
    
    A new test case was added in galera.galera_bf_kill_debug.test for scenario where
    wsrep applier thread and manual KILL command try to kill same idle victim
    7bffe468
galera_bf_lock_wait.test 1.43 KB