Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug#32416819 ASSERTION "UT_LIST_GET_LEN.TRX_SYS->MYSQL_TRX_LIST. == 0"
ON SHUTDOWN Note: This commit in 8.0 is different from 8.4 and trunk due to testcase Background: ----------- The trx_sys->mysql_trx_list maintains a list of trx_t objects created for user transactions. When the `USE <database>` statement is run, a trx_t object is created for the THD running this query and added to this list. When the connection is closed, the trx_t object of the THD is freed and removed from this list. During shutdown, all the connections are closed before trx_sys is closed. When closing trx_sys, it is expected that all trx_t objects in trx_sys->mysql_trx_list are freed and the list is empty. In replication, when the applier sees an `XA START`, it detaches the THD from the handlertons by storing a backup in the engine's ha_data. In case of InnoDB, the trx_t created for the THD is stored in ha_data and is made nullptr; but not removed from the mysql_trx_list. In replication, the detached engine ha_data is reattached after the XA transaction is processed. During the reattach, the trx_t is restored from the ha_data back to the THD. By design, the detach happens when `XA START` is encountered by the applier. When the applier sees an `XA PREPARE`, the reattach is done via `applier_reset_xa_trans` calling `attach_native_trx`. When the applier sees an `XA COMMIT .. ONE PHASE`, the reattach is done in `ha_commit_low`. If the server is shutdown, the applier performs the reattach in `ha_rollback_low`. The binlog applier can be simulated by enabling `pseudo_replica_mode` and running a `BINLOG '0'`. Issue: ------ When the XA transaction is empty, the ha_list is nullptr. The reattach logic is performed only when ha_list is non-empty. Hence, if the server is shutdown after the applier detaches the engine (i.e, after running an `XA START`), the applier would never reattach the ha_data which leads to the assert when InnoDB closes trx_sys. Due to the design, the problem is seen only with the reattach in `ha_commit_low` and `ha_rollback_low`. Fix: ---- Ensured that reattach is done even if ha_list is empty. Change-Id: Ida617d067d112914c9d55ef4cde9f91956d19a08
- Loading branch information