diff --git a/parse.go b/parse.go index 879ebc6..703c55e 100644 --- a/parse.go +++ b/parse.go @@ -34,17 +34,17 @@ const ( ) type Transaction struct { - GTID string `json:"gtid"` - Timestamp int64 `json:"timestamp"` - Time time.Time `json:"time"` - StartPos int `json:"startPos"` - EndPos int `json:"endPos"` - Size int `json:"size"` - RowsCount int `json:"rowsCount"` - Status uint8 `json:"status"` - sqlOrigin []string `json:"sqlOrigin"` - Txs []TxDetail `json:"txs"` - matchFilterSchema bool + GTID string `json:"gtid"` + Timestamp int64 `json:"timestamp"` + Time time.Time `json:"time"` + StartPos int `json:"startPos"` + EndPos int `json:"endPos"` + Size int `json:"size"` + RowsCount int `json:"rowsCount"` + Status uint8 `json:"status"` + sqlOrigin []string `json:"sqlOrigin"` + Txs []TxDetail `json:"txs"` + validSchemaCount int } func (t Transaction) GetSqlOrigin() []string { @@ -371,6 +371,9 @@ func parseBinlogWithFilter(r io.Reader, parse *replication.BinlogParser, filter if len(filter.ExcludeTables) == 0 && len(filter.ExcludeTables) == 0 { return true } + if db == "" && tb == "" { + return true + } if _, ok := includeMap["*.*"]; ok { return true } @@ -444,7 +447,7 @@ func parseBinlogWithFilter(r io.Reader, parse *replication.BinlogParser, filter if filter.SmallThan != 0 && filter.SmallThan < tx.Size { return true } - if len(tx.Txs) == 0 && tx.matchFilterSchema { + if tx.validSchemaCount == 0 { return true } return fn(tx) @@ -617,9 +620,9 @@ func parseBinlogWithFilter(r io.Reader, parse *replication.BinlogParser, filter tx.Status = status } if !matchTbs(ev.DB, ev.TB) { - tx.matchFilterSchema = true continue } + tx.validSchemaCount++ tx.Txs = append(tx.Txs, TxDetail{ StartPos: startPos, EndPos: int(h.LogPos),