From 92a8b5e847ac3738f0e07f6dd7580a59c7529f7c Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Tue, 16 Jun 2020 07:38:54 -0400 Subject: [PATCH 01/11] remove stack err msg of ctl --- dm/ctl/common/util.go | 7 ++++--- dm/ctl/master/check_task.go | 6 +++--- dm/ctl/master/list_member.go | 6 +++--- dm/ctl/master/migrate_relay.go | 4 ++-- dm/ctl/master/offline_member.go | 7 ++++--- dm/ctl/master/operate_leader.go | 4 ++-- dm/ctl/master/operate_source.go | 6 +++--- dm/ctl/master/pause_relay.go | 6 +++--- dm/ctl/master/pause_task.go | 6 +++--- dm/ctl/master/purge_relay.go | 5 +++-- dm/ctl/master/resume_relay.go | 6 +++--- dm/ctl/master/resume_task.go | 6 +++--- dm/ctl/master/show_ddl_locks.go | 6 +++--- dm/ctl/master/sql_inject.go | 10 +++++----- dm/ctl/master/sql_replace.go | 8 ++++---- dm/ctl/master/sql_skip.go | 6 +++--- dm/ctl/master/start_task.go | 7 +++---- dm/ctl/master/stop_task.go | 6 +++--- dm/ctl/master/switch_relay_master.go | 6 +++--- dm/ctl/master/unlock_ddl_lock.go | 6 +++--- dm/ctl/master/update_masterconfig.go | 6 +++--- dm/ctl/master/update_relay.go | 6 +++--- dm/ctl/master/update_task.go | 8 ++++---- dm/master/scheduler/scheduler.go | 2 +- 24 files changed, 74 insertions(+), 72 deletions(-) diff --git a/dm/ctl/common/util.go b/dm/ctl/common/util.go index 215c8d7b69..e9c7236ef2 100644 --- a/dm/ctl/common/util.go +++ b/dm/ctl/common/util.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/dm/dm/pb" parserpkg "github.com/pingcap/dm/pkg/parser" + "github.com/pingcap/dm/pkg/terror" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" @@ -72,7 +73,7 @@ func PrintLines(format string, a ...interface{}) { func PrettyPrintResponse(resp proto.Message) { s, err := marshResponseToString(resp) if err != nil { - PrintLines(errors.ErrorStack(err)) + PrintLines(terror.Message(err)) } else { fmt.Println(s) } @@ -82,7 +83,7 @@ func PrettyPrintResponse(resp proto.Message) { func PrettyPrintInterface(resp interface{}) { s, err := json.MarshalIndent(resp, "", " ") if err != nil { - PrintLines(errors.ErrorStack(err)) + PrintLines(terror.Message(err)) } else { fmt.Println(string(s)) } @@ -147,7 +148,7 @@ func PrettyPrintResponseWithCheckTask(resp proto.Message, subStr string) bool { } if err != nil { - fmt.Println(errors.ErrorStack(err)) + fmt.Println(terror.Message(err)) } else { // add indent to make it prettily. replacedStr = strings.Replace(replacedStr, "detail: {", " \tdetail: {", 1) diff --git a/dm/ctl/master/check_task.go b/dm/ctl/master/check_task.go index ef4b49c40b..532db370bf 100644 --- a/dm/ctl/master/check_task.go +++ b/dm/ctl/master/check_task.go @@ -17,12 +17,12 @@ import ( "context" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/checker" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewCheckTaskCmd creates a CheckTask command @@ -44,7 +44,7 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get file content error:\n%v", terror.Message(err)) return } @@ -57,7 +57,7 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) { Task: string(content), }) if err != nil { - common.PrintLines("fail to check task:\n%v", errors.ErrorStack(err)) + common.PrintLines("fail to check task:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/list_member.go b/dm/ctl/master/list_member.go index 2ce17cafac..30dd8a2c1c 100644 --- a/dm/ctl/master/list_member.go +++ b/dm/ctl/master/list_member.go @@ -17,11 +17,11 @@ import ( "context" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) var ( @@ -73,7 +73,7 @@ func listMemberFunc(cmd *cobra.Command, _ []string) { leader, master, worker, err := convertListMemberType(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) } ctx, cancel := context.WithCancel(context.Background()) @@ -88,7 +88,7 @@ func listMemberFunc(cmd *cobra.Command, _ []string) { }) if err != nil { - common.PrintLines("list member failed, error:\n%v", errors.ErrorStack(err)) + common.PrintLines("list member failed, error:\n%v", terror.Message(err)) return } common.PrettyPrintResponse(resp) diff --git a/dm/ctl/master/migrate_relay.go b/dm/ctl/master/migrate_relay.go index ea63a2af94..7c2a94872d 100644 --- a/dm/ctl/master/migrate_relay.go +++ b/dm/ctl/master/migrate_relay.go @@ -18,13 +18,13 @@ import ( "os" "strconv" - "github.com/pingcap/errors" "github.com/spf13/cobra" "go.uber.org/zap" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" "github.com/pingcap/dm/pkg/log" + "github.com/pingcap/dm/pkg/terror" ) // NewMigrateRelayCmd creates a MigrateRelay command @@ -49,7 +49,7 @@ func migrateRelayFunc(cmd *cobra.Command, _ []string) { binlogName := cmd.Flags().Arg(1) binlogPos, err := strconv.Atoi(cmd.Flags().Arg(2)) if err != nil { - common.PrintLines(errors.ErrorStack(err)) + common.PrintLines(terror.Message(err)) } ctx, cancel := context.WithCancel(context.Background()) diff --git a/dm/ctl/master/offline_member.go b/dm/ctl/master/offline_member.go index 488c05f377..7a3f8dafb8 100644 --- a/dm/ctl/master/offline_member.go +++ b/dm/ctl/master/offline_member.go @@ -19,6 +19,7 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" "github.com/pingcap/errors" "github.com/spf13/cobra" @@ -65,12 +66,12 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) { offlineType, err := convertOfflineMemberType(cmd) if err != nil { - common.PrintLines("get offline type failed, error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get offline type failed, error:\n%v", terror.Message(err)) return } name, err := cmd.Flags().GetString("name") if err != nil { - common.PrintLines("get offline name failed, error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get offline name failed, error:\n%v", terror.Message(err)) return } else if name == "" { common.PrintLines("a member name must be specified") @@ -85,7 +86,7 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) { Name: name, }) if err != nil { - common.PrintLines("offline member failed, error:\n%v", errors.ErrorStack(err)) + common.PrintLines("offline member failed, error:\n%v", terror.Message(err)) return } if !resp.Result { diff --git a/dm/ctl/master/operate_leader.go b/dm/ctl/master/operate_leader.go index 9efa881fa2..75015ca810 100644 --- a/dm/ctl/master/operate_leader.go +++ b/dm/ctl/master/operate_leader.go @@ -17,11 +17,11 @@ import ( "context" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewOperateLeaderCmd creates a OperateLeader command @@ -70,7 +70,7 @@ func operateLeaderFunc(cmd *cobra.Command, _ []string) { Op: op, }) if err != nil { - common.PrintLines("fail to operate leader:\n%v", errors.ErrorStack(err)) + common.PrintLines("fail to operate leader:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/operate_source.go b/dm/ctl/master/operate_source.go index fa87dc4bec..fea4837a1c 100644 --- a/dm/ctl/master/operate_source.go +++ b/dm/ctl/master/operate_source.go @@ -19,8 +19,8 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" - "github.com/pingcap/errors" "github.com/spf13/cobra" ) @@ -59,7 +59,7 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) { configFile := cmd.Flags().Arg(1) content, err := common.GetFileContent(configFile) if err != nil { - common.PrintLines("get file content error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get file content error:\n%v", terror.Message(err)) return } ctx, cancel := context.WithCancel(context.Background()) @@ -77,7 +77,7 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) { Op: op, }) if err != nil { - common.PrintLines("can not update task:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not update task:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/pause_relay.go b/dm/ctl/master/pause_relay.go index 427b88fad0..35a5deb39c 100644 --- a/dm/ctl/master/pause_relay.go +++ b/dm/ctl/master/pause_relay.go @@ -17,11 +17,11 @@ import ( "fmt" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewPauseRelayCmd creates a PauseRelay command @@ -44,7 +44,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } if len(sources) == 0 { @@ -54,7 +54,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) { resp, err := common.OperateRelay(pb.RelayOp_PauseRelay, sources) if err != nil { - common.PrintLines("can not pause relay unit:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not pause relay unit:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/pause_task.go b/dm/ctl/master/pause_task.go index 370be1c7b9..449e6a4061 100644 --- a/dm/ctl/master/pause_task.go +++ b/dm/ctl/master/pause_task.go @@ -16,11 +16,11 @@ package master import ( "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewPauseTaskCmd creates a PauseTask command @@ -44,13 +44,13 @@ func pauseTaskFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } resp, err := common.OperateTask(pb.TaskOp_Pause, name, sources) if err != nil { - common.PrintLines("can not pause task %s:\n%v", name, errors.ErrorStack(err)) + common.PrintLines("can not pause task %s:\n%v", name, terror.Message(err)) return } diff --git a/dm/ctl/master/purge_relay.go b/dm/ctl/master/purge_relay.go index 95a74bc68a..d2d9463847 100644 --- a/dm/ctl/master/purge_relay.go +++ b/dm/ctl/master/purge_relay.go @@ -25,6 +25,7 @@ import ( "github.com/pingcap/dm/dm/command" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) var ( @@ -63,7 +64,7 @@ func purgeRelayFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - fmt.Println(errors.ErrorStack(err)) + fmt.Println(terror.Message(err)) return } if len(sources) == 0 { @@ -145,7 +146,7 @@ func purgeRelayFunc(cmd *cobra.Command, _ []string) { SubDir: subDir, }) if err != nil { - common.PrintLines("can not purge relay log files: \n%s", errors.ErrorStack(err)) + common.PrintLines("can not purge relay log files: \n%s", terror.Message(err)) return } diff --git a/dm/ctl/master/resume_relay.go b/dm/ctl/master/resume_relay.go index 54ac1e89ac..cfd7a2c658 100644 --- a/dm/ctl/master/resume_relay.go +++ b/dm/ctl/master/resume_relay.go @@ -17,11 +17,11 @@ import ( "fmt" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewResumeRelayCmd creates a ResumeRelay command @@ -44,7 +44,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } if len(sources) == 0 { @@ -54,7 +54,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) { resp, err := common.OperateRelay(pb.RelayOp_ResumeRelay, sources) if err != nil { - common.PrintLines("can not resume relay unit:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not resume relay unit:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/resume_task.go b/dm/ctl/master/resume_task.go index 86c8c150cb..70a3dc34a6 100644 --- a/dm/ctl/master/resume_task.go +++ b/dm/ctl/master/resume_task.go @@ -16,11 +16,11 @@ package master import ( "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewResumeTaskCmd creates a ResumeTask command @@ -44,13 +44,13 @@ func resumeTaskFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } resp, err := common.OperateTask(pb.TaskOp_Resume, name, sources) if err != nil { - common.PrintLines("can not resume task %s:\n%v", name, errors.ErrorStack(err)) + common.PrintLines("can not resume task %s:\n%v", name, terror.Message(err)) return } diff --git a/dm/ctl/master/show_ddl_locks.go b/dm/ctl/master/show_ddl_locks.go index fcc5b02c4a..1ec231dd2c 100644 --- a/dm/ctl/master/show_ddl_locks.go +++ b/dm/ctl/master/show_ddl_locks.go @@ -19,8 +19,8 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" - "github.com/pingcap/errors" "github.com/spf13/cobra" ) @@ -45,7 +45,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } @@ -57,7 +57,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, errors.ErrorStack(err)) + common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, terror.Message(err)) return } diff --git a/dm/ctl/master/sql_inject.go b/dm/ctl/master/sql_inject.go index 5345c6d323..64a549b94d 100644 --- a/dm/ctl/master/sql_inject.go +++ b/dm/ctl/master/sql_inject.go @@ -18,11 +18,11 @@ import ( "os" "strings" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewSQLInjectCmd creates a SQLInject command @@ -45,7 +45,7 @@ func sqlInjectFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } if len(sources) != 1 { @@ -62,13 +62,13 @@ func sqlInjectFunc(cmd *cobra.Command, _ []string) { extraArgs := cmd.Flags().Args()[1:] realSQLs, err := common.ExtractSQLsFromArgs(extraArgs) if err != nil { - common.PrintLines("check sqls err %s", errors.ErrorStack(err)) + common.PrintLines("check sqls err %s", terror.Message(err)) return } for _, sql := range realSQLs { isDDL, err2 := common.IsDDL(sql) if err2 != nil { - common.PrintLines("check sql err %s", errors.ErrorStack(err2)) + common.PrintLines("check sql err %s", terror.Message(err2)) return } if !isDDL { @@ -87,7 +87,7 @@ func sqlInjectFunc(cmd *cobra.Command, _ []string) { Source: sources[0], }) if err != nil { - common.PrintLines("can not inject sql:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not inject sql:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/sql_replace.go b/dm/ctl/master/sql_replace.go index 83a1ec0341..063cb98eb5 100644 --- a/dm/ctl/master/sql_replace.go +++ b/dm/ctl/master/sql_replace.go @@ -20,8 +20,8 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" - "github.com/pingcap/errors" "github.com/spf13/cobra" ) @@ -55,7 +55,7 @@ func sqlReplaceFunc(cmd *cobra.Command, _ []string) { var source string sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } if sharding { @@ -79,7 +79,7 @@ func sqlReplaceFunc(cmd *cobra.Command, _ []string) { extraArgs := cmd.Flags().Args()[1:] realSQLs, err := common.ExtractSQLsFromArgs(extraArgs) if err != nil { - common.PrintLines("check SQLs error: %s", errors.ErrorStack(err)) + common.PrintLines("check SQLs error: %s", terror.Message(err)) return } @@ -96,7 +96,7 @@ func sqlReplaceFunc(cmd *cobra.Command, _ []string) { Sharding: sharding, }) if err != nil { - common.PrintLines("can not replace SQL:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not replace SQL:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/sql_skip.go b/dm/ctl/master/sql_skip.go index 89d49037df..76ec278f62 100644 --- a/dm/ctl/master/sql_skip.go +++ b/dm/ctl/master/sql_skip.go @@ -18,11 +18,11 @@ import ( "os" "strings" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewSQLSkipCmd creates a SQLSkip command @@ -55,7 +55,7 @@ func sqlSkipFunc(cmd *cobra.Command, _ []string) { var source string sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } if sharding { @@ -89,7 +89,7 @@ func sqlSkipFunc(cmd *cobra.Command, _ []string) { Sharding: sharding, }) if err != nil { - common.PrintLines("can not skip SQL:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not skip SQL:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/start_task.go b/dm/ctl/master/start_task.go index 0335d24e6b..420480413b 100644 --- a/dm/ctl/master/start_task.go +++ b/dm/ctl/master/start_task.go @@ -17,7 +17,6 @@ import ( "context" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/checker" @@ -46,13 +45,13 @@ func startTaskFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get file content error:\n%v", terror.Message(err)) return } sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } @@ -73,7 +72,7 @@ func startTaskFunc(cmd *cobra.Command, _ []string) { RemoveMeta: removeMeta, }) if err != nil { - common.PrintLines("can not start task:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not start task:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/stop_task.go b/dm/ctl/master/stop_task.go index f4babf9ff0..6993e91b06 100644 --- a/dm/ctl/master/stop_task.go +++ b/dm/ctl/master/stop_task.go @@ -16,11 +16,11 @@ package master import ( "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewStopTaskCmd creates a StopTask command @@ -44,13 +44,13 @@ func stopTaskFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } resp, err := common.OperateTask(pb.TaskOp_Stop, name, sources) if err != nil { - common.PrintLines("can not stop task %s:\n%v", name, errors.ErrorStack(err)) + common.PrintLines("can not stop task %s:\n%v", name, terror.Message(err)) return } diff --git a/dm/ctl/master/switch_relay_master.go b/dm/ctl/master/switch_relay_master.go index 320c4a5c03..eebd93c4d1 100644 --- a/dm/ctl/master/switch_relay_master.go +++ b/dm/ctl/master/switch_relay_master.go @@ -18,11 +18,11 @@ import ( "fmt" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewSwitchRelayMasterCmd creates a SwitchRelayMaster command @@ -45,7 +45,7 @@ func switchRelayMasterFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - fmt.Println(errors.ErrorStack(err)) + fmt.Println(terror.Message(err)) return } if len(sources) == 0 { @@ -60,7 +60,7 @@ func switchRelayMasterFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not switch relay's master server (in sources %v):\n%s", sources, errors.ErrorStack(err)) + common.PrintLines("can not switch relay's master server (in sources %v):\n%s", sources, terror.Message(err)) return } diff --git a/dm/ctl/master/unlock_ddl_lock.go b/dm/ctl/master/unlock_ddl_lock.go index cf4c3244ed..12fae8decc 100644 --- a/dm/ctl/master/unlock_ddl_lock.go +++ b/dm/ctl/master/unlock_ddl_lock.go @@ -20,8 +20,8 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" - "github.com/pingcap/errors" "github.com/spf13/cobra" ) @@ -46,7 +46,7 @@ func unlockDDLLockFunc(cmd *cobra.Command, _ []string) { } owner, err := cmd.Flags().GetString("owner") if err != nil { - fmt.Println(errors.ErrorStack(err)) + fmt.Println(terror.Message(err)) return } @@ -60,7 +60,7 @@ func unlockDDLLockFunc(cmd *cobra.Command, _ []string) { forceRemove, err := cmd.Flags().GetBool("force-remove") if err != nil { - fmt.Println(errors.ErrorStack(err)) + fmt.Println(terror.Message(err)) return } diff --git a/dm/ctl/master/update_masterconfig.go b/dm/ctl/master/update_masterconfig.go index 9a533d6895..322ffe76d4 100644 --- a/dm/ctl/master/update_masterconfig.go +++ b/dm/ctl/master/update_masterconfig.go @@ -19,8 +19,8 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" - "github.com/pingcap/errors" "github.com/spf13/cobra" ) @@ -42,7 +42,7 @@ func updateMasterConfigFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get file content error:\n%v", terror.Message(err)) return } @@ -54,7 +54,7 @@ func updateMasterConfigFunc(cmd *cobra.Command, _ []string) { Config: string(content), }) if err != nil { - common.PrintLines("can not update master config:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not update master config:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/update_relay.go b/dm/ctl/master/update_relay.go index 4ebf28dc0d..a584204d7a 100644 --- a/dm/ctl/master/update_relay.go +++ b/dm/ctl/master/update_relay.go @@ -18,11 +18,11 @@ import ( "fmt" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewUpdateRelayCmd creates a UpdateRelay command @@ -45,7 +45,7 @@ func updateRelayFunc(cmd *cobra.Command, _ []string) { content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get file content error:\n%v", terror.Message(err)) return } @@ -65,7 +65,7 @@ func updateRelayFunc(cmd *cobra.Command, _ []string) { }) if err != nil { - common.PrintLines("can not update relay config:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not update relay config:\n%v", terror.Message(err)) return } diff --git a/dm/ctl/master/update_task.go b/dm/ctl/master/update_task.go index bd30e4b6b7..2a8108c5bb 100644 --- a/dm/ctl/master/update_task.go +++ b/dm/ctl/master/update_task.go @@ -17,12 +17,12 @@ import ( "context" "os" - "github.com/pingcap/errors" "github.com/spf13/cobra" "github.com/pingcap/dm/checker" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" + "github.com/pingcap/dm/pkg/terror" ) // NewUpdateTaskCmd creates a UpdateTask command @@ -44,13 +44,13 @@ func updateTaskFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", errors.ErrorStack(err)) + common.PrintLines("get file content error:\n%v", terror.Message(err)) return } sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", errors.ErrorStack(err)) + common.PrintLines("%s", terror.Message(err)) return } @@ -64,7 +64,7 @@ func updateTaskFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not update task:\n%v", errors.ErrorStack(err)) + common.PrintLines("can not update task:\n%v", terror.Message(err)) return } diff --git a/dm/master/scheduler/scheduler.go b/dm/master/scheduler/scheduler.go index 1ae480bdb8..0fa038abd8 100644 --- a/dm/master/scheduler/scheduler.go +++ b/dm/master/scheduler/scheduler.go @@ -561,7 +561,7 @@ func (s *Scheduler) RemoveWorker(name string) error { if !ok { return terror.ErrSchedulerWorkerNotExist.Generate(name) } else if w.Stage() != WorkerOffline { - return terror.ErrSchedulerWorkerOnline.Generate() + return terror.ErrSchedulerWorkerOnline.Generate(name) } // delete the info in etcd. From f84068d3f7d64fd03b765ce96825803156ea1b31 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Tue, 16 Jun 2020 09:09:35 -0400 Subject: [PATCH 02/11] remove stack err msg of response msg --- dm/ctl/master/offline_member.go | 1 + dm/master/server.go | 64 ++++++++++++++++----------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/dm/ctl/master/offline_member.go b/dm/ctl/master/offline_member.go index 7a3f8dafb8..258f5eadd5 100644 --- a/dm/ctl/master/offline_member.go +++ b/dm/ctl/master/offline_member.go @@ -91,6 +91,7 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) { } if !resp.Result { common.PrintLines("offline member failed:\n%v", resp.Msg) + return } common.PrettyPrintResponse(resp) } diff --git a/dm/master/server.go b/dm/master/server.go index 4271db7221..1f43d25778 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -281,7 +281,7 @@ func (s *Server) RegisterWorker(ctx context.Context, req *pb.RegisterWorkerReque if err != nil { return &pb.RegisterWorkerResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), }, nil } log.L().Info("register worker successfully", zap.String("name", req.Name), zap.String("address", req.Address)) @@ -310,7 +310,7 @@ func (s *Server) OfflineMember(ctx context.Context, req *pb.OfflineMemberRequest if err != nil { return &pb.OfflineMemberResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), }, nil } } else if req.Type == common.Master { @@ -318,7 +318,7 @@ func (s *Server) OfflineMember(ctx context.Context, req *pb.OfflineMemberRequest if err != nil { return &pb.OfflineMemberResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), }, nil } } else { @@ -383,7 +383,7 @@ func (s *Server) StartTask(ctx context.Context, req *pb.StartTaskRequest) (*pb.S resp := &pb.StartTaskResponse{} cfg, stCfgs, err := s.generateSubTask(ctx, req.Task) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } log.L().Info("", zap.String("task name", cfg.Name), zap.Stringer("task", cfg), zap.String("request", "StartTask")) @@ -432,7 +432,7 @@ func (s *Server) StartTask(ctx context.Context, req *pb.StartTaskRequest) (*pb.S err = s.scheduler.AddSubTasks(subtaskCfgPointersToInstances(stCfgs...)...) s.removeMetaLock.Unlock() if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } resp.Result = true @@ -487,7 +487,7 @@ func (s *Server) OperateTask(ctx context.Context, req *pb.OperateTaskRequest) (* err = s.scheduler.UpdateExpectSubTaskStage(expect, req.Name, sources...) } if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } @@ -513,7 +513,7 @@ func (s *Server) UpdateTask(ctx context.Context, req *pb.UpdateTaskRequest) (*pb if err != nil { return &pb.UpdateTaskResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), }, nil } log.L().Info("update task", zap.String("task name", cfg.Name), zap.Stringer("task", cfg)) @@ -777,7 +777,7 @@ func (s *Server) HandleSQLs(ctx context.Context, req *pb.HandleSQLsRequest) (*pb if err != nil { return &pb.HandleSQLsResponse{ Result: false, - Msg: fmt.Sprintf("save request with --sharding error:\n%s", errors.ErrorStack(err)), + Msg: fmt.Sprintf("save request with --sharding error:\n%s", terror.Message(err)), }, nil } log.L().Info("handle sqls request was saved", zap.String("task name", req.Name), zap.String("request", "HandleSQLs")) @@ -816,7 +816,7 @@ func (s *Server) HandleSQLs(ctx context.Context, req *pb.HandleSQLsRequest) (*pb response, err := worker.SendRequest(ctx, subReq, s.cfg.RPCTimeout) workerResp := &pb.CommonWorkerResponse{} if err != nil { - workerResp = errorCommonWorkerResponse(errors.ErrorStack(err), req.Source, worker.BaseInfo().Name) + workerResp = errorCommonWorkerResponse(terror.Message(err), req.Source, worker.BaseInfo().Name) } else { workerResp = response.HandleSubTaskSQLs } @@ -861,7 +861,7 @@ func (s *Server) PurgeWorkerRelay(ctx context.Context, req *pb.PurgeWorkerRelayR resp, err := worker.SendRequest(ctx, workerReq, s.cfg.RPCTimeout) workerResp := &pb.CommonWorkerResponse{} if err != nil { - workerResp = errorCommonWorkerResponse(errors.ErrorStack(err), source, worker.BaseInfo().Name) + workerResp = errorCommonWorkerResponse(terror.Message(err), source, worker.BaseInfo().Name) } else { workerResp = resp.PurgeRelay } @@ -905,7 +905,7 @@ func (s *Server) SwitchWorkerRelayMaster(ctx context.Context, req *pb.SwitchWork handleErr := func(err error, source string) { log.L().Error("response error", zap.Error(err)) - resp := errorCommonWorkerResponse(errors.ErrorStack(err), source, "") + resp := errorCommonWorkerResponse(terror.Message(err), source, "") workerRespCh <- resp } @@ -928,7 +928,7 @@ func (s *Server) SwitchWorkerRelayMaster(ctx context.Context, req *pb.SwitchWork resp, err := worker.SendRequest(ctx, request, s.cfg.RPCTimeout) workerResp := &pb.CommonWorkerResponse{} if err != nil { - workerResp = errorCommonWorkerResponse(errors.ErrorStack(err), sourceID, worker.BaseInfo().Name) + workerResp = errorCommonWorkerResponse(terror.Message(err), sourceID, worker.BaseInfo().Name) } else { workerResp = resp.SwitchRelayMaster } @@ -987,7 +987,7 @@ func (s *Server) OperateWorkerRelayTask(ctx context.Context, req *pb.OperateWork } err := s.scheduler.UpdateExpectRelayStage(expect, req.Sources...) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } resp.Result = true @@ -1020,7 +1020,7 @@ func (s *Server) getStatusFromWorkers(ctx context.Context, sources []string, tas log.L().Error("response error", zap.Error(err)) resp := &pb.QueryStatusResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), SourceStatus: &pb.SourceStatus{ Source: source, }, @@ -1046,7 +1046,7 @@ func (s *Server) getStatusFromWorkers(ctx context.Context, sources []string, tas if err != nil { workerStatus = &pb.QueryStatusResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), SourceStatus: &pb.SourceStatus{}, } } else { @@ -1076,7 +1076,7 @@ func (s *Server) getErrorFromWorkers(ctx context.Context, sources []string, task log.L().Error("response error", zap.Error(err)) resp := &pb.QueryErrorResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), SourceError: &pb.SourceError{ Source: source, }, @@ -1103,7 +1103,7 @@ func (s *Server) getErrorFromWorkers(ctx context.Context, sources []string, task if err != nil { workerError = &pb.QueryErrorResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), SourceError: &pb.SourceError{}, } } else { @@ -1154,7 +1154,7 @@ func (s *Server) UpdateMasterConfig(ctx context.Context, req *pb.UpdateMasterCon s.Unlock() return &pb.UpdateMasterConfigResponse{ Result: false, - Msg: "Failed to write config to local file. detail: " + errors.ErrorStack(err), + Msg: "Failed to write config to local file. detail: " + terror.Message(err), }, nil } log.L().Info("saved dm-master config file", zap.String("config file", s.cfg.ConfigFile), zap.String("request", "UpdateMasterConfig")) @@ -1166,7 +1166,7 @@ func (s *Server) UpdateMasterConfig(ctx context.Context, req *pb.UpdateMasterCon s.Unlock() return &pb.UpdateMasterConfigResponse{ Result: false, - Msg: fmt.Sprintf("Failed to parse configure from file %s, detail: ", cfg.ConfigFile) + errors.ErrorStack(err), + Msg: fmt.Sprintf("Failed to parse configure from file %s, detail: ", cfg.ConfigFile) + terror.Message(err), }, nil } log.L().Info("update dm-master config", zap.Stringer("config", cfg), zap.String("request", "UpdateMasterConfig")) @@ -1205,7 +1205,7 @@ func (s *Server) UpdateWorkerRelayConfig(ctx context.Context, req *pb.UpdateWork } resp, err := worker.SendRequest(ctx, request, s.cfg.RPCTimeout) if err != nil { - return errorCommonWorkerResponse(errors.ErrorStack(err), source, worker.BaseInfo().Name), nil + return errorCommonWorkerResponse(terror.Message(err), source, worker.BaseInfo().Name), nil } return resp.UpdateRelay, nil } @@ -1249,7 +1249,7 @@ func (s *Server) MigrateWorkerRelay(ctx context.Context, req *pb.MigrateWorkerRe } resp, err := worker.SendRequest(ctx, request, s.cfg.RPCTimeout) if err != nil { - return errorCommonWorkerResponse(errors.ErrorStack(err), source, worker.BaseInfo().Name), nil + return errorCommonWorkerResponse(terror.Message(err), source, worker.BaseInfo().Name), nil } return resp.MigrateRelay, nil } @@ -1270,7 +1270,7 @@ func (s *Server) CheckTask(ctx context.Context, req *pb.CheckTaskRequest) (*pb.C if err != nil { return &pb.CheckTaskResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: terror.Message(err), }, nil } @@ -1317,7 +1317,7 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest Result: false, } if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } var w *scheduler.Worker @@ -1325,7 +1325,7 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest case pb.SourceOp_StartSource: err := s.scheduler.AddSourceCfg(*cfg) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } // for start source, we should get worker after start source @@ -1338,7 +1338,7 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest w = s.scheduler.GetWorkerBySource(cfg.SourceID) err := s.scheduler.RemoveSourceCfg(cfg.SourceID) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } default: @@ -1632,7 +1632,7 @@ func (s *Server) handleOperationResult(ctx context.Context, cli *scheduler.Worke var response *pb.CommonWorkerResponse queryResp, err := s.waitOperationOk(ctx, cli, taskName, sourceID, req) if err != nil { - response = errorCommonWorkerResponse(errors.ErrorStack(err), sourceID, cli.BaseInfo().Name) + response = errorCommonWorkerResponse(terror.Message(err), sourceID, cli.BaseInfo().Name) } else { response = &pb.CommonWorkerResponse{ Result: true, @@ -1699,7 +1699,7 @@ func (s *Server) listMemberMaster(ctx context.Context, names []string) (*pb.Memb memberList, err := s.etcdClient.MemberList(ctx) if err != nil { - resp.Master.Msg = errors.ErrorStack(err) + resp.Master.Msg = terror.Message(err) return resp, nil } @@ -1749,7 +1749,7 @@ func (s *Server) listMemberWorker(ctx context.Context, names []string) (*pb.Memb workerAgents, err := s.scheduler.GetAllWorkers() if err != nil { - resp.Worker.Msg = errors.ErrorStack(err) + resp.Worker.Msg = terror.Message(err) return resp, nil } @@ -1794,7 +1794,7 @@ func (s *Server) listMemberLeader(ctx context.Context, names []string) (*pb.Memb _, name, addr, err := s.election.LeaderInfo(ctx) if err != nil { - resp.Leader.Msg = errors.ErrorStack(err) + resp.Leader.Msg = terror.Message(err) return resp, nil } @@ -1831,7 +1831,7 @@ func (s *Server) ListMember(ctx context.Context, req *pb.ListMemberRequest) (*pb if req.Leader { res, err := s.listMemberLeader(ctx, req.Names) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } members = append(members, &pb.Members{ @@ -1842,7 +1842,7 @@ func (s *Server) ListMember(ctx context.Context, req *pb.ListMemberRequest) (*pb if req.Master { res, err := s.listMemberMaster(ctx, req.Names) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } members = append(members, &pb.Members{ @@ -1853,7 +1853,7 @@ func (s *Server) ListMember(ctx context.Context, req *pb.ListMemberRequest) (*pb if req.Worker { res, err := s.listMemberWorker(ctx, req.Names) if err != nil { - resp.Msg = errors.ErrorStack(err) + resp.Msg = terror.Message(err) return resp, nil } members = append(members, &pb.Members{ From 9dabcf50d69e024e07a8c0c1953cd599a9a41e19 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Tue, 16 Jun 2020 09:35:25 -0400 Subject: [PATCH 03/11] test --- tests/all_mode/run.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/all_mode/run.sh b/tests/all_mode/run.sh index 6b93446917..51ee2a2255 100755 --- a/tests/all_mode/run.sh +++ b/tests/all_mode/run.sh @@ -131,6 +131,10 @@ function run() { run_tidb_server 4000 $TIDB_PASSWORD sleep 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "fail fail fail" 1 + # use sync_diff_inspector to check data now! check_sync_diff $WORK_DIR $cur/conf/diff_config.toml From ffea03464e117531b104225ab3e78770c9e8495f Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Tue, 16 Jun 2020 09:55:05 -0400 Subject: [PATCH 04/11] sleep more time --- tests/all_mode/run.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/all_mode/run.sh b/tests/all_mode/run.sh index 51ee2a2255..1d29425fed 100755 --- a/tests/all_mode/run.sh +++ b/tests/all_mode/run.sh @@ -129,11 +129,7 @@ function run() { # restart tidb, and task will recover success run_tidb_server 4000 $TIDB_PASSWORD - sleep 2 - - run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "query-status test" \ - "fail fail fail" 1 + sleep 10 # use sync_diff_inspector to check data now! check_sync_diff $WORK_DIR $cur/conf/diff_config.toml From 21854ad4c53cf06274de25cc9ceb94a42b657fd8 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Tue, 16 Jun 2020 11:33:34 -0400 Subject: [PATCH 05/11] Revert "sleep more time" This reverts commit ffea03464e117531b104225ab3e78770c9e8495f. --- tests/all_mode/run.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/all_mode/run.sh b/tests/all_mode/run.sh index 1d29425fed..51ee2a2255 100755 --- a/tests/all_mode/run.sh +++ b/tests/all_mode/run.sh @@ -129,7 +129,11 @@ function run() { # restart tidb, and task will recover success run_tidb_server 4000 $TIDB_PASSWORD - sleep 10 + sleep 2 + + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "fail fail fail" 1 # use sync_diff_inspector to check data now! check_sync_diff $WORK_DIR $cur/conf/diff_config.toml From f222c0480052417653dad1ac7acd0da6961beed5 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Tue, 16 Jun 2020 11:34:00 -0400 Subject: [PATCH 06/11] Revert "test" This reverts commit 9dabcf50d69e024e07a8c0c1953cd599a9a41e19. --- tests/all_mode/run.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/all_mode/run.sh b/tests/all_mode/run.sh index 51ee2a2255..6b93446917 100755 --- a/tests/all_mode/run.sh +++ b/tests/all_mode/run.sh @@ -131,10 +131,6 @@ function run() { run_tidb_server 4000 $TIDB_PASSWORD sleep 2 - run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "query-status test" \ - "fail fail fail" 1 - # use sync_diff_inspector to check data now! check_sync_diff $WORK_DIR $cur/conf/diff_config.toml From ea58a8e61dee31f002a82aad49b60491f80375a7 Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Wed, 17 Jun 2020 00:57:08 -0400 Subject: [PATCH 07/11] print err directly --- dm/ctl/master/check_task.go | 5 ++--- dm/ctl/master/list_member.go | 5 ++--- dm/ctl/master/migrate_relay.go | 3 +-- dm/ctl/master/offline_member.go | 7 +++---- dm/ctl/master/operate_leader.go | 3 +-- dm/ctl/master/operate_source.go | 5 ++--- dm/ctl/master/pause_relay.go | 5 ++--- dm/ctl/master/pause_task.go | 5 ++--- dm/ctl/master/purge_relay.go | 5 ++--- dm/ctl/master/query_error.go | 5 ++--- dm/ctl/master/query_status.go | 7 +++---- dm/ctl/master/resume_relay.go | 5 ++--- dm/ctl/master/resume_task.go | 5 ++--- dm/ctl/master/show_ddl_locks.go | 5 ++--- dm/ctl/master/sql_inject.go | 9 ++++----- dm/ctl/master/sql_replace.go | 7 +++---- dm/ctl/master/sql_skip.go | 5 ++--- dm/ctl/master/start_task.go | 9 ++++----- dm/ctl/master/stop_task.go | 5 ++--- dm/ctl/master/switch_relay_master.go | 5 ++--- dm/ctl/master/unlock_ddl_lock.go | 5 ++--- dm/ctl/master/update_masterconfig.go | 5 ++--- dm/ctl/master/update_relay.go | 5 ++--- dm/ctl/master/update_task.go | 7 +++---- 24 files changed, 54 insertions(+), 78 deletions(-) diff --git a/dm/ctl/master/check_task.go b/dm/ctl/master/check_task.go index 532db370bf..c73fb26fac 100644 --- a/dm/ctl/master/check_task.go +++ b/dm/ctl/master/check_task.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/checker" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewCheckTaskCmd creates a CheckTask command @@ -44,7 +43,7 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", terror.Message(err)) + common.PrintLines("get file content error:\n%v", err) return } @@ -57,7 +56,7 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) { Task: string(content), }) if err != nil { - common.PrintLines("fail to check task:\n%v", terror.Message(err)) + common.PrintLines("fail to check task:\n%v", err) return } diff --git a/dm/ctl/master/list_member.go b/dm/ctl/master/list_member.go index 30dd8a2c1c..dc0cbe848b 100644 --- a/dm/ctl/master/list_member.go +++ b/dm/ctl/master/list_member.go @@ -21,7 +21,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) var ( @@ -73,7 +72,7 @@ func listMemberFunc(cmd *cobra.Command, _ []string) { leader, master, worker, err := convertListMemberType(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) } ctx, cancel := context.WithCancel(context.Background()) @@ -88,7 +87,7 @@ func listMemberFunc(cmd *cobra.Command, _ []string) { }) if err != nil { - common.PrintLines("list member failed, error:\n%v", terror.Message(err)) + common.PrintLines("list member failed, error:\n%v", err) return } common.PrettyPrintResponse(resp) diff --git a/dm/ctl/master/migrate_relay.go b/dm/ctl/master/migrate_relay.go index 7c2a94872d..f753df16ba 100644 --- a/dm/ctl/master/migrate_relay.go +++ b/dm/ctl/master/migrate_relay.go @@ -24,7 +24,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" "github.com/pingcap/dm/pkg/log" - "github.com/pingcap/dm/pkg/terror" ) // NewMigrateRelayCmd creates a MigrateRelay command @@ -49,7 +48,7 @@ func migrateRelayFunc(cmd *cobra.Command, _ []string) { binlogName := cmd.Flags().Arg(1) binlogPos, err := strconv.Atoi(cmd.Flags().Arg(2)) if err != nil { - common.PrintLines(terror.Message(err)) + common.PrintLines("%v", err) } ctx, cancel := context.WithCancel(context.Background()) diff --git a/dm/ctl/master/offline_member.go b/dm/ctl/master/offline_member.go index 258f5eadd5..69959cac80 100644 --- a/dm/ctl/master/offline_member.go +++ b/dm/ctl/master/offline_member.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/pingcap/errors" "github.com/spf13/cobra" @@ -66,12 +65,12 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) { offlineType, err := convertOfflineMemberType(cmd) if err != nil { - common.PrintLines("get offline type failed, error:\n%v", terror.Message(err)) + common.PrintLines("get offline type failed, error:\n%v", err) return } name, err := cmd.Flags().GetString("name") if err != nil { - common.PrintLines("get offline name failed, error:\n%v", terror.Message(err)) + common.PrintLines("get offline name failed, error:\n%v", err) return } else if name == "" { common.PrintLines("a member name must be specified") @@ -86,7 +85,7 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) { Name: name, }) if err != nil { - common.PrintLines("offline member failed, error:\n%v", terror.Message(err)) + common.PrintLines("offline member failed, error:\n%v", err) return } if !resp.Result { diff --git a/dm/ctl/master/operate_leader.go b/dm/ctl/master/operate_leader.go index 75015ca810..9af88bffe8 100644 --- a/dm/ctl/master/operate_leader.go +++ b/dm/ctl/master/operate_leader.go @@ -21,7 +21,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewOperateLeaderCmd creates a OperateLeader command @@ -70,7 +69,7 @@ func operateLeaderFunc(cmd *cobra.Command, _ []string) { Op: op, }) if err != nil { - common.PrintLines("fail to operate leader:\n%v", terror.Message(err)) + common.PrintLines("fail to operate leader:\n%v", err) return } diff --git a/dm/ctl/master/operate_source.go b/dm/ctl/master/operate_source.go index fea4837a1c..ee97cbac6c 100644 --- a/dm/ctl/master/operate_source.go +++ b/dm/ctl/master/operate_source.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/spf13/cobra" ) @@ -59,7 +58,7 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) { configFile := cmd.Flags().Arg(1) content, err := common.GetFileContent(configFile) if err != nil { - common.PrintLines("get file content error:\n%v", terror.Message(err)) + common.PrintLines("get file content error:\n%v", err) return } ctx, cancel := context.WithCancel(context.Background()) @@ -77,7 +76,7 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) { Op: op, }) if err != nil { - common.PrintLines("can not update task:\n%v", terror.Message(err)) + common.PrintLines("can not update task:\n%v", err) return } diff --git a/dm/ctl/master/pause_relay.go b/dm/ctl/master/pause_relay.go index 35a5deb39c..f0c4e41965 100644 --- a/dm/ctl/master/pause_relay.go +++ b/dm/ctl/master/pause_relay.go @@ -21,7 +21,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewPauseRelayCmd creates a PauseRelay command @@ -44,7 +43,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } if len(sources) == 0 { @@ -54,7 +53,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) { resp, err := common.OperateRelay(pb.RelayOp_PauseRelay, sources) if err != nil { - common.PrintLines("can not pause relay unit:\n%v", terror.Message(err)) + common.PrintLines("can not pause relay unit:\n%v", err) return } diff --git a/dm/ctl/master/pause_task.go b/dm/ctl/master/pause_task.go index 449e6a4061..88ec1fdabb 100644 --- a/dm/ctl/master/pause_task.go +++ b/dm/ctl/master/pause_task.go @@ -20,7 +20,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewPauseTaskCmd creates a PauseTask command @@ -44,13 +43,13 @@ func pauseTaskFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } resp, err := common.OperateTask(pb.TaskOp_Pause, name, sources) if err != nil { - common.PrintLines("can not pause task %s:\n%v", name, terror.Message(err)) + common.PrintLines("can not pause task %s:\n%v", name, err) return } diff --git a/dm/ctl/master/purge_relay.go b/dm/ctl/master/purge_relay.go index d2d9463847..d8e290e65c 100644 --- a/dm/ctl/master/purge_relay.go +++ b/dm/ctl/master/purge_relay.go @@ -25,7 +25,6 @@ import ( "github.com/pingcap/dm/dm/command" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) var ( @@ -64,7 +63,7 @@ func purgeRelayFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - fmt.Println(terror.Message(err)) + common.PrintLines("%v", err) return } if len(sources) == 0 { @@ -146,7 +145,7 @@ func purgeRelayFunc(cmd *cobra.Command, _ []string) { SubDir: subDir, }) if err != nil { - common.PrintLines("can not purge relay log files: \n%s", terror.Message(err)) + common.PrintLines("can not purge relay log files: \n%v", err) return } diff --git a/dm/ctl/master/query_error.go b/dm/ctl/master/query_error.go index ee12b0447e..859b485ed3 100644 --- a/dm/ctl/master/query_error.go +++ b/dm/ctl/master/query_error.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/spf13/cobra" ) @@ -45,7 +44,7 @@ func queryErrorFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } @@ -64,7 +63,7 @@ func queryErrorFunc(cmd *cobra.Command, _ []string) { if len(sources) > 0 { common.PrintLines("sources: %v", sources) } - common.PrintLines("error: %s", terror.Message(err)) + common.PrintLines("error: %v", err) return } diff --git a/dm/ctl/master/query_status.go b/dm/ctl/master/query_status.go index 0f308ad10c..d5fc3531e8 100644 --- a/dm/ctl/master/query_status.go +++ b/dm/ctl/master/query_status.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) const stageError = "Error" @@ -61,7 +60,7 @@ func queryStatusFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } @@ -73,13 +72,13 @@ func queryStatusFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not query %s task's status(in sources %v):\n%s", taskName, sources, terror.Message(err)) + common.PrintLines("can not query %s task's status(in sources %v):\n%v", taskName, sources, err) return } more, err := cmd.Flags().GetBool("more") if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } diff --git a/dm/ctl/master/resume_relay.go b/dm/ctl/master/resume_relay.go index cfd7a2c658..9de40d7a7d 100644 --- a/dm/ctl/master/resume_relay.go +++ b/dm/ctl/master/resume_relay.go @@ -21,7 +21,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewResumeRelayCmd creates a ResumeRelay command @@ -44,7 +43,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } if len(sources) == 0 { @@ -54,7 +53,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) { resp, err := common.OperateRelay(pb.RelayOp_ResumeRelay, sources) if err != nil { - common.PrintLines("can not resume relay unit:\n%v", terror.Message(err)) + common.PrintLines("can not resume relay unit:\n%v", err) return } diff --git a/dm/ctl/master/resume_task.go b/dm/ctl/master/resume_task.go index 70a3dc34a6..c9711645eb 100644 --- a/dm/ctl/master/resume_task.go +++ b/dm/ctl/master/resume_task.go @@ -20,7 +20,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewResumeTaskCmd creates a ResumeTask command @@ -44,13 +43,13 @@ func resumeTaskFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } resp, err := common.OperateTask(pb.TaskOp_Resume, name, sources) if err != nil { - common.PrintLines("can not resume task %s:\n%v", name, terror.Message(err)) + common.PrintLines("can not resume task %s:\n%v", name, err) return } diff --git a/dm/ctl/master/show_ddl_locks.go b/dm/ctl/master/show_ddl_locks.go index 1ec231dd2c..e7886669f5 100644 --- a/dm/ctl/master/show_ddl_locks.go +++ b/dm/ctl/master/show_ddl_locks.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/spf13/cobra" ) @@ -45,7 +44,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } @@ -57,7 +56,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, terror.Message(err)) + common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, err) return } diff --git a/dm/ctl/master/sql_inject.go b/dm/ctl/master/sql_inject.go index 64a549b94d..de750ea3e2 100644 --- a/dm/ctl/master/sql_inject.go +++ b/dm/ctl/master/sql_inject.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewSQLInjectCmd creates a SQLInject command @@ -45,7 +44,7 @@ func sqlInjectFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } if len(sources) != 1 { @@ -62,13 +61,13 @@ func sqlInjectFunc(cmd *cobra.Command, _ []string) { extraArgs := cmd.Flags().Args()[1:] realSQLs, err := common.ExtractSQLsFromArgs(extraArgs) if err != nil { - common.PrintLines("check sqls err %s", terror.Message(err)) + common.PrintLines("check sqls err %v", err) return } for _, sql := range realSQLs { isDDL, err2 := common.IsDDL(sql) if err2 != nil { - common.PrintLines("check sql err %s", terror.Message(err2)) + common.PrintLines("check sql err %v", err2) return } if !isDDL { @@ -87,7 +86,7 @@ func sqlInjectFunc(cmd *cobra.Command, _ []string) { Source: sources[0], }) if err != nil { - common.PrintLines("can not inject sql:\n%v", terror.Message(err)) + common.PrintLines("can not inject sql:\n%v", err) return } diff --git a/dm/ctl/master/sql_replace.go b/dm/ctl/master/sql_replace.go index 063cb98eb5..aa745c0848 100644 --- a/dm/ctl/master/sql_replace.go +++ b/dm/ctl/master/sql_replace.go @@ -20,7 +20,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/spf13/cobra" ) @@ -55,7 +54,7 @@ func sqlReplaceFunc(cmd *cobra.Command, _ []string) { var source string sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } if sharding { @@ -79,7 +78,7 @@ func sqlReplaceFunc(cmd *cobra.Command, _ []string) { extraArgs := cmd.Flags().Args()[1:] realSQLs, err := common.ExtractSQLsFromArgs(extraArgs) if err != nil { - common.PrintLines("check SQLs error: %s", terror.Message(err)) + common.PrintLines("check SQLs error: %v", err) return } @@ -96,7 +95,7 @@ func sqlReplaceFunc(cmd *cobra.Command, _ []string) { Sharding: sharding, }) if err != nil { - common.PrintLines("can not replace SQL:\n%v", terror.Message(err)) + common.PrintLines("can not replace SQL:\n%v", err) return } diff --git a/dm/ctl/master/sql_skip.go b/dm/ctl/master/sql_skip.go index 76ec278f62..719f279250 100644 --- a/dm/ctl/master/sql_skip.go +++ b/dm/ctl/master/sql_skip.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewSQLSkipCmd creates a SQLSkip command @@ -55,7 +54,7 @@ func sqlSkipFunc(cmd *cobra.Command, _ []string) { var source string sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } if sharding { @@ -89,7 +88,7 @@ func sqlSkipFunc(cmd *cobra.Command, _ []string) { Sharding: sharding, }) if err != nil { - common.PrintLines("can not skip SQL:\n%v", terror.Message(err)) + common.PrintLines("can not skip SQL:\n%v", err) return } diff --git a/dm/ctl/master/start_task.go b/dm/ctl/master/start_task.go index 420480413b..2203920786 100644 --- a/dm/ctl/master/start_task.go +++ b/dm/ctl/master/start_task.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/checker" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewStartTaskCmd creates a StartTask command @@ -45,19 +44,19 @@ func startTaskFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", terror.Message(err)) + common.PrintLines("get file content error:\n%v", err) return } sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } removeMeta, err := cmd.Flags().GetBool("remove-meta") if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } @@ -72,7 +71,7 @@ func startTaskFunc(cmd *cobra.Command, _ []string) { RemoveMeta: removeMeta, }) if err != nil { - common.PrintLines("can not start task:\n%v", terror.Message(err)) + common.PrintLines("can not start task:\n%v", err) return } diff --git a/dm/ctl/master/stop_task.go b/dm/ctl/master/stop_task.go index 6993e91b06..4b82c06274 100644 --- a/dm/ctl/master/stop_task.go +++ b/dm/ctl/master/stop_task.go @@ -20,7 +20,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewStopTaskCmd creates a StopTask command @@ -44,13 +43,13 @@ func stopTaskFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } resp, err := common.OperateTask(pb.TaskOp_Stop, name, sources) if err != nil { - common.PrintLines("can not stop task %s:\n%v", name, terror.Message(err)) + common.PrintLines("can not stop task %s:\n%v", name, err) return } diff --git a/dm/ctl/master/switch_relay_master.go b/dm/ctl/master/switch_relay_master.go index eebd93c4d1..f67469f9b3 100644 --- a/dm/ctl/master/switch_relay_master.go +++ b/dm/ctl/master/switch_relay_master.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewSwitchRelayMasterCmd creates a SwitchRelayMaster command @@ -45,7 +44,7 @@ func switchRelayMasterFunc(cmd *cobra.Command, _ []string) { sources, err := common.GetSourceArgs(cmd) if err != nil { - fmt.Println(terror.Message(err)) + common.PrintLines("%v", err) return } if len(sources) == 0 { @@ -60,7 +59,7 @@ func switchRelayMasterFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not switch relay's master server (in sources %v):\n%s", sources, terror.Message(err)) + common.PrintLines("can not switch relay's master server (in sources %v):\n%v", sources, err) return } diff --git a/dm/ctl/master/unlock_ddl_lock.go b/dm/ctl/master/unlock_ddl_lock.go index 12fae8decc..f181ed33e2 100644 --- a/dm/ctl/master/unlock_ddl_lock.go +++ b/dm/ctl/master/unlock_ddl_lock.go @@ -20,7 +20,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/spf13/cobra" ) @@ -46,7 +45,7 @@ func unlockDDLLockFunc(cmd *cobra.Command, _ []string) { } owner, err := cmd.Flags().GetString("owner") if err != nil { - fmt.Println(terror.Message(err)) + common.PrintLines("%v", err) return } @@ -60,7 +59,7 @@ func unlockDDLLockFunc(cmd *cobra.Command, _ []string) { forceRemove, err := cmd.Flags().GetBool("force-remove") if err != nil { - fmt.Println(terror.Message(err)) + common.PrintLines("%v", err) return } diff --git a/dm/ctl/master/update_masterconfig.go b/dm/ctl/master/update_masterconfig.go index 322ffe76d4..1ddf9621bf 100644 --- a/dm/ctl/master/update_masterconfig.go +++ b/dm/ctl/master/update_masterconfig.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" "github.com/spf13/cobra" ) @@ -42,7 +41,7 @@ func updateMasterConfigFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", terror.Message(err)) + common.PrintLines("get file content error:\n%v", err) return } @@ -54,7 +53,7 @@ func updateMasterConfigFunc(cmd *cobra.Command, _ []string) { Config: string(content), }) if err != nil { - common.PrintLines("can not update master config:\n%v", terror.Message(err)) + common.PrintLines("can not update master config:\n%v", err) return } diff --git a/dm/ctl/master/update_relay.go b/dm/ctl/master/update_relay.go index a584204d7a..4cb840bf24 100644 --- a/dm/ctl/master/update_relay.go +++ b/dm/ctl/master/update_relay.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewUpdateRelayCmd creates a UpdateRelay command @@ -45,7 +44,7 @@ func updateRelayFunc(cmd *cobra.Command, _ []string) { content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", terror.Message(err)) + common.PrintLines("get file content error:\n%v", err) return } @@ -65,7 +64,7 @@ func updateRelayFunc(cmd *cobra.Command, _ []string) { }) if err != nil { - common.PrintLines("can not update relay config:\n%v", terror.Message(err)) + common.PrintLines("can not update relay config:\n%v", err) return } diff --git a/dm/ctl/master/update_task.go b/dm/ctl/master/update_task.go index 2a8108c5bb..6387672320 100644 --- a/dm/ctl/master/update_task.go +++ b/dm/ctl/master/update_task.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/checker" "github.com/pingcap/dm/dm/ctl/common" "github.com/pingcap/dm/dm/pb" - "github.com/pingcap/dm/pkg/terror" ) // NewUpdateTaskCmd creates a UpdateTask command @@ -44,13 +43,13 @@ func updateTaskFunc(cmd *cobra.Command, _ []string) { } content, err := common.GetFileContent(cmd.Flags().Arg(0)) if err != nil { - common.PrintLines("get file content error:\n%v", terror.Message(err)) + common.PrintLines("get file content error:\n%v", err) return } sources, err := common.GetSourceArgs(cmd) if err != nil { - common.PrintLines("%s", terror.Message(err)) + common.PrintLines("%v", err) return } @@ -64,7 +63,7 @@ func updateTaskFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not update task:\n%v", terror.Message(err)) + common.PrintLines("can not update task:\n%v", err) return } From e78ee18e859d66118d24923580600511537288fe Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Wed, 17 Jun 2020 22:25:10 -0400 Subject: [PATCH 08/11] use err.Error() for msg --- dm/command/argument.go | 2 +- dm/master/server.go | 66 +++++++++++++++++++++--------------------- dm/tracer/server.go | 5 ++-- dm/worker/server.go | 8 ++--- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/dm/command/argument.go b/dm/command/argument.go index 4d4e3ccb7e..9a6cdf0166 100644 --- a/dm/command/argument.go +++ b/dm/command/argument.go @@ -50,7 +50,7 @@ func VerifySQLOperateArgs(binlogPosStr, sqlPattern string, sharding bool) (*mysq if len(binlogPosStr) > 0 { pos2, err := binlog.PositionFromStr(binlogPosStr) if err != nil { - return nil, nil, terror.ErrVerifySQLOperateArgs.Generatef("invalid --binlog-pos %s in sql operation: %s", binlogPosStr, terror.Message(err)) + return nil, nil, terror.ErrVerifySQLOperateArgs.Generatef("invalid --binlog-pos %s in sql operation: %v", binlogPosStr, err) } pos = &pos2 } else if len(sqlPattern) > 0 { diff --git a/dm/master/server.go b/dm/master/server.go index 1f43d25778..7ed5063316 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -281,7 +281,7 @@ func (s *Server) RegisterWorker(ctx context.Context, req *pb.RegisterWorkerReque if err != nil { return &pb.RegisterWorkerResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), }, nil } log.L().Info("register worker successfully", zap.String("name", req.Name), zap.String("address", req.Address)) @@ -310,7 +310,7 @@ func (s *Server) OfflineMember(ctx context.Context, req *pb.OfflineMemberRequest if err != nil { return &pb.OfflineMemberResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), }, nil } } else if req.Type == common.Master { @@ -318,7 +318,7 @@ func (s *Server) OfflineMember(ctx context.Context, req *pb.OfflineMemberRequest if err != nil { return &pb.OfflineMemberResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), }, nil } } else { @@ -383,7 +383,7 @@ func (s *Server) StartTask(ctx context.Context, req *pb.StartTaskRequest) (*pb.S resp := &pb.StartTaskResponse{} cfg, stCfgs, err := s.generateSubTask(ctx, req.Task) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } log.L().Info("", zap.String("task name", cfg.Name), zap.Stringer("task", cfg), zap.String("request", "StartTask")) @@ -432,7 +432,7 @@ func (s *Server) StartTask(ctx context.Context, req *pb.StartTaskRequest) (*pb.S err = s.scheduler.AddSubTasks(subtaskCfgPointersToInstances(stCfgs...)...) s.removeMetaLock.Unlock() if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } resp.Result = true @@ -487,7 +487,7 @@ func (s *Server) OperateTask(ctx context.Context, req *pb.OperateTaskRequest) (* err = s.scheduler.UpdateExpectSubTaskStage(expect, req.Name, sources...) } if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } @@ -513,7 +513,7 @@ func (s *Server) UpdateTask(ctx context.Context, req *pb.UpdateTaskRequest) (*pb if err != nil { return &pb.UpdateTaskResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), }, nil } log.L().Info("update task", zap.String("task name", cfg.Name), zap.Stringer("task", cfg)) @@ -753,7 +753,7 @@ func (s *Server) UnlockDDLLock(ctx context.Context, req *pb.UnlockDDLLockRequest err := s.pessimist.UnlockLock(ctx, req.ID, req.ReplaceOwner, req.ForceRemove) if err != nil { resp.Result = false - resp.Msg = terror.Message(err) + resp.Msg = err.Error() } return resp, nil @@ -777,7 +777,7 @@ func (s *Server) HandleSQLs(ctx context.Context, req *pb.HandleSQLsRequest) (*pb if err != nil { return &pb.HandleSQLsResponse{ Result: false, - Msg: fmt.Sprintf("save request with --sharding error:\n%s", terror.Message(err)), + Msg: fmt.Sprintf("save request with --sharding error:\n%v", err), }, nil } log.L().Info("handle sqls request was saved", zap.String("task name", req.Name), zap.String("request", "HandleSQLs")) @@ -816,7 +816,7 @@ func (s *Server) HandleSQLs(ctx context.Context, req *pb.HandleSQLsRequest) (*pb response, err := worker.SendRequest(ctx, subReq, s.cfg.RPCTimeout) workerResp := &pb.CommonWorkerResponse{} if err != nil { - workerResp = errorCommonWorkerResponse(terror.Message(err), req.Source, worker.BaseInfo().Name) + workerResp = errorCommonWorkerResponse(err.Error(), req.Source, worker.BaseInfo().Name) } else { workerResp = response.HandleSubTaskSQLs } @@ -861,7 +861,7 @@ func (s *Server) PurgeWorkerRelay(ctx context.Context, req *pb.PurgeWorkerRelayR resp, err := worker.SendRequest(ctx, workerReq, s.cfg.RPCTimeout) workerResp := &pb.CommonWorkerResponse{} if err != nil { - workerResp = errorCommonWorkerResponse(terror.Message(err), source, worker.BaseInfo().Name) + workerResp = errorCommonWorkerResponse(err.Error(), source, worker.BaseInfo().Name) } else { workerResp = resp.PurgeRelay } @@ -905,7 +905,7 @@ func (s *Server) SwitchWorkerRelayMaster(ctx context.Context, req *pb.SwitchWork handleErr := func(err error, source string) { log.L().Error("response error", zap.Error(err)) - resp := errorCommonWorkerResponse(terror.Message(err), source, "") + resp := errorCommonWorkerResponse(err.Error(), source, "") workerRespCh <- resp } @@ -928,7 +928,7 @@ func (s *Server) SwitchWorkerRelayMaster(ctx context.Context, req *pb.SwitchWork resp, err := worker.SendRequest(ctx, request, s.cfg.RPCTimeout) workerResp := &pb.CommonWorkerResponse{} if err != nil { - workerResp = errorCommonWorkerResponse(terror.Message(err), sourceID, worker.BaseInfo().Name) + workerResp = errorCommonWorkerResponse(err.Error(), sourceID, worker.BaseInfo().Name) } else { workerResp = resp.SwitchRelayMaster } @@ -987,7 +987,7 @@ func (s *Server) OperateWorkerRelayTask(ctx context.Context, req *pb.OperateWork } err := s.scheduler.UpdateExpectRelayStage(expect, req.Sources...) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } resp.Result = true @@ -1020,7 +1020,7 @@ func (s *Server) getStatusFromWorkers(ctx context.Context, sources []string, tas log.L().Error("response error", zap.Error(err)) resp := &pb.QueryStatusResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), SourceStatus: &pb.SourceStatus{ Source: source, }, @@ -1046,7 +1046,7 @@ func (s *Server) getStatusFromWorkers(ctx context.Context, sources []string, tas if err != nil { workerStatus = &pb.QueryStatusResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), SourceStatus: &pb.SourceStatus{}, } } else { @@ -1076,7 +1076,7 @@ func (s *Server) getErrorFromWorkers(ctx context.Context, sources []string, task log.L().Error("response error", zap.Error(err)) resp := &pb.QueryErrorResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), SourceError: &pb.SourceError{ Source: source, }, @@ -1103,7 +1103,7 @@ func (s *Server) getErrorFromWorkers(ctx context.Context, sources []string, task if err != nil { workerError = &pb.QueryErrorResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), SourceError: &pb.SourceError{}, } } else { @@ -1154,7 +1154,7 @@ func (s *Server) UpdateMasterConfig(ctx context.Context, req *pb.UpdateMasterCon s.Unlock() return &pb.UpdateMasterConfigResponse{ Result: false, - Msg: "Failed to write config to local file. detail: " + terror.Message(err), + Msg: "Failed to write config to local file. detail: " + err.Error(), }, nil } log.L().Info("saved dm-master config file", zap.String("config file", s.cfg.ConfigFile), zap.String("request", "UpdateMasterConfig")) @@ -1166,7 +1166,7 @@ func (s *Server) UpdateMasterConfig(ctx context.Context, req *pb.UpdateMasterCon s.Unlock() return &pb.UpdateMasterConfigResponse{ Result: false, - Msg: fmt.Sprintf("Failed to parse configure from file %s, detail: ", cfg.ConfigFile) + terror.Message(err), + Msg: fmt.Sprintf("Failed to parse configure from file %s, detail: ", cfg.ConfigFile) + err.Error(), }, nil } log.L().Info("update dm-master config", zap.Stringer("config", cfg), zap.String("request", "UpdateMasterConfig")) @@ -1205,7 +1205,7 @@ func (s *Server) UpdateWorkerRelayConfig(ctx context.Context, req *pb.UpdateWork } resp, err := worker.SendRequest(ctx, request, s.cfg.RPCTimeout) if err != nil { - return errorCommonWorkerResponse(terror.Message(err), source, worker.BaseInfo().Name), nil + return errorCommonWorkerResponse(err.Error(), source, worker.BaseInfo().Name), nil } return resp.UpdateRelay, nil } @@ -1249,7 +1249,7 @@ func (s *Server) MigrateWorkerRelay(ctx context.Context, req *pb.MigrateWorkerRe } resp, err := worker.SendRequest(ctx, request, s.cfg.RPCTimeout) if err != nil { - return errorCommonWorkerResponse(terror.Message(err), source, worker.BaseInfo().Name), nil + return errorCommonWorkerResponse(err.Error(), source, worker.BaseInfo().Name), nil } return resp.MigrateRelay, nil } @@ -1270,7 +1270,7 @@ func (s *Server) CheckTask(ctx context.Context, req *pb.CheckTaskRequest) (*pb.C if err != nil { return &pb.CheckTaskResponse{ Result: false, - Msg: terror.Message(err), + Msg: err.Error(), }, nil } @@ -1317,7 +1317,7 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest Result: false, } if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } var w *scheduler.Worker @@ -1325,7 +1325,7 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest case pb.SourceOp_StartSource: err := s.scheduler.AddSourceCfg(*cfg) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } // for start source, we should get worker after start source @@ -1338,7 +1338,7 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest w = s.scheduler.GetWorkerBySource(cfg.SourceID) err := s.scheduler.RemoveSourceCfg(cfg.SourceID) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } default: @@ -1632,7 +1632,7 @@ func (s *Server) handleOperationResult(ctx context.Context, cli *scheduler.Worke var response *pb.CommonWorkerResponse queryResp, err := s.waitOperationOk(ctx, cli, taskName, sourceID, req) if err != nil { - response = errorCommonWorkerResponse(terror.Message(err), sourceID, cli.BaseInfo().Name) + response = errorCommonWorkerResponse(err.Error(), sourceID, cli.BaseInfo().Name) } else { response = &pb.CommonWorkerResponse{ Result: true, @@ -1699,7 +1699,7 @@ func (s *Server) listMemberMaster(ctx context.Context, names []string) (*pb.Memb memberList, err := s.etcdClient.MemberList(ctx) if err != nil { - resp.Master.Msg = terror.Message(err) + resp.Master.Msg = err.Error() return resp, nil } @@ -1749,7 +1749,7 @@ func (s *Server) listMemberWorker(ctx context.Context, names []string) (*pb.Memb workerAgents, err := s.scheduler.GetAllWorkers() if err != nil { - resp.Worker.Msg = terror.Message(err) + resp.Worker.Msg = err.Error() return resp, nil } @@ -1794,7 +1794,7 @@ func (s *Server) listMemberLeader(ctx context.Context, names []string) (*pb.Memb _, name, addr, err := s.election.LeaderInfo(ctx) if err != nil { - resp.Leader.Msg = terror.Message(err) + resp.Leader.Msg = err.Error() return resp, nil } @@ -1831,7 +1831,7 @@ func (s *Server) ListMember(ctx context.Context, req *pb.ListMemberRequest) (*pb if req.Leader { res, err := s.listMemberLeader(ctx, req.Names) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } members = append(members, &pb.Members{ @@ -1842,7 +1842,7 @@ func (s *Server) ListMember(ctx context.Context, req *pb.ListMemberRequest) (*pb if req.Master { res, err := s.listMemberMaster(ctx, req.Names) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } members = append(members, &pb.Members{ @@ -1853,7 +1853,7 @@ func (s *Server) ListMember(ctx context.Context, req *pb.ListMemberRequest) (*pb if req.Worker { res, err := s.listMemberWorker(ctx, req.Names) if err != nil { - resp.Msg = terror.Message(err) + resp.Msg = err.Error() return resp, nil } members = append(members, &pb.Members{ diff --git a/dm/tracer/server.go b/dm/tracer/server.go index a8f2ac69b8..62f768bbfe 100644 --- a/dm/tracer/server.go +++ b/dm/tracer/server.go @@ -19,7 +19,6 @@ import ( "sync" "time" - "github.com/pingcap/errors" "github.com/siddontang/go/sync2" "github.com/soheilhy/cmux" "go.uber.org/zap" @@ -139,7 +138,7 @@ func (s *Server) UploadSyncerBinlogEvent(ctx context.Context, req *pb.UploadSync if err != nil { return &pb.CommonUploadResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: err.Error(), }, nil } } @@ -157,7 +156,7 @@ func (s *Server) UploadSyncerJobEvent(ctx context.Context, req *pb.UploadSyncerJ if err != nil { return &pb.CommonUploadResponse{ Result: false, - Msg: errors.ErrorStack(err), + Msg: err.Error(), }, nil } } diff --git a/dm/worker/server.go b/dm/worker/server.go index 604f5a8e39..73afe8b9ec 100644 --- a/dm/worker/server.go +++ b/dm/worker/server.go @@ -600,7 +600,7 @@ func (s *Server) OperateRelay(ctx context.Context, req *pb.OperateRelayRequest) err := w.OperateRelay(ctx, req) if err != nil { log.L().Error("fail to operate relay", zap.String("request", "OperateRelay"), zap.Stringer("payload", req), zap.Error(err)) - resp.Msg = errors.ErrorStack(err) + resp.Msg = err.Error() return resp, nil } @@ -663,7 +663,7 @@ func (s *Server) QueryWorkerConfig(ctx context.Context, req *pb.QueryWorkerConfi workerCfg, err := w.QueryConfig(ctx) if err != nil { resp.Result = false - resp.Msg = errors.ErrorStack(err) + resp.Msg = err.Error() log.L().Error("fail to query worker config", zap.String("request", "QueryWorkerConfig"), zap.Stringer("payload", req), zap.Error(err)) return resp, nil } @@ -671,7 +671,7 @@ func (s *Server) QueryWorkerConfig(ctx context.Context, req *pb.QueryWorkerConfi rawConfig, err := workerCfg.From.Toml() if err != nil { resp.Result = false - resp.Msg = errors.ErrorStack(err) + resp.Msg = err.Error() log.L().Error("fail to marshal worker config", zap.String("request", "QueryWorkerConfig"), zap.Stringer("worker from config", &workerCfg.From), zap.Error(err)) } @@ -808,7 +808,7 @@ func makeCommonWorkerResponse(reqErr error) *pb.CommonWorkerResponse { } if reqErr != nil { resp.Result = false - resp.Msg = errors.ErrorStack(reqErr) + resp.Msg = reqErr.Error() } return resp } From 99af3018ee2205983e41532f0a412c11d76f2d9f Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Wed, 17 Jun 2020 23:15:20 -0400 Subject: [PATCH 09/11] revert ErrVerifySQLOperateArgs --- dm/command/argument.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm/command/argument.go b/dm/command/argument.go index 9a6cdf0166..4d4e3ccb7e 100644 --- a/dm/command/argument.go +++ b/dm/command/argument.go @@ -50,7 +50,7 @@ func VerifySQLOperateArgs(binlogPosStr, sqlPattern string, sharding bool) (*mysq if len(binlogPosStr) > 0 { pos2, err := binlog.PositionFromStr(binlogPosStr) if err != nil { - return nil, nil, terror.ErrVerifySQLOperateArgs.Generatef("invalid --binlog-pos %s in sql operation: %v", binlogPosStr, err) + return nil, nil, terror.ErrVerifySQLOperateArgs.Generatef("invalid --binlog-pos %s in sql operation: %s", binlogPosStr, terror.Message(err)) } pos = &pos2 } else if len(sqlPattern) > 0 { From 13ec4b4b28d9d74949138a7e18f135e9254abdab Mon Sep 17 00:00:00 2001 From: gmhdbjd Date: Thu, 18 Jun 2020 03:38:22 -0400 Subject: [PATCH 10/11] address comment --- dm/ctl/common/util.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dm/ctl/common/util.go b/dm/ctl/common/util.go index e9c7236ef2..a497088719 100644 --- a/dm/ctl/common/util.go +++ b/dm/ctl/common/util.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/dm/dm/pb" parserpkg "github.com/pingcap/dm/pkg/parser" - "github.com/pingcap/dm/pkg/terror" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" @@ -73,7 +72,7 @@ func PrintLines(format string, a ...interface{}) { func PrettyPrintResponse(resp proto.Message) { s, err := marshResponseToString(resp) if err != nil { - PrintLines(terror.Message(err)) + PrintLines("%v", err) } else { fmt.Println(s) } @@ -83,7 +82,7 @@ func PrettyPrintResponse(resp proto.Message) { func PrettyPrintInterface(resp interface{}) { s, err := json.MarshalIndent(resp, "", " ") if err != nil { - PrintLines(terror.Message(err)) + PrintLines("%v", err) } else { fmt.Println(string(s)) } @@ -148,7 +147,7 @@ func PrettyPrintResponseWithCheckTask(resp proto.Message, subStr string) bool { } if err != nil { - fmt.Println(terror.Message(err)) + PrintLines("%v", err) } else { // add indent to make it prettily. replacedStr = strings.Replace(replacedStr, "detail: {", " \tdetail: {", 1) From bc8bbe382c86d790d53c2403f5a503b0a6048109 Mon Sep 17 00:00:00 2001 From: GMHDBJD <35025882+GMHDBJD@users.noreply.github.com> Date: Thu, 18 Jun 2020 03:40:16 -0400 Subject: [PATCH 11/11] Update dm/ctl/master/show_ddl_locks.go Co-authored-by: Xuecheng Zhang --- dm/ctl/master/show_ddl_locks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm/ctl/master/show_ddl_locks.go b/dm/ctl/master/show_ddl_locks.go index e7886669f5..c078fcd22c 100644 --- a/dm/ctl/master/show_ddl_locks.go +++ b/dm/ctl/master/show_ddl_locks.go @@ -56,7 +56,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) { Sources: sources, }) if err != nil { - common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, err) + common.PrintLines("can not show DDL locks for task %s and sources %v:\n%v", taskName, sources, err) return }