Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

config: fix binlog-gtid verify (#983) #987

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _utils/terror_gen/errors_release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ErrConfigOnlineSchemeNotSupport,[code=20007:class=config:scope=internal:level=me
ErrConfigInvalidTimezone,[code=20008:class=config:scope=internal:level=medium], "Message: invalid timezone string: %s, Workaround: Please check the `timezone` config in task configuration file."
ErrConfigParseFlagSet,[code=20009:class=config:scope=internal:level=medium], "Message: parse subtask config flag set"
ErrConfigDecryptDBPassword,[code=20010:class=config:scope=internal:level=medium], "Message: decrypt DB password %s failed"
ErrConfigMetaNoBinlogName,[code=20011:class=config:scope=internal:level=medium], "Message: binlog-name must specify, Workaround: Please check the `meta` config in task configuration file."
ErrConfigMetaInvalid,[code=20011:class=config:scope=internal:level=medium], "Message: must specify `binlog-name` without GTID enabled for the source or specify `binlog-gtid` with GTID enabled for the source, Workaround: Please check the `meta` config in task configuration file."
ErrConfigMySQLInstNotFound,[code=20012:class=config:scope=internal:level=medium], "Message: mysql instance config must specify, Workaround: Please check the `mysql-instances` config in task configuration file."
ErrConfigMySQLInstsAtLeastOne,[code=20013:class=config:scope=internal:level=medium], "Message: must specify at least one mysql-instances, Workaround: Please check the `mysql-instances` config in task configuration file."
ErrConfigMySQLInstSameSourceID,[code=20014:class=config:scope=internal:level=medium], "Message: mysql-instance (%d) and (%d) have same source-id (%s), Workaround: Please check the `mysql-instances` config in task configuration file."
Expand Down
5 changes: 3 additions & 2 deletions dm/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ type Meta struct {
}

// Verify does verification on configs
// NOTE: we can't decide to verify `binlog-name` or `binlog-gtid` until bound to a source (with `enable-gtid` set).
func (m *Meta) Verify() error {
if m != nil && len(m.BinLogName) == 0 {
return terror.ErrConfigMetaNoBinlogName.Generate()
if m != nil && len(m.BinLogName) == 0 && len(m.BinLogGTID) == 0 {
return terror.ErrConfigMetaInvalid.Generate()
}

return nil
Expand Down
35 changes: 35 additions & 0 deletions dm/config/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,38 @@ func (t *testConfig) TestFromSubTaskConfigs(c *C) {

c.Assert(cfg.String(), Equals, cfg2.String()) // some nil/(null value) compare may not equal, so use YAML format to compare.
}

func (t *testConfig) TestMetaVerify(c *C) {
var m *Meta
c.Assert(m.Verify(), IsNil) // nil meta is fine (for not incremental task mode)

// none
m = &Meta{}
c.Assert(terror.ErrConfigMetaInvalid.Equal(m.Verify()), IsTrue)

// only `binlog-name`.
m = &Meta{
BinLogName: "mysql-bin.000123",
}
c.Assert(m.Verify(), IsNil)

// only `binlog-pos`.
m = &Meta{
BinLogPos: 456,
}
c.Assert(terror.ErrConfigMetaInvalid.Equal(m.Verify()), IsTrue)

// only `binlog-gtid`.
m = &Meta{
BinLogGTID: "1-1-12,4-4-4",
}
c.Assert(m.Verify(), IsNil)

// all
m = &Meta{
BinLogName: "mysql-bin.000123",
BinLogPos: 456,
BinLogGTID: "1-1-12,4-4-4",
}
c.Assert(m.Verify(), IsNil)
}
2 changes: 1 addition & 1 deletion errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ workaround = ""
tags = ["internal", "medium"]

[error.DM-config-20011]
message = "binlog-name must specify"
message = "must specify `binlog-name` without GTID enabled for the source or specify `binlog-gtid` with GTID enabled for the source"
description = ""
workaround = "Please check the `meta` config in task configuration file."
tags = ["internal", "medium"]
Expand Down
4 changes: 2 additions & 2 deletions pkg/terror/error_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const (
codeConfigInvalidTimezone
codeConfigParseFlagSet
codeConfigDecryptDBPassword
codeConfigMetaNoBinlogName
codeConfigMetaInvalid
codeConfigMySQLInstNotFound
codeConfigMySQLInstsAtLeastOne
codeConfigMySQLInstSameSourceID
Expand Down Expand Up @@ -765,7 +765,7 @@ var (
ErrConfigInvalidTimezone = New(codeConfigInvalidTimezone, ClassConfig, ScopeInternal, LevelMedium, "invalid timezone string: %s", "Please check the `timezone` config in task configuration file.")
ErrConfigParseFlagSet = New(codeConfigParseFlagSet, ClassConfig, ScopeInternal, LevelMedium, "parse subtask config flag set", "")
ErrConfigDecryptDBPassword = New(codeConfigDecryptDBPassword, ClassConfig, ScopeInternal, LevelMedium, "decrypt DB password %s failed", "")
ErrConfigMetaNoBinlogName = New(codeConfigMetaNoBinlogName, ClassConfig, ScopeInternal, LevelMedium, "binlog-name must specify", "Please check the `meta` config in task configuration file.")
ErrConfigMetaInvalid = New(codeConfigMetaInvalid, ClassConfig, ScopeInternal, LevelMedium, "must specify `binlog-name` without GTID enabled for the source or specify `binlog-gtid` with GTID enabled for the source", "Please check the `meta` config in task configuration file.")
ErrConfigMySQLInstNotFound = New(codeConfigMySQLInstNotFound, ClassConfig, ScopeInternal, LevelMedium, "mysql instance config must specify", "Please check the `mysql-instances` config in task configuration file.")
ErrConfigMySQLInstsAtLeastOne = New(codeConfigMySQLInstsAtLeastOne, ClassConfig, ScopeInternal, LevelMedium, "must specify at least one mysql-instances", "Please check the `mysql-instances` config in task configuration file.")
ErrConfigMySQLInstSameSourceID = New(codeConfigMySQLInstSameSourceID, ClassConfig, ScopeInternal, LevelMedium, "mysql-instance (%d) and (%d) have same source-id (%s)", "Please check the `mysql-instances` config in task configuration file.")
Expand Down