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

source: check whether GTID is ON in the upstream ealier #946

Merged
merged 3 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions _utils/terror_gen/errors_release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions dm/config/source_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust could check and return error, so maybe we could put these code into Adjust?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. seems we have use *sql.DB in Adjust now.

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
}
4 changes: 4 additions & 0 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
2 changes: 2 additions & 0 deletions pkg/terror/error_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const (
codeTaskCheckGenColumnMapping
codeTaskCheckSyncConfigError
codeTaskCheckGenBAList
codeSourceCheckGTID
)

// Relay log utils error code
Expand Down Expand Up @@ -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", "")
Expand Down
2 changes: 2 additions & 0 deletions pkg/terror/terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
ClassBinlogOp
ClassCheckpoint
ClassTaskCheck
ClassSourceCheck
ClassRelayEventLib
ClassRelayUnit
ClassDumpUnit
Expand All @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}