• Sergei Golubchik's avatar
    MDEV-7126 replication slave - deadlock in terminate_slave_thread with stop... · f8320210
    Sergei Golubchik authored
    MDEV-7126 replication slave - deadlock in terminate_slave_thread with stop slave and show variables of replication filters and show global status
    
    Three-way deadlock:
    
      T1: SHOW GLOBAL STATUS
          -> acquire LOCK_status
      T2: STOP SLAVE
          -> acquire LOCK_active_mi
          -> terminate_slave_thread()
          -> -> cond_timedwait for handle_slave_sql to stop
      T3: sql slave thread (same applies to io thread)
          -> handle_slave_sql(), when exiting
          -> -> THD::add_status_to_global()
          -> -> -> wait for LOCK_status...
      T1: SHOW GLOBAL STATUS
          -> for "Slave_heartbeat_period" status variable
          -> -> show_heartbeat_period()
          -> -> -> wait for LOCK_active_mi
    
    cherry-pick from 5.6:
    
      commit fc8b395898f40387b3468122bd0dae31e29a6fde
      Author: Venkatesh Duggirala <venkatesh.duggirala@oracle.com>
      Date:   Wed Jun 12 21:41:05 2013 +0530
    
        BUG#16904035-SHOW STATUS - EXCESSIVE LOCKING ON LOCK_ACTIVE_MI AND
        ACTIVE_MI->RLI->DATA_LOCK
    
        Problem: Excessive locking on lock_active_mi and rli->data_lock
        while executing any `show status like 'X'` command.
    
        Analysis: SHOW_FUNCs for Slave_running, Slave_retried_transactions,
        Slave_heartbeat_period, Slave_received_heartbeats,
        Slave_last_heartbeat are acquiring lock_active_mi and rli->data_lock
        to show their variable value. It is ok to show stale data while showing
        the status variables i.e., even if they miss one update, it will
        not cause any great trouble.
    
        Fix: Remove the locks from the above mentioned SHOW_FUNC functions.
    
    Add a test case
    f8320210
show_status_stop_slave_race-7126.result 45 Bytes