go-mysql-org / go-mysql

a powerful mysql toolset with Go
MIT License
4.58k stars 976 forks source link

How to use TRANSACTION_CONTEXT_EVENT for the replication #857

Open zhanghaiyang9999 opened 5 months ago

zhanghaiyang9999 commented 5 months ago

When using the following code, how to detect what's is the transaction begin(if a transaction has multiple operations) ? is the TRANSACTION_CONTEXT_EVENT ? thanks!

streamer, err := syncer.StartSync(pos) contx, cancel := context.WithTimeout(context.Background(), time.Second) ev, err := streamer.GetEvent(contx)

lance6716 commented 5 months ago

it depends on your mysql version. you can dump every events to log and find the pattern. for some mysql version, I remember there are "BEGIN" query events for each transaction.

cameron-p-m commented 5 months ago

If you have GTID enabled, GTID_event is the beginning of the transaction and Xid_event is the end of the transaction.