From ba7d58319ca98b8283920a535f4cac8136820fcd Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Fri, 28 Aug 2020 15:12:56 +0800 Subject: [PATCH 1/2] check whether GTID is `ON` in the upstream ealier --- _utils/terror_gen/errors_release.txt | 1 + dm/config/source_config.go | 15 +++++++++++++++ dm/master/server.go | 4 ++++ errors.toml | 6 ++++++ pkg/terror/error_list.go | 2 ++ pkg/terror/terror.go | 2 ++ pkg/utils/db.go | 6 ++++++ 7 files changed, 36 insertions(+) diff --git a/_utils/terror_gen/errors_release.txt b/_utils/terror_gen/errors_release.txt index 17816584dc..100348a462 100644 --- a/_utils/terror_gen/errors_release.txt +++ b/_utils/terror_gen/errors_release.txt @@ -173,6 +173,7 @@ ErrTaskCheckGenTableRouter,[code=26003:class=task-check:scope=internal:level=med ErrTaskCheckGenColumnMapping,[code=26004:class=task-check:scope=internal:level=medium], "Message: generate column mapping error, Workaround: Please check the `column-mappings` config in task configuration file." ErrTaskCheckSyncConfigError,[code=26005:class=task-check:scope=internal:level=medium], "Message: %s: %v\n detail: %v" ErrTaskCheckGenBAList,[code=26006:class=task-check:scope=internal:level=medium], "Message: generate block allow list error, Workaround: Please check the `block-allow-list` config in task configuration file." +ErrSourceCheckGTID,[code=26007:class=task-check:scope=internal:level=medium], "Message: %s has GTID_MODE = %s instead of ON, Workaround: Please check the `enable-gtid` config in source configuration file." ErrRelayParseUUIDIndex,[code=28001:class=relay-event-lib:scope=internal:level=high], "Message: parse server-uuid.index" ErrRelayParseUUIDSuffix,[code=28002:class=relay-event-lib:scope=internal:level=high], "Message: UUID (with suffix) %s not valid" ErrRelayUUIDWithSuffixNotFound,[code=28003:class=relay-event-lib:scope=internal:level=high], "Message: no UUID (with suffix) matched %s found in %s, all UUIDs are %v" diff --git a/dm/config/source_config.go b/dm/config/source_config.go index 920cd11e79..d6e0e1e1b6 100644 --- a/dm/config/source_config.go +++ b/dm/config/source_config.go @@ -318,3 +318,18 @@ func (c *SourceConfig) check(metaData *toml.MetaData, err error) error { c.adjust() return nil } + +// PreCheck check valify source config +func (c *SourceConfig) PreCheck(db *sql.DB) error { + if c.EnableGTID { + val, err := utils.GetGTID(db) + if err != nil { + return err + } + if val != "ON" { + return terror.ErrSourceCheckGTID.Generate(c.SourceID, val) + } + } + + return nil +} diff --git a/dm/master/server.go b/dm/master/server.go index e607b8ffdf..195d56db9f 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -1351,6 +1351,10 @@ func parseAndAdjustSourceConfig(contents []string) ([]*config.SourceConfig, erro if _, err = cfg.Yaml(); err != nil { return cfgs, err } + if err = cfg.PreCheck(fromDB.DB); err != nil { + return cfgs, err + } + cfgs[i] = cfg } return cfgs, nil diff --git a/errors.toml b/errors.toml index a6caf2c5c7..df5ec4a472 100644 --- a/errors.toml +++ b/errors.toml @@ -1048,6 +1048,12 @@ description = "" workaround = "Please check the `block-allow-list` config in task configuration file." tags = ["internal", "medium"] +[error.DM-task-check-26007] +message = "%s has GTID_MODE = %s instead of ON" +description = "" +workaround = "Please check the `enable-gtid` config in source configuration file." +tags = ["internal", "medium"] + [error.DM-relay-event-lib-28001] message = "parse server-uuid.index" description = "" diff --git a/pkg/terror/error_list.go b/pkg/terror/error_list.go index a3ce57a9c3..25c2f22d5e 100644 --- a/pkg/terror/error_list.go +++ b/pkg/terror/error_list.go @@ -238,6 +238,7 @@ const ( codeTaskCheckGenColumnMapping codeTaskCheckSyncConfigError codeTaskCheckGenBAList + codeSourceCheckGTID ) // Relay log utils error code @@ -811,6 +812,7 @@ var ( ErrTaskCheckGenColumnMapping = New(codeTaskCheckGenColumnMapping, ClassTaskCheck, ScopeInternal, LevelMedium, "generate column mapping error", "Please check the `column-mappings` config in task configuration file.") ErrTaskCheckSyncConfigError = New(codeTaskCheckSyncConfigError, ClassTaskCheck, ScopeInternal, LevelMedium, "%s: %v\n detail: %v", "") ErrTaskCheckGenBAList = New(codeTaskCheckGenBAList, ClassTaskCheck, ScopeInternal, LevelMedium, "generate block allow list error", "Please check the `block-allow-list` config in task configuration file.") + ErrSourceCheckGTID = New(codeSourceCheckGTID, ClassTaskCheck, ScopeInternal, LevelMedium, "%s has GTID_MODE = %s instead of ON", "Please check the `enable-gtid` config in source configuration file.") // Relay log basic API error ErrRelayParseUUIDIndex = New(codeRelayParseUUIDIndex, ClassRelayEventLib, ScopeInternal, LevelHigh, "parse server-uuid.index", "") diff --git a/pkg/terror/terror.go b/pkg/terror/terror.go index 42419c556f..b5a96c3815 100644 --- a/pkg/terror/terror.go +++ b/pkg/terror/terror.go @@ -38,6 +38,7 @@ const ( ClassBinlogOp ClassCheckpoint ClassTaskCheck + ClassSourceCheck ClassRelayEventLib ClassRelayUnit ClassDumpUnit @@ -59,6 +60,7 @@ var errClass2Str = map[ErrClass]string{ ClassBinlogOp: "binlog-op", ClassCheckpoint: "checkpoint", ClassTaskCheck: "task-check", + ClassSourceCheck: "source-check", ClassRelayEventLib: "relay-event-lib", ClassRelayUnit: "relay-unit", ClassDumpUnit: "dump-unit", diff --git a/pkg/utils/db.go b/pkg/utils/db.go index 8d43994380..1389bbeced 100644 --- a/pkg/utils/db.go +++ b/pkg/utils/db.go @@ -403,3 +403,9 @@ func IsErrBinlogPurged(err error) bool { func IsNoSuchThreadError(err error) bool { return IsMySQLError(err, tmysql.ErrNoSuchThread) } + +// GetGTID return GTID_MODE +func GetGTID(db *sql.DB) (string, error) { + val, err := GetGlobalVariable(db, "GTID_MODE") + return val, err +} From c25b8136694ed91222859dde3a41ce22157cf283 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Fri, 28 Aug 2020 22:20:13 +0800 Subject: [PATCH 2/2] address comment --- dm/config/source_config.go | 25 ++++++++++--------------- dm/master/server.go | 3 --- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/dm/config/source_config.go b/dm/config/source_config.go index d6e0e1e1b6..141780864f 100644 --- a/dm/config/source_config.go +++ b/dm/config/source_config.go @@ -241,6 +241,16 @@ func (c *SourceConfig) Adjust(db *sql.DB) (err error) { } } + if c.EnableGTID { + val, err := utils.GetGTID(db) + if err != nil { + return err + } + if val != "ON" { + return terror.ErrSourceCheckGTID.Generate(c.SourceID, val) + } + } + return nil } @@ -318,18 +328,3 @@ func (c *SourceConfig) check(metaData *toml.MetaData, err error) error { c.adjust() return nil } - -// PreCheck check valify source config -func (c *SourceConfig) PreCheck(db *sql.DB) error { - if c.EnableGTID { - val, err := utils.GetGTID(db) - if err != nil { - return err - } - if val != "ON" { - return terror.ErrSourceCheckGTID.Generate(c.SourceID, val) - } - } - - return nil -} diff --git a/dm/master/server.go b/dm/master/server.go index 195d56db9f..fab9b2fede 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -1351,9 +1351,6 @@ func parseAndAdjustSourceConfig(contents []string) ([]*config.SourceConfig, erro if _, err = cfg.Yaml(); err != nil { return cfgs, err } - if err = cfg.PreCheck(fromDB.DB); err != nil { - return cfgs, err - } cfgs[i] = cfg }