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

Method StreamEvents

driver/mysql/extractor.go:972–1068  ·  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

970// StreamEvents will begin streaming events. It will be blocking, so should be
971// executed by a goroutine
972func (e *Extractor) StreamEvents() error {
973 e.wg.Add(1)
974 go func() {
975 defer func() {
976 e.wg.Done()
977 e.logger.Debug("StreamEvents goroutine exited")
978 }()
979 entries := common.DataEntries{}
980 entriesSize := 0
981 sendEntriesAndClear := func() error {
982 var gno int64 = 0
983 if len(entries.Entries) > 0 {
984 theEntries := entries.Entries[0]
985 gno = theEntries.Coordinates.GetGNO()
986 if theEntries.Events != nil && len(theEntries.Events) > 0 {
987 e.timestampCtx.TimestampCh <- theEntries.Events[0].Timestamp
988 }
989 }
990
991 txMsg, err := common.Encode(&entries)
992 if err != nil {
993 return err
994 }
995 e.logger.Debug("publish.before", "gno", gno, "n", len(entries.Entries))
996 if err = e.publish(fmt.Sprintf("%s_incr_hete", e.subject), txMsg, gno); err != nil {
997 return err
998 }
999
1000 for _, entry := range entries.Entries {
1001 atomic.AddInt64(e.memory2, -int64(entry.Size()))
1002 }
1003 e.logger.Debug("publish.after", "gno", gno, "n", len(entries.Entries))
1004 entries.Entries = nil
1005 entriesSize = 0
1006
1007 return nil
1008 }
1009
1010 groupTimeoutDuration := time.Duration(e.mysqlContext.GroupTimeout) * time.Millisecond
1011 timer := time.NewTimer(groupTimeoutDuration)
1012 defer timer.Stop()
1013
1014 LOOP:
1015 for !e.shutdown {
1016 select {
1017 case entryCtx := <-e.dataChannel:
1018 binlogEntry := entryCtx.Entry
1019 atomic.AddUint64(&e.extractorQueryCount, uint64(len(binlogEntry.Events)))
1020 entries.Entries = append(entries.Entries, binlogEntry)
1021 entriesSize += entryCtx.OriginalSize
1022
1023 if entriesSize >= e.mysqlContext.GroupMaxSize {
1024 e.logger.Debug("incr. send by GroupLimit",
1025 "entriesSize", entriesSize,
1026 "groupMaxSize", e.mysqlContext.GroupMaxSize,
1027 "Entries.len", len(entries.Entries))
1028
1029 e.sendBySizeFullCounter += 1

Callers 1

initiateStreamingMethod · 0.95

Calls 7

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

Tested by

no test coverage detected