Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.
Open
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
12 changes: 9 additions & 3 deletions dm/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ func (c *TaskConfig) adjust() error {
}
globalConfigReferCount[configRefPrefixes[mydumperIdx]+inst.MydumperConfigName]++
inst.Mydumper = new(MydumperConfig)
*inst.Mydumper = *rule // ref mydumper config
if rule != nil {
*inst.Mydumper = *rule // ref mydumper config
}
}
if inst.Mydumper == nil {
if len(c.Mydumpers) != 0 {
Expand Down Expand Up @@ -587,7 +589,9 @@ func (c *TaskConfig) adjust() error {
}
globalConfigReferCount[configRefPrefixes[loaderIdx]+inst.LoaderConfigName]++
inst.Loader = new(LoaderConfig)
*inst.Loader = *rule // ref loader config
if rule != nil {
*inst.Loader = *rule // ref loader config
}
}
if inst.Loader == nil {
if len(c.Loaders) != 0 {
Expand All @@ -607,7 +611,9 @@ func (c *TaskConfig) adjust() error {
}
globalConfigReferCount[configRefPrefixes[syncerIdx]+inst.SyncerConfigName]++
inst.Syncer = new(SyncerConfig)
*inst.Syncer = *rule // ref syncer config
if rule != nil {
*inst.Syncer = *rule // ref syncer config
}
}
if inst.Syncer == nil {
if len(c.Syncers) != 0 {
Expand Down
53 changes: 49 additions & 4 deletions dm/config/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,62 @@ mysql-instances:
loader-config-name: "global"
syncer-config-name: "global"
`
taskConfig := NewTaskConfig()
err := taskConfig.Decode(errorTaskConfig1)
errorTaskConfig3 := `---
name: test
task-mode: all

target-database:
host: "127.0.0.1"
port: 4000
user: "root"
password: ""

mysql-instances:
- source-id: "mysql-replica-01"
mydumper-config-name: "global"

mydumpers:
global:
`

dontPanicTaskConfig := `---
name: test
task-mode: all

target-database:
host: "127.0.0.1"
port: 4000
user: "root"
password: ""

mysql-instances:
- source-id: "mysql-replica-01"
syncer-config-name: "global1"
loader-config-name: "global2"

loaders:
global2:

syncers:
global1:
`
err := NewTaskConfig().Decode(errorTaskConfig1)
// field server-id is not a member of TaskConfig
c.Check(err, NotNil)
c.Assert(err, ErrorMatches, "*line 18: field server-id not found in type config.MySQLInstance.*")

err = taskConfig.Decode(errorTaskConfig2)
err = NewTaskConfig().Decode(errorTaskConfig2)
// field name duplicate
c.Check(err, NotNil)
c.Assert(err, ErrorMatches, "*line 3: field name already set in type config.TaskConfig.*")

err = NewTaskConfig().Decode(errorTaskConfig3)
c.Check(err, NotNil)
c.Assert(err, ErrorMatches, "*Please check the `mydumper-path` config in task configuration file.*")

err = NewTaskConfig().Decode(dontPanicTaskConfig)
c.Check(err, IsNil)

filepath := path.Join(c.MkDir(), "test_invalid_task.yaml")
configContent := []byte(`---
aaa: xxx
Expand All @@ -325,7 +370,7 @@ ignore-checking-items: ["all"]
`)
err = os.WriteFile(filepath, configContent, 0o644)
c.Assert(err, IsNil)
taskConfig = NewTaskConfig()
taskConfig := NewTaskConfig()
err = taskConfig.DecodeFile(filepath)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*line 2: field aaa not found in type config.TaskConfig.*")
Expand Down
8 changes: 8 additions & 0 deletions tests/gtid/conf/dm-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ mysql-instances:

- source-id: "mysql-replica-02"
block-allow-list: "instance"
syncer-config-name: "global1"
loader-config-name: "global2"

loaders:
global2:

syncers:
global1:

black-white-list: # compatible with deprecated config
instance:
Expand Down