From 99df0e47d9b9dac0c9a5bdcffdaa5201fa89e4f8 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Wed, 20 Oct 2021 17:26:03 +0800 Subject: [PATCH] save work --- dm/config/task.go | 12 ++++++-- dm/config/task_test.go | 53 +++++++++++++++++++++++++++++++++--- tests/gtid/conf/dm-task.yaml | 8 ++++++ 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/dm/config/task.go b/dm/config/task.go index 496e08161b..5e5368aacb 100644 --- a/dm/config/task.go +++ b/dm/config/task.go @@ -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 { @@ -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 { @@ -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 { diff --git a/dm/config/task_test.go b/dm/config/task_test.go index fbf67b5fdf..db1e98a21d 100644 --- a/dm/config/task_test.go +++ b/dm/config/task_test.go @@ -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 @@ -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.*") diff --git a/tests/gtid/conf/dm-task.yaml b/tests/gtid/conf/dm-task.yaml index 8e96b67f10..4da1f0c547 100644 --- a/tests/gtid/conf/dm-task.yaml +++ b/tests/gtid/conf/dm-task.yaml @@ -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: