2026-03-19 17:04:35 +08:00
|
|
|
package binlog
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ParseBinlogFile(path string, fx func(transaction Transaction) bool) error {
|
2026-05-10 14:02:53 +08:00
|
|
|
return ParseBinlogWithOptions(path, ParseOptions{}, fx)
|
2026-03-19 17:04:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func finalizeTx(tx *Transaction, onlyShowGtid bool) {
|
|
|
|
|
idx := 0
|
|
|
|
|
for k, v := range tx.Txs {
|
|
|
|
|
if v.SqlType != "query" && len(tx.sqlOrigin) > idx {
|
|
|
|
|
v.Sql = tx.sqlOrigin[idx]
|
|
|
|
|
idx++
|
|
|
|
|
}
|
|
|
|
|
tx.RowsCount += v.RowCount
|
|
|
|
|
tx.Txs[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if onlyShowGtid {
|
|
|
|
|
tx.Size = 0
|
|
|
|
|
} else {
|
|
|
|
|
tx.Size = tx.EndPos - tx.StartPos
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fillTimeLazy(tx *Transaction) {
|
|
|
|
|
if tx.Timestamp != 0 && tx.Time.IsZero() {
|
|
|
|
|
tx.Time = time.Unix(tx.Timestamp, 0)
|
|
|
|
|
}
|
|
|
|
|
for i := range tx.Txs {
|
|
|
|
|
if tx.Txs[i].Timestamp != 0 && tx.Txs[i].Time.IsZero() {
|
|
|
|
|
tx.Txs[i].Time = time.Unix(tx.Txs[i].Timestamp, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|