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

Method ConnectBinlogStreamer

driver/mysql/binlog/binlog_reader.go:282–414  ·  view source on GitHub ↗
(coordinates common.MySQLCoordinates)

Source from the content-addressed store, hash-verified

280}
281
282func (b *BinlogReader) ConnectBinlogStreamer(coordinates common.MySQLCoordinates) (err error) {
283 if coordinates.IsEmpty() {
284 b.logger.Warn("Emptry coordinates at ConnectBinlogStreamer")
285 }
286
287 b.currentCoord = coordinates
288 b.logger.Info("Connecting binlog streamer",
289 "file", coordinates.LogFile, "pos", coordinates.LogPos, "gtid", coordinates.GtidSet)
290
291 if b.mysqlContext.BinlogRelay {
292 dbConfig := dmconfig.DBConfig{
293 Host: b.mysqlContext.SrcConnectionConfig.Host,
294 Port: b.mysqlContext.SrcConnectionConfig.Port,
295 User: b.mysqlContext.SrcConnectionConfig.User,
296 Password: b.mysqlContext.SrcConnectionConfig.Password,
297 }
298
299 relayConfig := &dmrelay.Config{
300 EnableGTID: true,
301 RelayDir: b.getBinlogDir(),
302 ServerID: uint32(b.serverId),
303 Flavor: "mysql",
304 From: dbConfig,
305 BinLogName: "",
306 BinlogGTID: coordinates.GtidSet,
307 ReaderRetry: dmretry.ReaderRetryConfig{
308 // value from dm/relay/relay_test.go
309 BackoffRollback: 200 * time.Millisecond,
310 BackoffMax: 1 * time.Second,
311 BackoffMin: 1 * time.Millisecond,
312 BackoffJitter: true,
313 BackoffFactor: 2,
314 },
315 }
316 b.relay = dmrelay.NewRelay(relayConfig)
317 err = b.relay.Init(b.ctx)
318 if err != nil {
319 return err
320 }
321
322 var ctx context.Context
323 ctx, b.relayCancelF = context.WithCancel(b.ctx)
324
325 {
326 brConfig := &dmstreamer.BinlogReaderConfig{
327 RelayDir: b.getBinlogDir(),
328 Timezone: time.UTC,
329 }
330 b.binlogReader = dmstreamer.NewBinlogReader(dmlog.L(), brConfig)
331 }
332
333 go func() {
334 b.logger.Info("starting BinlogRelay", "gtidSet", coordinates.GtidSet)
335 pr := b.relay.Process(ctx)
336 b.logger.Warn("relay.Process stopped", "isCancelled", pr.IsCanceled, "deail", string(pr.Detail))
337 for _, prErr := range pr.Errors {
338 b.logger.Error("relay.Process error", "err", prErr)
339 }

Callers 1

initBinlogReaderMethod · 0.95

Calls 3

getBinlogDirMethod · 0.95
IsEmptyMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected