(ev *replication.BinlogEvent, entriesChannel chan<- *common.EntryContext)
| 448 | } |
| 449 | |
| 450 | func (b *BinlogReader) handleEvent(ev *replication.BinlogEvent, entriesChannel chan<- *common.EntryContext) error { |
| 451 | switch ev.Header.EventType { |
| 452 | case replication.GTID_EVENT: |
| 453 | evt := ev.Event.(*replication.GTIDEvent) |
| 454 | b.currentCoordMutex.Lock() |
| 455 | // TODO this does not unlock until function return. wrap with func() if needed |
| 456 | defer b.currentCoordMutex.Unlock() |
| 457 | u, _ := uuid.FromBytes(evt.SID) |
| 458 | |
| 459 | entry := common.NewBinlogEntry() |
| 460 | entry.Coordinates = &common.MySQLCoordinateTx{ |
| 461 | LogFile: b.currentCoord.LogFile, |
| 462 | LogPos: int64(ev.Header.LogPos), |
| 463 | SID: u, |
| 464 | GNO: evt.GNO, |
| 465 | LastCommitted: evt.LastCommitted, |
| 466 | SeqenceNumber: evt.SequenceNumber, |
| 467 | } |
| 468 | entry.Index = 0 |
| 469 | entry.Final = true |
| 470 | |
| 471 | b.hasBeginQuery = false |
| 472 | b.entryContext = &common.EntryContext{ |
| 473 | Entry: entry, |
| 474 | TableItems: nil, |
| 475 | OriginalSize: 1, // GroupMaxSize is default to 1 and we send on EntriesSize >= GroupMaxSize |
| 476 | Rows: 0, |
| 477 | } |
| 478 | case replication.QUERY_EVENT: |
| 479 | return b.handleQueryEvent(ev, entriesChannel) |
| 480 | case replication.XID_EVENT: |
| 481 | evt := ev.Event.(*replication.XIDEvent) |
| 482 | b.currentCoord.LogPos = int64(ev.Header.LogPos) |
| 483 | // TODO is the pos the start or the end of a event? |
| 484 | // pos if which event should be use? Do we need +1? |
| 485 | mysqlCoordinates := b.entryContext.Entry.Coordinates.(*common.MySQLCoordinateTx) |
| 486 | mysqlCoordinates.LogPos = b.currentCoord.LogPos |
| 487 | b.sendEntry(entriesChannel) |
| 488 | |
| 489 | b.handleEventGSet(evt.GSet) |
| 490 | default: |
| 491 | if rowsEvent, ok := ev.Event.(*replication.RowsEvent); ok { |
| 492 | return b.handleRowsEvent(ev, rowsEvent, entriesChannel) |
| 493 | } |
| 494 | } |
| 495 | return nil |
| 496 | } |
| 497 | |
| 498 | func queryIsBegin(query string) bool { |
| 499 | return len(query) == 5 && strings.ToUpper(query) == "BEGIN" |
no test coverage detected