diff --git a/canal/config.go b/canal/config.go index 29c58f66b..99694b801 100644 --- a/canal/config.go +++ b/canal/config.go @@ -8,11 +8,12 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/go-mysql-org/go-mysql/client" - "github.com/go-mysql-org/go-mysql/mysql" "github.com/pingcap/errors" "github.com/siddontang/go-log/log" "github.com/siddontang/go-log/loggers" + + "github.com/go-mysql-org/go-mysql/client" + "github.com/go-mysql-org/go-mysql/mysql" ) type DumpConfig struct { @@ -91,13 +92,13 @@ type Config struct { // Set TLS config TLSConfig *tls.Config - //Set Logger + // Set Logger Logger loggers.Advanced - //Set Dialer + // Set Dialer Dialer client.Dialer - //Set Localhost + // Set Localhost Localhost string } @@ -121,19 +122,18 @@ func NewConfig(data string) (*Config, error) { return &c, nil } +// NewDefaultConfig initiates some default config for Canal func NewDefaultConfig() *Config { c := new(Config) - c.Addr = "127.0.0.1:3306" - c.User = "root" - c.Password = "" - + c.Addr = mysql.DEFAULT_ADDR + c.User = mysql.DEFAULT_USER + c.Password = mysql.DEFAULT_PASSWORD c.Charset = mysql.DEFAULT_CHARSET c.ServerID = uint32(rand.New(rand.NewSource(time.Now().Unix())).Intn(1000)) + 1001 + c.Flavor = mysql.DEFAULT_FLAVOR - c.Flavor = "mysql" - - c.Dump.ExecutionPath = "mysqldump" + c.Dump.ExecutionPath = mysql.DEFAULT_DUMP_EXECUTION_PATH c.Dump.DiscardErr = true c.Dump.SkipMasterData = false diff --git a/mysql/const.go b/mysql/const.go index 34661294a..0cb7fc704 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -170,11 +170,19 @@ const ( ) const ( + DEFAULT_ADDR = "127.0.0.1:3306" + DEFAULT_USER = "root" + DEFAULT_PASSWORD = "" + DEFAULT_FLAVOR = "mysql" DEFAULT_CHARSET = "utf8" DEFAULT_COLLATION_ID uint8 = 33 DEFAULT_COLLATION_NAME string = "utf8_general_ci" ) +const ( + DEFAULT_DUMP_EXECUTION_PATH = "mysqldump" +) + // Like vitess, use flavor for different MySQL versions, const ( MySQLFlavor = "mysql" diff --git a/mysql/position.go b/mysql/position.go index c592d6363..09bd95f70 100644 --- a/mysql/position.go +++ b/mysql/position.go @@ -6,12 +6,14 @@ import ( "strings" ) -// For binlog filename + position based replication +// Position for binlog filename + position based replication type Position struct { Name string Pos uint32 } +// Compare the position information between the p and o, +// if p > o return 1 means the position of p is further back than o. func (p Position) Compare(o Position) int { // First compare binlog name nameCmp := CompareBinlogFileName(p.Name, o.Name) @@ -32,6 +34,9 @@ func (p Position) String() string { return fmt.Sprintf("(%s, %d)", p.Name, p.Pos) } +// CompareBinlogFileName compares the binlog filename of a and b. +// if a>b will return 1. +// if b>a will return -1. func CompareBinlogFileName(a, b string) int { // sometimes it's convenient to construct a `Position` literal with no `Name` if a == "" && b == "" { @@ -61,9 +66,11 @@ func CompareBinlogFileName(a, b string) int { return n[:i], seq } + // get the basename(aBase) and the serial number(aSeq) aBase, aSeq := splitBinlogName(a) bBase, bSeq := splitBinlogName(b) + // aBase and bBase generally will be equal if they are both from the same database configuration. if aBase > bBase { return 1 } else if aBase < bBase {