Code Implementation
Table 1 lists the new classes of the MySQL lock-free tuning feature.
Class |
Description |
|---|---|
rw_trx_hash_t |
Lock-free hash container, which encapsulates the MySQL LF_HASH. |
rw_trx_hash_element_t |
Elements of rw_trx_hash_t. |
Changes in trx_lists_init_at_db_start: During the database startup process, the TrxIdSet whose life cycle is trx_lists_init_at_db_start is used to implement the original global TrxIdSet function. In "Ressurrect transactions that were doing updates" of trx_resurrect, trxid is used to locate the transaction instance, which prevents repeated creation of trx instances.
Changes in trx_reference: Atomic operations are used to replace the original mutex protection.
Changes in trx_erase_lists: The rw_trx_set.erase operation is removed from the trx_sys->mutex critical region.
Changes in trx_release_impl_and_expl_locks:
- trx_sys->rw_trx_hash.erase is added outside the critical region of trx_sys->mutex to replace rw_trx_set.erase in trx_erase_lists.
- To ensure that rw_trx_hash contains only transactions in the PREPARED or ACTIVE state, trx->state = TRX_STATE_COMMITTED_IN_MEMORY in trx_release_impl_and_expl_locks is moved out of the critical region of trx_sys->mutex.
- The original code contains the following comment:
As trx->state = TRX_STATE_COMMITTED_IN_MEMORY has been moved out of the critical region of trx_sys->mutex, method (1) does not work anymore. As a result, the lock_rec_convert_impl_to_expl of method (1) may see that trx has been moved out of rw_trx_hash, but the state has not been TRX_STATE_COMMITTED_IN_MEMORY. In this case, the correctness of the lock_rec_convert_impl_to_expl is ensured as follows:
- In the context of lock_rec_convert_impl_to_expl, trx does not exist in rw_trx_hash, which is equivalent to !trx_rw_is_active() of the original logic.
- lock_rec_convert_impl_to_expl uses lock_rec_convert_impl_to_expl_for_trx to determine the transaction status again, that is, "deciding for the final time if we really want to create explicit lock on behalf of implicit lock holder" in the comment.
Changes in trx_rw_is_active and trx_rw_is_active_low: The two interfaces are deleted and replaced by rw_trx_hash.find.
Changes in trx_get_rw_trx_by_id: This interface is deleted and replaced by rw_trx_hash.find.
Changes in trx_assert_recovered: This interface is deleted because it is not used.
Changes in trx_sys_rw_trx_add: This interface is deleted because it has incorrect semantics. rw_trx_hash.insert is used instead.
Changes in rec_queue_validate_latched: Due to the changes in trx_release_impl_and_expl_locks, a method similar to lock_rec_convert_impl_to_expl_for_trx is used to determine the transaction state.
