Said MGR - global transaction authentication module & remote transaction execution module

Global transaction authentication module


Global transaction authentication module has a message queue for storing received messages. These are primarily Binlog Event transaction, also part of the status and control messages. Field in the state table replication_group_member_stats COUNT_TRANSACTIONS_IN_QUEUE refers to the number of transactions in the queue.


Global transaction authentication module core task is to do collision detection, identify those transactions simultaneously modify the same data, and make the appropriate treatment. Information needed includes three time collision detection.


· Primary key information.

• Transaction snapshot version of the database when.

· UUID MySQL instances of executing the transaction.



Information required for conflict detection


MGR collision detection in units of data, two transactions are not the same data is modified, by modifying the firm judgment of the primary key values. When they find the two transactions modify the same data, how to judge these two transactions are not simultaneously enforce it? This uses the database snapshot version. A database snapshot is a transient state database, each write operation will lead to changes in the database state, different states are represented by different snapshot version. GTID snapshot version is represented, each write transaction will generate a unique GTID, this GTID generated by the global transaction authentication module, and will be added to the global variables gtid_executed at the time of the transaction commits. Therefore, gtid_executed content is a snapshot version of the MySQL database.


Collision Detection Database


Global transaction authentication module also maintains a database conflict detection, it is the primary key hash + snapshot version of the list. Snapshot storage version is the last transaction to modify this key primary snapshot version plus this transaction GTID. After receiving the transaction information, global transaction authentication module based on the primary key information Transaction_context_log_event, conflict detection is retrieved from all database snapshot and the snapshot versions of the primary key of the version of the transaction are compared. Current snapshot version of the transaction must be retrieved GTID include all primary key snapshot version, otherwise there is a conflict.


Conflict management


After detecting the conflict, the global authentication module is the next processing local and remote transaction the transaction differentiation. Transaction_context_log_event recorded in the UUID generated for this transaction MySQL instance. According to the UUID, we can determine this is a local or remote transactional matters. For local transactions as follows.


If there is no conflict, wake up the thread of this transaction, and tell it to complete the commit operation.

If there is a conflict, wake up the thread of affairs, and tell it in conflict, need to roll back.

· Whether there is a conflict, Binlog Event will be discarded.


For off-site transaction processing is as follows.


If there is no conflict, this transaction will Binlog Event writing Relay log in, let group_replication_applier channel execution.

If there is a conflict, then discard Binlog Event this transaction.



Cleanup conflict detection database


With the use of more and more time, the primary key conflict detection information maintained in the database will be more and more, will take up a lot of memory. In order to reduce memory usage and improve query efficiency, global transaction authentication module requires regular cleaning collision detection database. If a transaction has been executed on all members, and perform other transactions and it certainly will not conflict, so that all primary key information on this transaction can be removed from the conflict detection database. Clean up the primary key information is based on a global variable gtid_executed GTID members of the set to do. Global authentication module started a thread broadcast every 60 seconds set of broadcast to all the members of his gtid_executed GTID. After the global authentication module received GTID set of all members take their intersection. This intersection is a collection that has been performed on all members of the affairs GTID contained, known as a global completed GTID collection (replication_group_member_stats table TRANSACTIONS_COMMITTED_ALL_MEMBERS display is completed GTID global collection.). Snapshot version of the global transaction authentication module will conflict detection database of all primary key and global completed GTID collection contrast, if the snapshot version GTID set is a subset of the global completed GTID the collection, the information this master key would conflict detection database from removed.



Remote transaction execution module


To Binlog Event execute remote transactions, MGR will automatically create a channel called group_replication_applier of. Receiver thread this channel is closed, and will not go up Binlog Event copied from other members. All Binlog Event Relay log is written to the API by the global transaction authentication modules.


Summary of the transaction process


During the execution of a transaction in MGR can be summarized as the following three parts.

·network transmission.

• Transactions in the local implementation process.

· Execution of transactions in different places.



network transmission


MGR transaction information to spread through the Paxos protocol. Paxos security of all transaction information dissemination to all members of the same order.


Execution of transactions on the local member


Transactions when local commit (after prepare, before writing Binlog), transaction information is sent to the communication module, and then began to wait for the transaction authentication result. Communication module will be sent to local members of global transaction authentication module after the transaction ordering. Global transaction authentication module done after collision detection, wake up the transaction proceed, or rolled back.


Execution of transactions on remote members


Communication module sends the authentication module to the global transaction after transaction ordering. After the global transaction authentication module the authentication is successful, the write transaction Binlog Event Relay log, performed by group_replication_applier channel. If a global transaction authentication module authentication fails, Binlog Event of the transaction will be discarded.

Guess you like

Origin blog.51cto.com/coveringindex/2440111