StreamEvents will begin streaming events. It will be blocking, so should be executed by a goroutine
()
| 676 | // StreamEvents will begin streaming events. It will be blocking, so should be |
| 677 | // executed by a goroutine |
| 678 | func (e *ExtractorOracle) StreamEvents() error { |
| 679 | e.wg.Add(1) |
| 680 | go func() { |
| 681 | defer func() { |
| 682 | e.wg.Done() |
| 683 | e.logger.Debug("StreamEvents goroutine exited") |
| 684 | }() |
| 685 | entries := common.DataEntries{} |
| 686 | entriesSize := 0 |
| 687 | sendEntriesAndClear := func() error { |
| 688 | var gno int64 = 0 |
| 689 | if len(entries.Entries) > 0 { |
| 690 | theEntries := entries.Entries[0] |
| 691 | // gno = theEntries.Coordinates.GNO |
| 692 | if theEntries.Events != nil && len(theEntries.Events) > 0 { |
| 693 | //e.timestampCtx.TimestampCh <- theEntries.Events[0].Timestamp |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | txMsg, err := common.Encode(&entries) |
| 698 | if err != nil { |
| 699 | return err |
| 700 | } |
| 701 | e.logger.Debug("publish.before", "gno", gno, "n", len(entries.Entries)) |
| 702 | if err = e.publish(fmt.Sprintf("%s_incr_hete", e.subject), txMsg, gno); err != nil { |
| 703 | return err |
| 704 | } |
| 705 | |
| 706 | for _, entry := range entries.Entries { |
| 707 | atomic.AddInt64(e.memory2, -int64(entry.Size())) |
| 708 | } |
| 709 | |
| 710 | e.logger.Debug("publish.after", "gno", gno, "n", len(entries.Entries)) |
| 711 | entries.Entries = nil |
| 712 | entriesSize = 0 |
| 713 | |
| 714 | return nil |
| 715 | } |
| 716 | |
| 717 | groupTimeoutDuration := time.Duration(e.mysqlContext.GroupTimeout) * time.Millisecond |
| 718 | timer := time.NewTimer(groupTimeoutDuration) |
| 719 | defer timer.Stop() |
| 720 | |
| 721 | LOOP: |
| 722 | for !e.shutdown { |
| 723 | select { |
| 724 | case entryCtx := <-e.dataChannel: |
| 725 | binlogEntry := entryCtx.Entry |
| 726 | |
| 727 | entries.Entries = append(entries.Entries, binlogEntry) |
| 728 | entriesSize += entryCtx.OriginalSize |
| 729 | |
| 730 | if entriesSize >= e.mysqlContext.GroupMaxSize { |
| 731 | e.logger.Debug("incr. send by GroupLimit", |
| 732 | "entriesSize", entriesSize, |
| 733 | "groupMaxSize", e.mysqlContext.GroupMaxSize, |
| 734 | "Entries.len", len(entries.Entries)) |
| 735 |
no test coverage detected