|
|
|
@ -29,10 +29,14 @@ type Transaction struct {
|
|
|
|
|
EndPos int
|
|
|
|
|
Size int
|
|
|
|
|
RowsCount int
|
|
|
|
|
SQLOrigin string
|
|
|
|
|
sqlOrigin []string
|
|
|
|
|
Txs []TxDetail
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t Transaction) GetSqlOrigin() []string {
|
|
|
|
|
return t.sqlOrigin
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ParseBinlogFile(path string, fx func(transaction Transaction)) error {
|
|
|
|
|
return parseOneBinlog(path, fx)
|
|
|
|
|
}
|
|
|
|
@ -85,6 +89,9 @@ func parseBinlogDetail(r io.Reader, f func(Transaction)) error {
|
|
|
|
|
for {
|
|
|
|
|
headBuf := make([]byte, replication.EventHeaderSize)
|
|
|
|
|
if _, err = io.ReadFull(r, headBuf); err == io.EOF {
|
|
|
|
|
if tx.EndPos != 0 {
|
|
|
|
|
f(tx)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -151,9 +158,15 @@ func parseBinlogDetail(r io.Reader, f func(Transaction)) error {
|
|
|
|
|
}
|
|
|
|
|
switch sqlType {
|
|
|
|
|
case "gtid":
|
|
|
|
|
if currentGtid == "" {
|
|
|
|
|
for _, v := range tx.Txs {
|
|
|
|
|
if currentGtid != "" {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
tx.Size = tx.EndPos - tx.StartPos
|
|
|
|
|
if f != nil {
|
|
|
|
@ -172,7 +185,7 @@ func parseBinlogDetail(r io.Reader, f func(Transaction)) error {
|
|
|
|
|
continue
|
|
|
|
|
case "rowsquery":
|
|
|
|
|
tx.EndPos = int(h.LogPos)
|
|
|
|
|
tx.SQLOrigin = sql
|
|
|
|
|
tx.sqlOrigin = append(tx.sqlOrigin, sql)
|
|
|
|
|
default:
|
|
|
|
|
tx.EndPos = int(h.LogPos)
|
|
|
|
|
tx.Txs = append(tx.Txs, TxDetail{
|
|
|
|
|