github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/pkg/binlog/common/replication.go (about)

     1  // Copyright 2019 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package common
    15  
    16  import (
    17  	"time"
    18  
    19  	"github.com/go-mysql-org/go-mysql/replication"
    20  )
    21  
    22  var (
    23  	// MaxBinlogSyncerReconnect is the max reconnection times for binlog syncer in go-mysql.
    24  	MaxBinlogSyncerReconnect = 60
    25  	// SlaveReadTimeout is slave read binlog data timeout, ref: https://dev.mysql.com/doc/refman/8.0/en/replication-options-replica.html#sysvar_slave_net_timeout
    26  	SlaveReadTimeout = 1 * time.Minute
    27  	// MasterHeartbeatPeriod is the master server send heartbeat period, ref: `MASTER_HEARTBEAT_PERIOD` in https://dev.mysql.com/doc/refman/8.0/en/change-master-to.html
    28  	MasterHeartbeatPeriod = 30 * time.Second
    29  )
    30  
    31  // SetDefaultReplicationCfg sets some default value for BinlogSyncerConfig
    32  // Note: retryCount should be greater than 0, set retryCount = 1 if you want to disable retry sync.
    33  func SetDefaultReplicationCfg(cfg *replication.BinlogSyncerConfig, retryCount int) {
    34  	// after https://github.com/go-mysql-org/go-mysql/pull/598 we could use `false` to improve performance without
    35  	// losing precision.
    36  	cfg.UseDecimal = false
    37  	cfg.VerifyChecksum = true
    38  	cfg.MaxReconnectAttempts = retryCount
    39  	if retryCount == 1 {
    40  		cfg.DisableRetrySync = true
    41  	}
    42  	cfg.ReadTimeout = SlaveReadTimeout
    43  	cfg.HeartbeatPeriod = MasterHeartbeatPeriod
    44  }