github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/relay/config.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 relay 15 16 import ( 17 "encoding/json" 18 19 "github.com/pingcap/tiflow/dm/config" 20 "github.com/pingcap/tiflow/dm/config/dbconfig" 21 "github.com/pingcap/tiflow/dm/pkg/log" 22 ) 23 24 // Config is the configuration for Relay. 25 type Config struct { 26 EnableGTID bool `toml:"enable-gtid" json:"enable-gtid"` 27 // deprecated 28 AutoFixGTID bool `toml:"auto-fix-gtid" json:"auto-fix-gtid"` 29 RelayDir string `toml:"relay-dir" json:"relay-dir"` 30 ServerID uint32 `toml:"server-id" json:"server-id"` 31 Flavor string `toml:"flavor" json:"flavor"` 32 Charset string `toml:"charset" json:"charset"` 33 From dbconfig.DBConfig `toml:"data-source" json:"data-source"` 34 35 // synchronous start point (if no meta saved before) 36 // do not need to specify binlog-pos, because relay will fetch the whole file 37 BinLogName string `toml:"binlog-name" json:"binlog-name"` 38 BinlogGTID string `toml:"binlog-gtid" json:"binlog-gtid"` 39 UUIDSuffix int `toml:"-" json:"-"` 40 41 // for binlog reader retry 42 ReaderRetry ReaderRetryConfig `toml:"reader-retry" json:"reader-retry"` 43 } 44 45 func (c *Config) String() string { 46 cfg, err := json.Marshal(c) 47 if err != nil { 48 log.L().Error("fail to marshal relay config to json", log.ShortError(err)) 49 } 50 return string(cfg) 51 } 52 53 // FromSourceCfg gen relay config from source config. 54 func FromSourceCfg(sourceCfg *config.SourceConfig) *Config { 55 clone := sourceCfg.GetDecryptedClone() 56 cfg := &Config{ 57 EnableGTID: clone.EnableGTID, 58 Flavor: clone.Flavor, 59 RelayDir: clone.RelayDir, 60 ServerID: clone.ServerID, 61 Charset: clone.Charset, 62 From: clone.From, 63 BinLogName: clone.RelayBinLogName, 64 BinlogGTID: clone.RelayBinlogGTID, 65 UUIDSuffix: clone.UUIDSuffix, 66 ReaderRetry: ReaderRetryConfig{ // we use config from TaskChecker now 67 BackoffRollback: clone.Checker.BackoffRollback.Duration, 68 BackoffMax: clone.Checker.BackoffMax.Duration, 69 BackoffMin: clone.Checker.BackoffMin.Duration, 70 BackoffJitter: clone.Checker.BackoffJitter, 71 BackoffFactor: clone.Checker.BackoffFactor, 72 }, 73 } 74 return cfg 75 }