From 1fbfd2f0aea82cfa8bd03ed71367341e6048fa22 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Thu, 25 Nov 2021 11:58:34 +0800 Subject: [PATCH 01/13] save work --- dm/_utils/terror_gen/errors_release.txt | 1 + dm/dm/common/common.go | 6 +- dm/dm/common/common_test.go | 5 + dm/errors.toml | 6 ++ dm/openapi/task.go | 12 +++ dm/pkg/ha/task_config_template.go | 117 ++++++++++++++++++++++++ dm/pkg/ha/task_config_template_test.go | 78 ++++++++++++++++ dm/pkg/terror/error_list.go | 2 + 8 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 dm/pkg/ha/task_config_template.go create mode 100644 dm/pkg/ha/task_config_template_test.go diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index c81497876da..293bdb339c5 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -179,6 +179,7 @@ ErrConfigGenColumnMapping,[code=20046:class=config:scope=internal:level=high], " ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high], "Message: invalid `chunk-filesize` %v, Workaround: Please check the `chunk-filesize` config in task configuration file." ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." +ErrTaskConfigTemplateExists,[code=20050:class=config:scope=internal:level=low], "Message: the task config template for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" ErrBinlogParsePosFromStr,[code=22003:class=binlog-op:scope=internal:level=high] diff --git a/dm/dm/common/common.go b/dm/dm/common/common.go index f55d5aee8e8..fa5b8387180 100644 --- a/dm/dm/common/common.go +++ b/dm/dm/common/common.go @@ -88,13 +88,17 @@ var ( // tb2: +a +b +c // tb3: +a +b +c ShardDDLOptimismDroppedColumnsKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/shardddl-optimism/dropped-columns/") + + // TaskConfigTemplateKeyAdapter is used to store the config of the task config template, now it's only used for WebUI. + // k/v: Encode(task-name) -> openapi.Task. + TaskConfigTemplateKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/task-config-template/") ) func keyAdapterKeysLen(s KeyAdapter) int { switch s { case WorkerRegisterKeyAdapter, UpstreamConfigKeyAdapter, UpstreamBoundWorkerKeyAdapter, WorkerKeepAliveKeyAdapter, StageRelayKeyAdapter, - UpstreamLastBoundWorkerKeyAdapter, UpstreamRelayWorkerKeyAdapter: + UpstreamLastBoundWorkerKeyAdapter, UpstreamRelayWorkerKeyAdapter, TaskConfigTemplateKeyAdapter: return 1 case UpstreamSubTaskKeyAdapter, StageSubTaskKeyAdapter, ShardDDLPessimismInfoKeyAdapter, ShardDDLPessimismOperationKeyAdapter, diff --git a/dm/dm/common/common_test.go b/dm/dm/common/common_test.go index 9624a3faaa7..ef1f1574095 100644 --- a/dm/dm/common/common_test.go +++ b/dm/dm/common/common_test.go @@ -81,6 +81,11 @@ func (t *testCommon) TestKeyAdapter(c *C) { adapter: UpstreamSubTaskKeyAdapter, want: "/dm-master/upstream/subtask/6d7973716c31/e4b8ade6968731f09f8084efb88f", }, + { + keys: []string{"task-1"}, + adapter: TaskConfigTemplateKeyAdapter, + want: "/dm-master/task-config-template/7461736b2d31", + }, } for _, ca := range testCases { diff --git a/dm/errors.toml b/dm/errors.toml index 9fd7af01ece..1e94e132f01 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1084,6 +1084,12 @@ description = "" workaround = "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." tags = ["internal", "high"] +[error.DM-config-20050] +message = "the task config template for '%s' already exists" +description = "" +workaround = "If you want to override it, pleaset use the overwite flag." +tags = ["internal", "low"] + [error.DM-binlog-op-22001] message = "" description = "" diff --git a/dm/openapi/task.go b/dm/openapi/task.go index 4b1b0963d0f..3179dd87b17 100644 --- a/dm/openapi/task.go +++ b/dm/openapi/task.go @@ -14,6 +14,8 @@ package openapi import ( + "encoding/json" + "github.com/pingcap/ticdc/dm/pkg/terror" ) @@ -30,3 +32,13 @@ func (t *Task) Adjust() error { } return nil } + +// FromJSON unmarshal json to task. +func (t *Task) FromJSON(data []byte) error { + return json.Unmarshal(data, t) +} + +// ToJSON marshal json to task. +func (t *Task) ToJSON() ([]byte, error) { + return json.Marshal(t) +} diff --git a/dm/pkg/ha/task_config_template.go b/dm/pkg/ha/task_config_template.go new file mode 100644 index 00000000000..8b14268023a --- /dev/null +++ b/dm/pkg/ha/task_config_template.go @@ -0,0 +1,117 @@ +// Copyright 2021 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package ha + +import ( + "context" + + "go.etcd.io/etcd/clientv3" + "go.etcd.io/etcd/clientv3/clientv3util" + + "github.com/pingcap/ticdc/dm/dm/common" + "github.com/pingcap/ticdc/dm/openapi" + "github.com/pingcap/ticdc/dm/pkg/etcdutil" + "github.com/pingcap/ticdc/dm/pkg/terror" +) + +func openAPITaskFromResp(resp *clientv3.GetResponse) (*openapi.Task, error) { + task := &openapi.Task{} + if resp.Count == 0 { + return nil, nil + } else if resp.Count > 1 { + // this should not happen. + return task, terror.ErrConfigMoreThanOne.Generate(resp.Count, "openapi.Task", "") + } + // we make sure only have one task config. + if err := task.FromJSON(resp.Kvs[0].Value); err != nil { + return task, err + } + return task, nil +} + +// PutTaskConfigTemplate puts the task config template of task-name. +func PutTaskConfigTemplate(cli *clientv3.Client, task openapi.Task, overWrite bool) error { + ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) + defer cancel() + + key := common.TaskConfigTemplateKeyAdapter.Encode(task.Name) + taskJSON, err := task.ToJSON() + if err != nil { + return err // it should not happen. + } + txn := cli.Txn(ctx) + if !overWrite { + txn = txn.If(clientv3util.KeyMissing(key)) + } + resp, err := txn.Then(clientv3.OpPut(key, string(taskJSON))).Commit() + if err != nil { + return err + } + // user don't want overwrite and key already exists. + if !overWrite && !resp.Succeeded { + return terror.ErrTaskConfigTemplateExists.Generate(task.Name) + } + return nil +} + +// DeleteTaskConfigTemplate deletes the task config template of task-name. +func DeleteTaskConfigTemplate(cli *clientv3.Client, taskName string) error { + ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) + defer cancel() + if _, err := cli.Delete(ctx, common.TaskConfigTemplateKeyAdapter.Encode(taskName)); err != nil { + return err + } + return nil +} + +// GetTaskConfigTemplate gets the task config template of task-name. +func GetTaskConfigTemplate(cli *clientv3.Client, taskName string) (*openapi.Task, error) { + ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) + defer cancel() + + var ( + task *openapi.Task + resp *clientv3.GetResponse + err error + ) + resp, err = cli.Get(ctx, common.TaskConfigTemplateKeyAdapter.Encode(taskName)) + if err != nil { + return task, err + } + task, err = openAPITaskFromResp(resp) + if err != nil { + return task, err + } + return task, nil +} + +// GetAllTaskConfigTemplate gets all task config templates. +func GetAllTaskConfigTemplate(cli *clientv3.Client) ([]*openapi.Task, error) { + ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) + defer cancel() + + resp, err := cli.Get(ctx, common.TaskConfigTemplateKeyAdapter.Path(), clientv3.WithPrefix()) + if err != nil { + return nil, err + } + tasks := make([]*openapi.Task, resp.Count) + for i, kv := range resp.Kvs { + t := &openapi.Task{} + if err := t.FromJSON(kv.Value); err != nil { + return nil, err + } + tasks[i] = t + } + return tasks, nil +} diff --git a/dm/pkg/ha/task_config_template_test.go b/dm/pkg/ha/task_config_template_test.go new file mode 100644 index 00000000000..0593e0d5758 --- /dev/null +++ b/dm/pkg/ha/task_config_template_test.go @@ -0,0 +1,78 @@ +// Copyright 2020 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package ha + +import ( + . "github.com/pingcap/check" + + "github.com/pingcap/ticdc/dm/openapi" + "github.com/pingcap/ticdc/dm/openapi/fixtures" + "github.com/pingcap/ticdc/dm/pkg/terror" +) + +func (t *testForEtcd) TestTaskConfigTemplateEtcd(c *C) { + defer clearTestInfoOperation(c) + + task1, err := fixtures.GenNoShardOpenAPITaskForTest() + task1.Name = "test-1" + c.Assert(err, IsNil) + task2, err := fixtures.GenShardAndFilterOpenAPITaskForTest() + task2.Name = "test-2" + c.Assert(err, IsNil) + + // no task config template exist. + task1InEtcd, err := GetTaskConfigTemplate(etcdTestCli, task1.Name) + c.Assert(err, IsNil) + c.Assert(task1InEtcd, IsNil) + + task2InEtcd, err := GetTaskConfigTemplate(etcdTestCli, task2.Name) + c.Assert(err, IsNil) + c.Assert(task2InEtcd, IsNil) + + tasks, err := GetAllTaskConfigTemplate(etcdTestCli) + c.Assert(err, IsNil) + c.Assert(tasks, HasLen, 0) + + // put task config template. + c.Assert(PutTaskConfigTemplate(etcdTestCli, task1, false), IsNil) + c.Assert(PutTaskConfigTemplate(etcdTestCli, task2, false), IsNil) + + task1InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task1.Name) + c.Assert(err, IsNil) + c.Assert(*task1InEtcd, DeepEquals, task1) + + task2InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task2.Name) + c.Assert(err, IsNil) + c.Assert(*task2InEtcd, DeepEquals, task2) + + tasks, err = GetAllTaskConfigTemplate(etcdTestCli) + c.Assert(err, IsNil) + c.Assert(tasks, HasLen, 2) + + // put task config template again without overwrite will fail + c.Assert(terror.ErrTaskConfigTemplateExists.Equal(PutTaskConfigTemplate(etcdTestCli, task1, false)), IsTrue) + + // in overwrite mode, it will overwrite the old one. + task1.TaskMode = openapi.TaskTaskModeFull + c.Assert(PutTaskConfigTemplate(etcdTestCli, task1, true), IsNil) + task1InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task1.Name) + c.Assert(err, IsNil) + c.Assert(*task1InEtcd, DeepEquals, task1) + + // delete task config + c.Assert(DeleteTaskConfigTemplate(etcdTestCli, task1.Name), IsNil) + tasks, err = GetAllTaskConfigTemplate(etcdTestCli) + c.Assert(err, IsNil) + c.Assert(tasks, HasLen, 1) +} diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index 347192f5719..349a5fdb8b5 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -244,6 +244,7 @@ const ( codeConfigInvalidChunkFileSize codeConfigOnlineDDLInvalidRegex codeConfigOnlineDDLMistakeRegex + codeConfigTaskConfigTemplateExists ) // Binlog operation error code list. @@ -893,6 +894,7 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") + ErrTaskConfigTemplateExists = New(codeConfigTaskConfigTemplateExists, ClassConfig, ScopeInternal, LevelLow, "the task config template for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") // Binlog operation error. ErrBinlogExtractPosition = New(codeBinlogExtractPosition, ClassBinlogOp, ScopeInternal, LevelHigh, "", "") From 0dbe4655cf6fd0c1ee6bd56402950db7551500ac Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Mon, 29 Nov 2021 10:12:15 +0800 Subject: [PATCH 02/13] address comment --- dm/pkg/ha/task_config_template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm/pkg/ha/task_config_template.go b/dm/pkg/ha/task_config_template.go index 8b14268023a..3cb6cb2d500 100644 --- a/dm/pkg/ha/task_config_template.go +++ b/dm/pkg/ha/task_config_template.go @@ -58,7 +58,7 @@ func PutTaskConfigTemplate(cli *clientv3.Client, task openapi.Task, overWrite bo if err != nil { return err } - // user don't want overwrite and key already exists. + // user don't want to overwrite and key already exists. if !overWrite && !resp.Succeeded { return terror.ErrTaskConfigTemplateExists.Generate(task.Name) } From df0507a4a7a611d555dec5dc29f00b956f17f7a6 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Mon, 29 Nov 2021 11:20:11 +0800 Subject: [PATCH 03/13] add PutTaskConfigTemplateIfExist --- dm/_utils/terror_gen/errors_release.txt | 1 + dm/errors.toml | 6 ++++++ dm/pkg/ha/task_config_template.go | 22 ++++++++++++++++++++++ dm/pkg/ha/task_config_template_test.go | 13 +++++++++++++ dm/pkg/terror/error_list.go | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index 293bdb339c5..dff3a114709 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -180,6 +180,7 @@ ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." ErrTaskConfigTemplateExists,[code=20050:class=config:scope=internal:level=low], "Message: the task config template for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." +ErrTaskConfigTemplateNotExists,[code=20051:class=config:scope=internal:level=low], "Message: the task config template for '%s' not exists" ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" ErrBinlogParsePosFromStr,[code=22003:class=binlog-op:scope=internal:level=high] diff --git a/dm/errors.toml b/dm/errors.toml index 1e94e132f01..076f85768f9 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1090,6 +1090,12 @@ description = "" workaround = "If you want to override it, pleaset use the overwite flag." tags = ["internal", "low"] +[error.DM-config-20051] +message = "the task config template for '%s' not exists" +description = "" +workaround = "" +tags = ["internal", "low"] + [error.DM-binlog-op-22001] message = "" description = "" diff --git a/dm/pkg/ha/task_config_template.go b/dm/pkg/ha/task_config_template.go index 3cb6cb2d500..c939dbbdb04 100644 --- a/dm/pkg/ha/task_config_template.go +++ b/dm/pkg/ha/task_config_template.go @@ -65,6 +65,28 @@ func PutTaskConfigTemplate(cli *clientv3.Client, task openapi.Task, overWrite bo return nil } +// PutTaskConfigTemplate puts the task config template of task-name. +func PutTaskConfigTemplateIfExist(cli *clientv3.Client, task openapi.Task) error { + ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) + defer cancel() + + key := common.TaskConfigTemplateKeyAdapter.Encode(task.Name) + taskJSON, err := task.ToJSON() + if err != nil { + return err // it should not happen. + } + txn := cli.Txn(ctx).If(clientv3util.KeyExists(key)).Then(clientv3.OpPut(key, string(taskJSON))) + resp, err := txn.Commit() + if err != nil { + return err + } + // user want to update a key not exists. + if !resp.Succeeded { + return terror.ErrTaskConfigTemplateNotExists.Generate(task.Name) + } + return nil +} + // DeleteTaskConfigTemplate deletes the task config template of task-name. func DeleteTaskConfigTemplate(cli *clientv3.Client, taskName string) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) diff --git a/dm/pkg/ha/task_config_template_test.go b/dm/pkg/ha/task_config_template_test.go index 0593e0d5758..74c8940bd20 100644 --- a/dm/pkg/ha/task_config_template_test.go +++ b/dm/pkg/ha/task_config_template_test.go @@ -70,6 +70,19 @@ func (t *testForEtcd) TestTaskConfigTemplateEtcd(c *C) { c.Assert(err, IsNil) c.Assert(*task1InEtcd, DeepEquals, task1) + // put task config that not exist will fail + task3, err := fixtures.GenNoShardOpenAPITaskForTest() + c.Assert(err, IsNil) + task3.Name = "test-3" + c.Assert(terror.ErrTaskConfigTemplateNotExists.Equal(PutTaskConfigTemplateIfExist(etcdTestCli, task3)), IsTrue) + + // update exist task config template will success + task1.TaskMode = openapi.TaskTaskModeAll + c.Assert(PutTaskConfigTemplateIfExist(etcdTestCli, task1), IsNil) + task1InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task1.Name) + c.Assert(err, IsNil) + c.Assert(*task1InEtcd, DeepEquals, task1) + // delete task config c.Assert(DeleteTaskConfigTemplate(etcdTestCli, task1.Name), IsNil) tasks, err = GetAllTaskConfigTemplate(etcdTestCli) diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index 349a5fdb8b5..42badf9a6e0 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -245,6 +245,7 @@ const ( codeConfigOnlineDDLInvalidRegex codeConfigOnlineDDLMistakeRegex codeConfigTaskConfigTemplateExists + codeConfigTaskConfigTemplateNotExists ) // Binlog operation error code list. @@ -894,7 +895,8 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrTaskConfigTemplateExists = New(codeConfigTaskConfigTemplateExists, ClassConfig, ScopeInternal, LevelLow, "the task config template for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") + ErrTaskConfigTemplateExists = New(codeConfigTaskConfigTemplateExists, ClassConfig, ScopeInternal, LevelLow, "the task config template for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") + ErrTaskConfigTemplateNotExists = New(codeConfigTaskConfigTemplateNotExists, ClassConfig, ScopeInternal, LevelLow, "the task config template for '%s' not exists", "") // Binlog operation error. ErrBinlogExtractPosition = New(codeBinlogExtractPosition, ClassBinlogOp, ScopeInternal, LevelHigh, "", "") From c7c86c633ed14b2ebe0f30e13e671ee234f9c383 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Mon, 29 Nov 2021 14:03:16 +0800 Subject: [PATCH 04/13] add more comments --- dm/dm/common/common.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dm/dm/common/common.go b/dm/dm/common/common.go index fa5b8387180..d94304f53eb 100644 --- a/dm/dm/common/common.go +++ b/dm/dm/common/common.go @@ -89,7 +89,9 @@ var ( // tb3: +a +b +c ShardDDLOptimismDroppedColumnsKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/shardddl-optimism/dropped-columns/") - // TaskConfigTemplateKeyAdapter is used to store the config of the task config template, now it's only used for WebUI. + // TaskConfigTemplateKeyAdapter is used to store the task config template(openapi.Task), now it's only used for WebUI. + // openapi.Task is a struct that can be converted to config.StubTaskConfig so if any field of openapi.Task updated + // user should use ha.PutTaskConfigTemplate(key, openapi.Task,overwrite) to force update the content in etcd. // k/v: Encode(task-name) -> openapi.Task. TaskConfigTemplateKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/task-config-template/") ) From c0131e6f2265b80e0aa53d09195e11f6faddd646 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Mon, 6 Dec 2021 10:10:04 +0800 Subject: [PATCH 05/13] rename to OpenAPITaskConfig --- dm/_utils/terror_gen/errors_release.txt | 4 +- dm/dm/common/common.go | 8 ++-- dm/dm/common/common_test.go | 4 +- dm/errors.toml | 4 +- ...fig_template.go => openapi_task_config.go} | 34 +++++++-------- ...te_test.go => openapi_task_config_test.go} | 42 +++++++++---------- dm/pkg/terror/error_list.go | 8 ++-- 7 files changed, 52 insertions(+), 52 deletions(-) rename dm/pkg/ha/{task_config_template.go => openapi_task_config.go} (69%) rename dm/pkg/ha/{task_config_template_test.go => openapi_task_config_test.go} (57%) diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index e0679397cd5..ba83303d4cd 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -179,8 +179,8 @@ ErrConfigGenColumnMapping,[code=20046:class=config:scope=internal:level=high], " ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high], "Message: invalid `chunk-filesize` %v, Workaround: Please check the `chunk-filesize` config in task configuration file." ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." -ErrTaskConfigTemplateExists,[code=20050:class=config:scope=internal:level=low], "Message: the task config template for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." -ErrTaskConfigTemplateNotExists,[code=20051:class=config:scope=internal:level=low], "Message: the task config template for '%s' not exists" +ErrOpenAPITaskConfigExists,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." +ErrOpenAPITaskConfigNotExists,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' not exists" ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" ErrBinlogParsePosFromStr,[code=22003:class=binlog-op:scope=internal:level=high] diff --git a/dm/dm/common/common.go b/dm/dm/common/common.go index d94304f53eb..b373d9e70d5 100644 --- a/dm/dm/common/common.go +++ b/dm/dm/common/common.go @@ -89,18 +89,18 @@ var ( // tb3: +a +b +c ShardDDLOptimismDroppedColumnsKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/shardddl-optimism/dropped-columns/") - // TaskConfigTemplateKeyAdapter is used to store the task config template(openapi.Task), now it's only used for WebUI. + // OpenAPITaskConfigKeyAdapter is used to store the openapi task config (openapi.Task), now it's only used for WebUI. // openapi.Task is a struct that can be converted to config.StubTaskConfig so if any field of openapi.Task updated - // user should use ha.PutTaskConfigTemplate(key, openapi.Task,overwrite) to force update the content in etcd. + // user should use ha.PutOpenAPITaskConfig(key, openapi.Task,overwrite) to force update the content in etcd. // k/v: Encode(task-name) -> openapi.Task. - TaskConfigTemplateKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/task-config-template/") + OpenAPITaskConfigKeyAdapter KeyAdapter = keyHexEncoderDecoder("/dm-master/openapi-task-config/") ) func keyAdapterKeysLen(s KeyAdapter) int { switch s { case WorkerRegisterKeyAdapter, UpstreamConfigKeyAdapter, UpstreamBoundWorkerKeyAdapter, WorkerKeepAliveKeyAdapter, StageRelayKeyAdapter, - UpstreamLastBoundWorkerKeyAdapter, UpstreamRelayWorkerKeyAdapter, TaskConfigTemplateKeyAdapter: + UpstreamLastBoundWorkerKeyAdapter, UpstreamRelayWorkerKeyAdapter, OpenAPITaskConfigKeyAdapter: return 1 case UpstreamSubTaskKeyAdapter, StageSubTaskKeyAdapter, ShardDDLPessimismInfoKeyAdapter, ShardDDLPessimismOperationKeyAdapter, diff --git a/dm/dm/common/common_test.go b/dm/dm/common/common_test.go index ef1f1574095..bc0493e96ac 100644 --- a/dm/dm/common/common_test.go +++ b/dm/dm/common/common_test.go @@ -83,8 +83,8 @@ func (t *testCommon) TestKeyAdapter(c *C) { }, { keys: []string{"task-1"}, - adapter: TaskConfigTemplateKeyAdapter, - want: "/dm-master/task-config-template/7461736b2d31", + adapter: OpenAPITaskConfigKeyAdapter, + want: "/dm-master/openapi-task-config/7461736b2d31", }, } diff --git a/dm/errors.toml b/dm/errors.toml index a7f10dc68fc..1a291b180ae 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1085,13 +1085,13 @@ workaround = "Please update your `shadow-table-rules` or `trash-table-rules` in tags = ["internal", "high"] [error.DM-config-20050] -message = "the task config template for '%s' already exists" +message = "the openapi task config for '%s' already exists" description = "" workaround = "If you want to override it, pleaset use the overwite flag." tags = ["internal", "low"] [error.DM-config-20051] -message = "the task config template for '%s' not exists" +message = "the openapi task config for '%s' not exists" description = "" workaround = "" tags = ["internal", "low"] diff --git a/dm/pkg/ha/task_config_template.go b/dm/pkg/ha/openapi_task_config.go similarity index 69% rename from dm/pkg/ha/task_config_template.go rename to dm/pkg/ha/openapi_task_config.go index c939dbbdb04..2f5d9c5b428 100644 --- a/dm/pkg/ha/task_config_template.go +++ b/dm/pkg/ha/openapi_task_config.go @@ -40,12 +40,12 @@ func openAPITaskFromResp(resp *clientv3.GetResponse) (*openapi.Task, error) { return task, nil } -// PutTaskConfigTemplate puts the task config template of task-name. -func PutTaskConfigTemplate(cli *clientv3.Client, task openapi.Task, overWrite bool) error { +// PutOpenAPITaskConfig puts the openapi task config of task-name. +func PutOpenAPITaskConfig(cli *clientv3.Client, task openapi.Task, overWrite bool) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() - key := common.TaskConfigTemplateKeyAdapter.Encode(task.Name) + key := common.OpenAPITaskConfigKeyAdapter.Encode(task.Name) taskJSON, err := task.ToJSON() if err != nil { return err // it should not happen. @@ -60,17 +60,17 @@ func PutTaskConfigTemplate(cli *clientv3.Client, task openapi.Task, overWrite bo } // user don't want to overwrite and key already exists. if !overWrite && !resp.Succeeded { - return terror.ErrTaskConfigTemplateExists.Generate(task.Name) + return terror.ErrOpenAPITaskConfigExists.Generate(task.Name) } return nil } -// PutTaskConfigTemplate puts the task config template of task-name. -func PutTaskConfigTemplateIfExist(cli *clientv3.Client, task openapi.Task) error { +// PutOpenAPITaskConfig puts the openapi task config of task-name. +func PutOpenAPITaskConfigIfExist(cli *clientv3.Client, task openapi.Task) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() - key := common.TaskConfigTemplateKeyAdapter.Encode(task.Name) + key := common.OpenAPITaskConfigKeyAdapter.Encode(task.Name) taskJSON, err := task.ToJSON() if err != nil { return err // it should not happen. @@ -82,23 +82,23 @@ func PutTaskConfigTemplateIfExist(cli *clientv3.Client, task openapi.Task) error } // user want to update a key not exists. if !resp.Succeeded { - return terror.ErrTaskConfigTemplateNotExists.Generate(task.Name) + return terror.ErrOpenAPITaskConfigNotExists.Generate(task.Name) } return nil } -// DeleteTaskConfigTemplate deletes the task config template of task-name. -func DeleteTaskConfigTemplate(cli *clientv3.Client, taskName string) error { +// DeleteOpenAPITaskConfig deletes the openapi task config of task-name. +func DeleteOpenAPITaskConfig(cli *clientv3.Client, taskName string) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() - if _, err := cli.Delete(ctx, common.TaskConfigTemplateKeyAdapter.Encode(taskName)); err != nil { + if _, err := cli.Delete(ctx, common.OpenAPITaskConfigKeyAdapter.Encode(taskName)); err != nil { return err } return nil } -// GetTaskConfigTemplate gets the task config template of task-name. -func GetTaskConfigTemplate(cli *clientv3.Client, taskName string) (*openapi.Task, error) { +// GetOpenAPITaskConfig gets the openapi task config of task-name. +func GetOpenAPITaskConfig(cli *clientv3.Client, taskName string) (*openapi.Task, error) { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() @@ -107,7 +107,7 @@ func GetTaskConfigTemplate(cli *clientv3.Client, taskName string) (*openapi.Task resp *clientv3.GetResponse err error ) - resp, err = cli.Get(ctx, common.TaskConfigTemplateKeyAdapter.Encode(taskName)) + resp, err = cli.Get(ctx, common.OpenAPITaskConfigKeyAdapter.Encode(taskName)) if err != nil { return task, err } @@ -118,12 +118,12 @@ func GetTaskConfigTemplate(cli *clientv3.Client, taskName string) (*openapi.Task return task, nil } -// GetAllTaskConfigTemplate gets all task config templates. -func GetAllTaskConfigTemplate(cli *clientv3.Client) ([]*openapi.Task, error) { +// GetAllOpenAPITaskConfig gets all openapi task config s. +func GetAllOpenAPITaskConfig(cli *clientv3.Client) ([]*openapi.Task, error) { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() - resp, err := cli.Get(ctx, common.TaskConfigTemplateKeyAdapter.Path(), clientv3.WithPrefix()) + resp, err := cli.Get(ctx, common.OpenAPITaskConfigKeyAdapter.Path(), clientv3.WithPrefix()) if err != nil { return nil, err } diff --git a/dm/pkg/ha/task_config_template_test.go b/dm/pkg/ha/openapi_task_config_test.go similarity index 57% rename from dm/pkg/ha/task_config_template_test.go rename to dm/pkg/ha/openapi_task_config_test.go index 74c8940bd20..68ca3579233 100644 --- a/dm/pkg/ha/task_config_template_test.go +++ b/dm/pkg/ha/openapi_task_config_test.go @@ -21,7 +21,7 @@ import ( "github.com/pingcap/ticdc/dm/pkg/terror" ) -func (t *testForEtcd) TestTaskConfigTemplateEtcd(c *C) { +func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { defer clearTestInfoOperation(c) task1, err := fixtures.GenNoShardOpenAPITaskForTest() @@ -31,42 +31,42 @@ func (t *testForEtcd) TestTaskConfigTemplateEtcd(c *C) { task2.Name = "test-2" c.Assert(err, IsNil) - // no task config template exist. - task1InEtcd, err := GetTaskConfigTemplate(etcdTestCli, task1.Name) + // no openapi task config exist. + task1InEtcd, err := GetOpenAPITaskConfig(etcdTestCli, task1.Name) c.Assert(err, IsNil) c.Assert(task1InEtcd, IsNil) - task2InEtcd, err := GetTaskConfigTemplate(etcdTestCli, task2.Name) + task2InEtcd, err := GetOpenAPITaskConfig(etcdTestCli, task2.Name) c.Assert(err, IsNil) c.Assert(task2InEtcd, IsNil) - tasks, err := GetAllTaskConfigTemplate(etcdTestCli) + tasks, err := GetAllOpenAPITaskConfig(etcdTestCli) c.Assert(err, IsNil) c.Assert(tasks, HasLen, 0) - // put task config template. - c.Assert(PutTaskConfigTemplate(etcdTestCli, task1, false), IsNil) - c.Assert(PutTaskConfigTemplate(etcdTestCli, task2, false), IsNil) + // put openapi task config . + c.Assert(PutOpenAPITaskConfig(etcdTestCli, task1, false), IsNil) + c.Assert(PutOpenAPITaskConfig(etcdTestCli, task2, false), IsNil) - task1InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task1.Name) + task1InEtcd, err = GetOpenAPITaskConfig(etcdTestCli, task1.Name) c.Assert(err, IsNil) c.Assert(*task1InEtcd, DeepEquals, task1) - task2InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task2.Name) + task2InEtcd, err = GetOpenAPITaskConfig(etcdTestCli, task2.Name) c.Assert(err, IsNil) c.Assert(*task2InEtcd, DeepEquals, task2) - tasks, err = GetAllTaskConfigTemplate(etcdTestCli) + tasks, err = GetAllOpenAPITaskConfig(etcdTestCli) c.Assert(err, IsNil) c.Assert(tasks, HasLen, 2) - // put task config template again without overwrite will fail - c.Assert(terror.ErrTaskConfigTemplateExists.Equal(PutTaskConfigTemplate(etcdTestCli, task1, false)), IsTrue) + // put openapi task config again without overwrite will fail + c.Assert(terror.ErrOpenAPITaskConfigExists.Equal(PutOpenAPITaskConfig(etcdTestCli, task1, false)), IsTrue) // in overwrite mode, it will overwrite the old one. task1.TaskMode = openapi.TaskTaskModeFull - c.Assert(PutTaskConfigTemplate(etcdTestCli, task1, true), IsNil) - task1InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task1.Name) + c.Assert(PutOpenAPITaskConfig(etcdTestCli, task1, true), IsNil) + task1InEtcd, err = GetOpenAPITaskConfig(etcdTestCli, task1.Name) c.Assert(err, IsNil) c.Assert(*task1InEtcd, DeepEquals, task1) @@ -74,18 +74,18 @@ func (t *testForEtcd) TestTaskConfigTemplateEtcd(c *C) { task3, err := fixtures.GenNoShardOpenAPITaskForTest() c.Assert(err, IsNil) task3.Name = "test-3" - c.Assert(terror.ErrTaskConfigTemplateNotExists.Equal(PutTaskConfigTemplateIfExist(etcdTestCli, task3)), IsTrue) + c.Assert(terror.ErrOpenAPITaskConfigNotExists.Equal(PutOpenAPITaskConfigIfExist(etcdTestCli, task3)), IsTrue) - // update exist task config template will success + // update exist openapi task config will success task1.TaskMode = openapi.TaskTaskModeAll - c.Assert(PutTaskConfigTemplateIfExist(etcdTestCli, task1), IsNil) - task1InEtcd, err = GetTaskConfigTemplate(etcdTestCli, task1.Name) + c.Assert(PutOpenAPITaskConfigIfExist(etcdTestCli, task1), IsNil) + task1InEtcd, err = GetOpenAPITaskConfig(etcdTestCli, task1.Name) c.Assert(err, IsNil) c.Assert(*task1InEtcd, DeepEquals, task1) // delete task config - c.Assert(DeleteTaskConfigTemplate(etcdTestCli, task1.Name), IsNil) - tasks, err = GetAllTaskConfigTemplate(etcdTestCli) + c.Assert(DeleteOpenAPITaskConfig(etcdTestCli, task1.Name), IsNil) + tasks, err = GetAllOpenAPITaskConfig(etcdTestCli) c.Assert(err, IsNil) c.Assert(tasks, HasLen, 1) } diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index 486eb0c7ce9..e86d9beb4b7 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -244,8 +244,8 @@ const ( codeConfigInvalidChunkFileSize codeConfigOnlineDDLInvalidRegex codeConfigOnlineDDLMistakeRegex - codeConfigTaskConfigTemplateExists - codeConfigTaskConfigTemplateNotExists + codeConfigOpenAPITaskConfigExists + codeConfigOpenAPITaskConfigNotExists ) // Binlog operation error code list. @@ -899,8 +899,8 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrTaskConfigTemplateExists = New(codeConfigTaskConfigTemplateExists, ClassConfig, ScopeInternal, LevelLow, "the task config template for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") - ErrTaskConfigTemplateNotExists = New(codeConfigTaskConfigTemplateNotExists, ClassConfig, ScopeInternal, LevelLow, "the task config template for '%s' not exists", "") + ErrOpenAPITaskConfigExists = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") + ErrOpenAPITaskConfigNotExists = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' not exists", "") // Binlog operation error. ErrBinlogExtractPosition = New(codeBinlogExtractPosition, ClassBinlogOp, ScopeInternal, LevelHigh, "", "") From 698fcc2f6f9be0fecdd5ee61032581e09fbec861 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Tue, 7 Dec 2021 17:25:15 +0800 Subject: [PATCH 06/13] fix code format --- dm/_utils/terror_gen/errors_release.txt | 4 ++-- dm/errors.toml | 4 ++-- dm/pkg/ha/openapi_task_config.go | 10 +++------- dm/pkg/ha/openapi_task_config_test.go | 8 ++++---- dm/pkg/terror/error_list.go | 4 ++-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index ba83303d4cd..03d93d36059 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -179,8 +179,8 @@ ErrConfigGenColumnMapping,[code=20046:class=config:scope=internal:level=high], " ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high], "Message: invalid `chunk-filesize` %v, Workaround: Please check the `chunk-filesize` config in task configuration file." ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." -ErrOpenAPITaskConfigExists,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." -ErrOpenAPITaskConfigNotExists,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' not exists" +ErrOpenAPITaskConfigExists,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." +ErrOpenAPITaskConfigNotExists,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' does not exists" ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" ErrBinlogParsePosFromStr,[code=22003:class=binlog-op:scope=internal:level=high] diff --git a/dm/errors.toml b/dm/errors.toml index 1a291b180ae..80a94104a58 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1085,13 +1085,13 @@ workaround = "Please update your `shadow-table-rules` or `trash-table-rules` in tags = ["internal", "high"] [error.DM-config-20050] -message = "the openapi task config for '%s' already exists" +message = "the openapi task config for '%s' already exists" description = "" workaround = "If you want to override it, pleaset use the overwite flag." tags = ["internal", "low"] [error.DM-config-20051] -message = "the openapi task config for '%s' not exists" +message = "the openapi task config for '%s' does not exists" description = "" workaround = "" tags = ["internal", "low"] diff --git a/dm/pkg/ha/openapi_task_config.go b/dm/pkg/ha/openapi_task_config.go index 2f5d9c5b428..60e2b9a5f03 100644 --- a/dm/pkg/ha/openapi_task_config.go +++ b/dm/pkg/ha/openapi_task_config.go @@ -87,7 +87,7 @@ func PutOpenAPITaskConfigIfExist(cli *clientv3.Client, task openapi.Task) error return nil } -// DeleteOpenAPITaskConfig deletes the openapi task config of task-name. +// DeleteOpenAPITaskConfig deletes the openapi task config of task-name. func DeleteOpenAPITaskConfig(cli *clientv3.Client, taskName string) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() @@ -97,7 +97,7 @@ func DeleteOpenAPITaskConfig(cli *clientv3.Client, taskName string) error { return nil } -// GetOpenAPITaskConfig gets the openapi task config of task-name. +// GetOpenAPITaskConfig gets the openapi task config of task-name. func GetOpenAPITaskConfig(cli *clientv3.Client, taskName string) (*openapi.Task, error) { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() @@ -111,11 +111,7 @@ func GetOpenAPITaskConfig(cli *clientv3.Client, taskName string) (*openapi.Task, if err != nil { return task, err } - task, err = openAPITaskFromResp(resp) - if err != nil { - return task, err - } - return task, nil + return openAPITaskFromResp(resp) } // GetAllOpenAPITaskConfig gets all openapi task config s. diff --git a/dm/pkg/ha/openapi_task_config_test.go b/dm/pkg/ha/openapi_task_config_test.go index 68ca3579233..482fec581bc 100644 --- a/dm/pkg/ha/openapi_task_config_test.go +++ b/dm/pkg/ha/openapi_task_config_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 PingCAP, Inc. +// Copyright 2021 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { task2.Name = "test-2" c.Assert(err, IsNil) - // no openapi task config exist. + // no openapi task config exist. task1InEtcd, err := GetOpenAPITaskConfig(etcdTestCli, task1.Name) c.Assert(err, IsNil) c.Assert(task1InEtcd, IsNil) @@ -60,7 +60,7 @@ func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { c.Assert(err, IsNil) c.Assert(tasks, HasLen, 2) - // put openapi task config again without overwrite will fail + // put openapi task config again without overwrite will fail c.Assert(terror.ErrOpenAPITaskConfigExists.Equal(PutOpenAPITaskConfig(etcdTestCli, task1, false)), IsTrue) // in overwrite mode, it will overwrite the old one. @@ -76,7 +76,7 @@ func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { task3.Name = "test-3" c.Assert(terror.ErrOpenAPITaskConfigNotExists.Equal(PutOpenAPITaskConfigIfExist(etcdTestCli, task3)), IsTrue) - // update exist openapi task config will success + // update exist openapi task config will success task1.TaskMode = openapi.TaskTaskModeAll c.Assert(PutOpenAPITaskConfigIfExist(etcdTestCli, task1), IsNil) task1InEtcd, err = GetOpenAPITaskConfig(etcdTestCli, task1.Name) diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index e86d9beb4b7..4cc8e4c3fcb 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -899,8 +899,8 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrOpenAPITaskConfigExists = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") - ErrOpenAPITaskConfigNotExists = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' not exists", "") + ErrOpenAPITaskConfigExists = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") + ErrOpenAPITaskConfigNotExists = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exists", "") // Binlog operation error. ErrBinlogExtractPosition = New(codeBinlogExtractPosition, ClassBinlogOp, ScopeInternal, LevelHigh, "", "") From 385e8ad8448f5d06312a56a9a4cb72ed183a07f0 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Wed, 8 Dec 2021 09:53:07 +0800 Subject: [PATCH 07/13] exists -> exist --- dm/_utils/terror_gen/errors_release.txt | 4 ++-- dm/errors.toml | 4 ++-- dm/pkg/ha/openapi_task_config.go | 4 ++-- dm/pkg/ha/openapi_task_config_test.go | 4 ++-- dm/pkg/terror/error_list.go | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index 03d93d36059..d8bdb030fe3 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -179,8 +179,8 @@ ErrConfigGenColumnMapping,[code=20046:class=config:scope=internal:level=high], " ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high], "Message: invalid `chunk-filesize` %v, Workaround: Please check the `chunk-filesize` config in task configuration file." ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." -ErrOpenAPITaskConfigExists,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exists, Workaround: If you want to override it, pleaset use the overwite flag." -ErrOpenAPITaskConfigNotExists,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' does not exists" +ErrOpenAPITaskConfigExist,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exist, Workaround: If you want to override it, pleaset use the overwite flag." +ErrOpenAPITaskConfigNotExist,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' does not exist" ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" ErrBinlogParsePosFromStr,[code=22003:class=binlog-op:scope=internal:level=high] diff --git a/dm/errors.toml b/dm/errors.toml index 80a94104a58..1468dbef925 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1085,13 +1085,13 @@ workaround = "Please update your `shadow-table-rules` or `trash-table-rules` in tags = ["internal", "high"] [error.DM-config-20050] -message = "the openapi task config for '%s' already exists" +message = "the openapi task config for '%s' already exist" description = "" workaround = "If you want to override it, pleaset use the overwite flag." tags = ["internal", "low"] [error.DM-config-20051] -message = "the openapi task config for '%s' does not exists" +message = "the openapi task config for '%s' does not exist" description = "" workaround = "" tags = ["internal", "low"] diff --git a/dm/pkg/ha/openapi_task_config.go b/dm/pkg/ha/openapi_task_config.go index 60e2b9a5f03..a37ed5823ed 100644 --- a/dm/pkg/ha/openapi_task_config.go +++ b/dm/pkg/ha/openapi_task_config.go @@ -60,7 +60,7 @@ func PutOpenAPITaskConfig(cli *clientv3.Client, task openapi.Task, overWrite boo } // user don't want to overwrite and key already exists. if !overWrite && !resp.Succeeded { - return terror.ErrOpenAPITaskConfigExists.Generate(task.Name) + return terror.ErrOpenAPITaskConfigExist.Generate(task.Name) } return nil } @@ -82,7 +82,7 @@ func PutOpenAPITaskConfigIfExist(cli *clientv3.Client, task openapi.Task) error } // user want to update a key not exists. if !resp.Succeeded { - return terror.ErrOpenAPITaskConfigNotExists.Generate(task.Name) + return terror.ErrOpenAPITaskConfigNotExist.Generate(task.Name) } return nil } diff --git a/dm/pkg/ha/openapi_task_config_test.go b/dm/pkg/ha/openapi_task_config_test.go index 482fec581bc..2eeb603e38e 100644 --- a/dm/pkg/ha/openapi_task_config_test.go +++ b/dm/pkg/ha/openapi_task_config_test.go @@ -61,7 +61,7 @@ func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { c.Assert(tasks, HasLen, 2) // put openapi task config again without overwrite will fail - c.Assert(terror.ErrOpenAPITaskConfigExists.Equal(PutOpenAPITaskConfig(etcdTestCli, task1, false)), IsTrue) + c.Assert(terror.ErrOpenAPITaskConfigExist.Equal(PutOpenAPITaskConfig(etcdTestCli, task1, false)), IsTrue) // in overwrite mode, it will overwrite the old one. task1.TaskMode = openapi.TaskTaskModeFull @@ -74,7 +74,7 @@ func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { task3, err := fixtures.GenNoShardOpenAPITaskForTest() c.Assert(err, IsNil) task3.Name = "test-3" - c.Assert(terror.ErrOpenAPITaskConfigNotExists.Equal(PutOpenAPITaskConfigIfExist(etcdTestCli, task3)), IsTrue) + c.Assert(terror.ErrOpenAPITaskConfigNotExist.Equal(PutOpenAPITaskConfigIfExist(etcdTestCli, task3)), IsTrue) // update exist openapi task config will success task1.TaskMode = openapi.TaskTaskModeAll diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index 4cc8e4c3fcb..2ab92d65799 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -899,8 +899,8 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrOpenAPITaskConfigExists = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exists", "If you want to override it, pleaset use the overwite flag.") - ErrOpenAPITaskConfigNotExists = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exists", "") + ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, pleaset use the overwite flag.") + ErrOpenAPITaskConfigNotExist = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exist", "") // Binlog operation error. ErrBinlogExtractPosition = New(codeBinlogExtractPosition, ClassBinlogOp, ScopeInternal, LevelHigh, "", "") From 0f81b94408124b2d3439141b28dd6befc289d340 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Wed, 8 Dec 2021 09:56:23 +0800 Subject: [PATCH 08/13] fix typo --- dm/_utils/terror_gen/errors_release.txt | 2 +- dm/errors.toml | 2 +- dm/pkg/terror/error_list.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index d8bdb030fe3..5758be4e6f5 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -179,7 +179,7 @@ ErrConfigGenColumnMapping,[code=20046:class=config:scope=internal:level=high], " ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high], "Message: invalid `chunk-filesize` %v, Workaround: Please check the `chunk-filesize` config in task configuration file." ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." -ErrOpenAPITaskConfigExist,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exist, Workaround: If you want to override it, pleaset use the overwite flag." +ErrOpenAPITaskConfigExist,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exist, Workaround: If you want to override it, pleaset use the overwrite flag." ErrOpenAPITaskConfigNotExist,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' does not exist" ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" diff --git a/dm/errors.toml b/dm/errors.toml index 1468dbef925..03adb41e895 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1087,7 +1087,7 @@ tags = ["internal", "high"] [error.DM-config-20050] message = "the openapi task config for '%s' already exist" description = "" -workaround = "If you want to override it, pleaset use the overwite flag." +workaround = "If you want to override it, pleaset use the overwrite flag." tags = ["internal", "low"] [error.DM-config-20051] diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index 2ab92d65799..1f602ef6618 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -899,7 +899,7 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, pleaset use the overwite flag.") + ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, pleaset use the overwrite flag.") ErrOpenAPITaskConfigNotExist = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exist", "") // Binlog operation error. From 25a0db4ee1d756a1eb98f4c12d78c9c9ed365761 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Wed, 8 Dec 2021 10:09:19 +0800 Subject: [PATCH 09/13] pleaset -> please --- dm/_utils/terror_gen/errors_release.txt | 2 +- dm/errors.toml | 2 +- dm/pkg/terror/error_list.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dm/_utils/terror_gen/errors_release.txt b/dm/_utils/terror_gen/errors_release.txt index 5758be4e6f5..afd95ce815a 100644 --- a/dm/_utils/terror_gen/errors_release.txt +++ b/dm/_utils/terror_gen/errors_release.txt @@ -179,7 +179,7 @@ ErrConfigGenColumnMapping,[code=20046:class=config:scope=internal:level=high], " ErrConfigInvalidChunkFileSize,[code=20047:class=config:scope=internal:level=high], "Message: invalid `chunk-filesize` %v, Workaround: Please check the `chunk-filesize` config in task configuration file." ErrConfigOnlineDDLInvalidRegex,[code=20048:class=config:scope=internal:level=high], "Message: config '%s' regex pattern '%s' invalid, reason: %s, Workaround: Please check if params is correctly in the configuration file." ErrConfigOnlineDDLMistakeRegex,[code=20049:class=config:scope=internal:level=high], "Message: online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex, Workaround: Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file." -ErrOpenAPITaskConfigExist,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exist, Workaround: If you want to override it, pleaset use the overwrite flag." +ErrOpenAPITaskConfigExist,[code=20050:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' already exist, Workaround: If you want to override it, please use the overwrite flag." ErrOpenAPITaskConfigNotExist,[code=20051:class=config:scope=internal:level=low], "Message: the openapi task config for '%s' does not exist" ErrBinlogExtractPosition,[code=22001:class=binlog-op:scope=internal:level=high] ErrBinlogInvalidFilename,[code=22002:class=binlog-op:scope=internal:level=high], "Message: invalid binlog filename" diff --git a/dm/errors.toml b/dm/errors.toml index 03adb41e895..e964a55155b 100644 --- a/dm/errors.toml +++ b/dm/errors.toml @@ -1087,7 +1087,7 @@ tags = ["internal", "high"] [error.DM-config-20050] message = "the openapi task config for '%s' already exist" description = "" -workaround = "If you want to override it, pleaset use the overwrite flag." +workaround = "If you want to override it, please use the overwrite flag." tags = ["internal", "low"] [error.DM-config-20051] diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index 1f602ef6618..f846508070a 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -899,7 +899,7 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, pleaset use the overwrite flag.") + pleaset -> pleaseErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, please use the overwrite flag.") ErrOpenAPITaskConfigNotExist = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exist", "") // Binlog operation error. From a3da735f42040033bf37f1fcdd8dca417fb97675 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Wed, 8 Dec 2021 10:11:29 +0800 Subject: [PATCH 10/13] fix --- dm/pkg/terror/error_list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index f846508070a..ba2dff5c10c 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -899,7 +899,7 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - pleaset -> pleaseErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, please use the overwrite flag.") + ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, please use the overwrite flag.") ErrOpenAPITaskConfigNotExist = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exist", "") // Binlog operation error. From da97ff25f9eab518e88b7ebbc3fdb51f9e734589 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Thu, 9 Dec 2021 08:09:18 +0800 Subject: [PATCH 11/13] fix terror code name --- dm/pkg/terror/error_list.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dm/pkg/terror/error_list.go b/dm/pkg/terror/error_list.go index ba2dff5c10c..40ec97749ea 100644 --- a/dm/pkg/terror/error_list.go +++ b/dm/pkg/terror/error_list.go @@ -244,8 +244,8 @@ const ( codeConfigInvalidChunkFileSize codeConfigOnlineDDLInvalidRegex codeConfigOnlineDDLMistakeRegex - codeConfigOpenAPITaskConfigExists - codeConfigOpenAPITaskConfigNotExists + codeConfigOpenAPITaskConfigExist + codeConfigOpenAPITaskConfigNotExist ) // Binlog operation error code list. @@ -899,8 +899,8 @@ var ( "config '%s' regex pattern '%s' invalid, reason: %s", "Please check if params is correctly in the configuration file.") ErrConfigOnlineDDLMistakeRegex = New(codeConfigOnlineDDLMistakeRegex, ClassConfig, ScopeInternal, LevelHigh, "online ddl sql '%s' invalid, table %s fail to match '%s' online ddl regex", "Please update your `shadow-table-rules` or `trash-table-rules` in the configuration file.") - ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, please use the overwrite flag.") - ErrOpenAPITaskConfigNotExist = New(codeConfigOpenAPITaskConfigNotExists, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exist", "") + ErrOpenAPITaskConfigExist = New(codeConfigOpenAPITaskConfigExist, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' already exist", "If you want to override it, please use the overwrite flag.") + ErrOpenAPITaskConfigNotExist = New(codeConfigOpenAPITaskConfigNotExist, ClassConfig, ScopeInternal, LevelLow, "the openapi task config for '%s' does not exist", "") // Binlog operation error. ErrBinlogExtractPosition = New(codeBinlogExtractPosition, ClassBinlogOp, ScopeInternal, LevelHigh, "", "") From e115a8d040aee80e098480e0957fa3b1ab68c82c Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Mon, 13 Dec 2021 13:52:26 +0800 Subject: [PATCH 12/13] rename func --- dm/pkg/ha/openapi_task_config.go | 4 ++-- dm/pkg/ha/openapi_task_config_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dm/pkg/ha/openapi_task_config.go b/dm/pkg/ha/openapi_task_config.go index a37ed5823ed..71f4edfa471 100644 --- a/dm/pkg/ha/openapi_task_config.go +++ b/dm/pkg/ha/openapi_task_config.go @@ -65,8 +65,8 @@ func PutOpenAPITaskConfig(cli *clientv3.Client, task openapi.Task, overWrite boo return nil } -// PutOpenAPITaskConfig puts the openapi task config of task-name. -func PutOpenAPITaskConfigIfExist(cli *clientv3.Client, task openapi.Task) error { +// UpdateOpenAPITaskConfig puts the openapi task config of task-name. +func UpdateOpenAPITaskConfig(cli *clientv3.Client, task openapi.Task) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel() diff --git a/dm/pkg/ha/openapi_task_config_test.go b/dm/pkg/ha/openapi_task_config_test.go index 2eeb603e38e..0a0ccbc1b21 100644 --- a/dm/pkg/ha/openapi_task_config_test.go +++ b/dm/pkg/ha/openapi_task_config_test.go @@ -74,11 +74,11 @@ func (t *testForEtcd) TestOpenAPITaskConfigEtcd(c *C) { task3, err := fixtures.GenNoShardOpenAPITaskForTest() c.Assert(err, IsNil) task3.Name = "test-3" - c.Assert(terror.ErrOpenAPITaskConfigNotExist.Equal(PutOpenAPITaskConfigIfExist(etcdTestCli, task3)), IsTrue) + c.Assert(terror.ErrOpenAPITaskConfigNotExist.Equal(UpdateOpenAPITaskConfig(etcdTestCli, task3)), IsTrue) // update exist openapi task config will success task1.TaskMode = openapi.TaskTaskModeAll - c.Assert(PutOpenAPITaskConfigIfExist(etcdTestCli, task1), IsNil) + c.Assert(UpdateOpenAPITaskConfig(etcdTestCli, task1), IsNil) task1InEtcd, err = GetOpenAPITaskConfig(etcdTestCli, task1.Name) c.Assert(err, IsNil) c.Assert(*task1InEtcd, DeepEquals, task1) From f9a40268a991ce9a56e1a8e772a92c40778ce2e5 Mon Sep 17 00:00:00 2001 From: Ehco Date: Mon, 13 Dec 2021 14:11:45 +0800 Subject: [PATCH 13/13] Update dm/pkg/ha/openapi_task_config.go Co-authored-by: okJiang <819421878@qq.com> --- dm/pkg/ha/openapi_task_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm/pkg/ha/openapi_task_config.go b/dm/pkg/ha/openapi_task_config.go index 71f4edfa471..570bb307671 100644 --- a/dm/pkg/ha/openapi_task_config.go +++ b/dm/pkg/ha/openapi_task_config.go @@ -65,7 +65,7 @@ func PutOpenAPITaskConfig(cli *clientv3.Client, task openapi.Task, overWrite boo return nil } -// UpdateOpenAPITaskConfig puts the openapi task config of task-name. +// UpdateOpenAPITaskConfig updates the openapi task config by task-name. func UpdateOpenAPITaskConfig(cli *clientv3.Client, task openapi.Task) error { ctx, cancel := context.WithTimeout(cli.Ctx(), etcdutil.DefaultRequestTimeout) defer cancel()