GTID 的生命周期
1,A transaction is executed and committed on the replication source server. This client transaction is assigned a GTID composed of the source's UUID and the smallest nonzero transaction sequence number not yet used on this server. The GTID is written to the source's binary log (immediately preceding the transaction itself in the log). If a client transaction is not written to the binary log (for example, because the transaction was filtered out, or the transaction was read-only), it is not assigned a GTID
一个事务执行且提交后,会分配一个GTID(包含server_uuid和一个最小的非0事务序列号),如果事务被过滤或者只读,是不会分配GTID的。
2,If a GTID was assigned for the transaction, the GTID is persisted atomically at commit time by writing it to the binary log at the beginning of the transaction (as a
Gtid_log_event
). Whenever the binary log is rotated or the server is shut down, the server writes GTIDs for all transactions that were written into the previous binary log file into themysql.gtid_executed
table.
在commit之后,GTID会在写在binlog日志文件中(Gtid_log_event
),当binlog切换或者mysql关闭后,gtid会被写到mysql.gtid_executed
表中。
3,If a GTID was assigned for the transaction, the GTID is externalized non-atomically (very shortly after the transaction is committed) by adding it to the set of GTIDs in the
gtid_executed
system variable (@@GLOBAL.gtid_executed
)