MCPcopy Create free account
hub / github.com/actiontech/dtle / StreamEvents

Method StreamEvents

driver/oracle/extractor/extractor_oracle.go:678–775  ·  view source on GitHub ↗

StreamEvents will begin streaming events. It will be blocking, so should be executed by a goroutine

()

Source from the content-addressed store, hash-verified

676// StreamEvents will begin streaming events. It will be blocking, so should be
677// executed by a goroutine
678func (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

Callers 1

initiateStreamingMethod · 0.95

Calls 6

publishMethod · 0.95
onErrorMethod · 0.95
DataStreamEventsMethod · 0.95
EncodeFunction · 0.92
SizeMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected