WL#7193: Decouple THD and st_transactions
Affects: Server-5.7 — Status: Complete — Priority: Medium
The current paradigm of handling transactions in the server is that a transaction lives in the scope of connection. In other words, a transaction can not outlive the connection where the transaction has been started. This paradigm does not allow XA JOIN / XA RESUME operations, since those operations assume that a transaction can live longer than the initial connection. Moreover, a transaction can change different connections. Thus, in order to support operations XA JOIN/XA RESUME for distributed transactions we need to change that paradigm and allow transaction context to span outside its connection. That means that we need to decouple connection context (represented by class THD) and transaction context (represented by st_transactions structure). User Documentation ================== None required.
F1. information about an XA transaction in a prepared state has to be stored outside the THD class. It means that such information has to be external to the THD class. Requirements for refactoring: NF1. Rename st_transaction to Transaction_ctx. NF2. Move a declaration of Transaction_ctx outside THD class. NF3. Get rid of direct access to the data member THD::transaction, introduce the new method THD::get_transaction() for such access. NF4. Hide direct access to as many data member of class Transaction_ctx as possible. NF5. Move declarations/definitions of classes THD_TRANS, Ha_trx_info, Transaction_ctx from files sql_class.h/sql_class.cc to the separate files transaction_info.h/transaction_info.cc. NF6. Move THD_TRANS into the class Transaction_ctx to make the class THD_TRANS to be implementation details of Transaction_ctx.
Refactoring steps: ------------------ Currently the class st_transactions is declared inside THD (st_transactions is inner class for THD). THD has the data member 'transaction' of type st_transactions. To decouple st_transactions from THD the following steps will be done: 1. class st_transactions will be renamed to Transaction_ctx. 2. declaration of class Transaction_ctx will be moved from THD class (currently st_transactions is an inner class for THD). 3. new source files transaction_info.h, transaction_info.cc will be added where the declaration of classes THD_TRANS, Ha_trx_info, and Transaction_ctx will be placed. So, all runtime transaction specific staff will be collected in the dedicated source file. 4. the data member THD::transaction will be renamed to THD::m_transaction and will have private access specifier. To get access to the member THD::m_transaction the new method THD::get_transaction will be introduced. 5. New cache 'transaction_cache' will be introduced. This cache will be used to store instance of class st_transaction when such instance correspond to XA transaction. This new cache will replace the cache 'xid_cache'. Rationale for use the new files transaction_info.h/transaction_info.cc. ------------------ Currently there are the files transaction.h/transaction.cc that contains the following standalone functions for transaction management: bool trans_check_state(THD *thd); bool trans_begin(THD *thd, uint flags= 0); bool trans_commit(THD *thd); bool trans_commit_implicit(THD *thd); bool trans_rollback(THD *thd); bool trans_rollback_implicit(THD *thd); bool trans_commit_stmt(THD *thd); bool trans_rollback_stmt(THD *thd); bool trans_savepoint(THD *thd, LEX_STRING name); bool trans_rollback_to_savepoint(THD *thd, LEX_STRING name); bool trans_release_savepoint(THD *thd, LEX_STRING name); These functions are only contained in the files transaction.h/transaction.cc and used from other parts of the server when a new transaction has to be started/committed/rollbacked and so on, that is these functions forms transaction management interface. On the other hand, the things declared in transaction_info.h/transaction_info.cc are used by implementation of transaction management api, like functions ha_commit_low, ha_commit_trans, ha_rollaback and so on. From this point of view such things are details of implementation. By this reason those things were placed into the separate files transaction_info.h/transaction_info.cc.
Copyright (c) 2000, 2018, Oracle Corporation and/or its affiliates. All rights reserved.