Skip to content

Commit

Permalink
dm: display instruction separately if precheck error is terror.Error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
D3Hunter authored Feb 21, 2023
1 parent 1b1703b commit e9014db
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dm/_utils/terror_gen/errors_release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ErrNoRelayPosMatchGTID,[code=11121:class=functional:scope=internal:level=high],
ErrReaderReachEndOfFile,[code=11122:class=functional:scope=internal:level=low]
ErrMetadataNoBinlogLoc,[code=11123:class=functional:scope=upstream:level=low], "Message: didn't found binlog location in dumped metadata file %s, Workaround: Please check log of dump unit, there maybe errors when read upstream binlog status"
ErrPreviousGTIDNotExist,[code=11124:class=functional:scope=internal:level=high], "Message: no previous gtid event from binlog %s"
ErrNoMasterStatus,[code=11125:class=functional:scope=upstream:level=medium], "Message: upstream returns an empty result for SHOW MASTER STATUS, Workaround: Please check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS."
ErrNoMasterStatus,[code=11125:class=functional:scope=upstream:level=medium], "Message: upstream returns an empty result for SHOW MASTER STATUS, Workaround: Please make sure binlog is enabled, and check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS."
ErrIncorrectReturnColumnsNum,[code=11130:class=functional:scope=upstream:level=medium], "Message: upstream returns incorrect number of columns for SHOW MASTER STATUS, Workaround: Please check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS."
ErrBinlogNotLogColumn,[code=11126:class=binlog-op:scope=upstream:level=high], "Message: upstream didn't log enough columns in binlog, Workaround: Please check if session `binlog_row_image` variable is not FULL, restart task to the location from where FULL binlog_row_image is used."
ErrShardDDLOptimismNeedSkipAndRedirect,[code=11127:class=functional:scope=internal:level=high], "Message: receive conflict DDL for the optimistic shard ddl lock %s: %s. Now DM does not support conflicting DDLs, such as 'modify column'/'rename column'/'add column not null non default'."
Expand Down
2 changes: 1 addition & 1 deletion dm/errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ tags = ["internal", "high"]
[error.DM-functional-11125]
message = "upstream returns an empty result for SHOW MASTER STATUS"
description = ""
workaround = "Please check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS."
workaround = "Please make sure binlog is enabled, and check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS."
tags = ["upstream", "medium"]

[error.DM-binlog-op-11126]
Expand Down
8 changes: 7 additions & 1 deletion dm/pkg/checker/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb-tools/pkg/utils"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tiflow/dm/pkg/terror"
)

// MySQLVersion represents MySQL version number.
Expand Down Expand Up @@ -135,7 +136,12 @@ func markCheckError(result *Result, err error) {
if result.State != StateFailure {
result.State = state
}
result.Errors = append(result.Errors, &Error{Severity: state, ShortErr: err.Error()})
if err2, ok := err.(*terror.Error); ok {
result.Errors = append(result.Errors, &Error{Severity: state, ShortErr: err2.ErrorWithoutWorkaround()})
result.Instruction = err2.Workaround()
} else {
result.Errors = append(result.Errors, &Error{Severity: state, ShortErr: err.Error()})
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions dm/pkg/checker/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package checker
import (
"testing"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tiflow/dm/pkg/terror"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -123,3 +125,12 @@ func TestGetColumnsAndIgnorable(t *testing.T) {
require.Equal(t, c.expected, columns)
}
}

func TestMarkCheckError(t *testing.T) {
res := &Result{}
markCheckError(res, terror.ErrNoMasterStatus.Generate())
require.Equal(t, terror.ErrNoMasterStatus.Workaround(), res.Instruction)
res = &Result{}
markCheckError(res, errors.New("other err"))
require.Zero(t, len(res.Instruction))
}
2 changes: 1 addition & 1 deletion dm/pkg/election/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func testElection2After1(t *testElectionSuite, c *C, normalExit bool) {
defer cancel5()
_, err = NewElection(ctx5, cli, sessionTTL, key, ID3, addr3, t.notifyBlockTime)
c.Assert(terror.ErrElectionCampaignFail.Equal(err), IsTrue)
c.Assert(err, ErrorMatches, ".*, Message: fail to campaign leader: create the initial session, RawCause: context canceled.*")
c.Assert(err, ErrorMatches, ".*Message: fail to campaign leader: create the initial session, RawCause: context canceled.*")
cancel0()
}

Expand Down
2 changes: 1 addition & 1 deletion dm/pkg/terror/error_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ var (
ErrPreviousGTIDNotExist = New(codePreviousGTIDNotExist, ClassFunctional, ScopeInternal, LevelHigh, "no previous gtid event from binlog %s", "")

// pkg/utils.
ErrNoMasterStatus = New(codeNoMasterStatus, ClassFunctional, ScopeUpstream, LevelMedium, "upstream returns an empty result for SHOW MASTER STATUS", "Please check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS.")
ErrNoMasterStatus = New(codeNoMasterStatus, ClassFunctional, ScopeUpstream, LevelMedium, "upstream returns an empty result for SHOW MASTER STATUS", "Please make sure binlog is enabled, and check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS.")
ErrIncorrectReturnColumnsNum = New(codeIncorrectReturnColumnsNum, ClassFunctional, ScopeUpstream, LevelMedium, "upstream returns incorrect number of columns for SHOW MASTER STATUS", "Please check the upstream settings like privileges, RDS settings to read data from SHOW MASTER STATUS.")

// pkg/binlog.
Expand Down
23 changes: 18 additions & 5 deletions dm/pkg/terror/terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,27 @@ func (e *Error) Workaround() string {
return e.workaround
}

// Error implements error interface.
func (e *Error) Error() string {
str := fmt.Sprintf(errBaseFormat, e.code, e.class, e.scope, e.level)
// ErrorWithoutWorkaround returns err msg without workaround, in some place like cloud we want display it separately.
func (e *Error) ErrorWithoutWorkaround() string {
var str string
if e.getMsg() != "" {
str += fmt.Sprintf(", Message: %s", e.getMsg())
str += fmt.Sprintf("Message: %s", e.getMsg())
}
if e.rawCause != nil {
str += fmt.Sprintf(", RawCause: %s", Message(e.rawCause))
if len(str) > 0 {
str += ", "
}
str += fmt.Sprintf("RawCause: %s", Message(e.rawCause))
}
return str
}

// Error implements error interface.
func (e *Error) Error() string {
str := fmt.Sprintf(errBaseFormat, e.code, e.class, e.scope, e.level)
tmp := e.ErrorWithoutWorkaround()
if tmp != "" {
str += ", " + tmp
}
if e.workaround != "" {
str += fmt.Sprintf(", Workaround: %s", e.workaround)
Expand Down

0 comments on commit e9014db

Please sign in to comment.