Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

check: add error/warn count for check-task #1610

Merged
merged 11 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
router "github.com/pingcap/tidb-tools/pkg/table-router"

"github.com/pingcap/dm/dm/config"
"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/pkg/conn"

tc "github.com/pingcap/check"
Expand Down Expand Up @@ -75,16 +76,17 @@ func ignoreExcept(itemMap map[string]struct{}) []string {
}

func (s *testCheckerSuite) TestIgnoreAllCheckingItems(c *tc.C) {
c.Assert(CheckSyncConfig(context.Background(), nil), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), nil, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)

cfgs := []*config.SubTaskConfig{
{
IgnoreCheckingItems: []string{config.AllChecking},
},
}
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

// nolint:dupl
func (s *testCheckerSuite) TestDumpPrivilegeChecking(c *tc.C) {
cfgs := []*config.SubTaskConfig{
{
Expand All @@ -94,16 +96,17 @@ func (s *testCheckerSuite) TestDumpPrivilegeChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT USAGE ON *.* TO 'haha'@'%'"))
err := CheckSyncConfig(context.Background(), cfgs)
err := CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt)
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*RELOAD(.|\n)*")
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*Select(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT RELOAD,SELECT ON *.* TO 'haha'@'%'"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

// nolint:dupl
func (s *testCheckerSuite) TestReplicationPrivilegeChecking(c *tc.C) {
cfgs := []*config.SubTaskConfig{
{
Expand All @@ -113,14 +116,14 @@ func (s *testCheckerSuite) TestReplicationPrivilegeChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT USAGE ON *.* TO 'haha'@'%'"))
err := CheckSyncConfig(context.Background(), cfgs)
err := CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt)
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*REPLICATION SLAVE(.|\n)*")
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*REPLICATION CLIENT(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'haha'@'%'"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestVersionChecking(c *tc.C) {
Expand All @@ -133,22 +136,22 @@ func (s *testCheckerSuite) TestVersionChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "5.7.26-log"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "10.1.29-MariaDB"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "5.5.26-log"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*version required at least .* but got 5.5.26(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*version required at least .* but got 5.5.26(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "10.0.0-MariaDB"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*version required at least .* but got 10.0.0(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*version required at least .* but got 10.0.0(.|\n)*")
}

func (s *testCheckerSuite) TestServerIDChecking(c *tc.C) {
Expand All @@ -161,12 +164,12 @@ func (s *testCheckerSuite) TestServerIDChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'server_id'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("server_id", "0"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*please set server_id greater than 0(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*please set server_id greater than 0(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'server_id'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("server_id", "1"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestBinlogEnableChecking(c *tc.C) {
Expand All @@ -179,12 +182,12 @@ func (s *testCheckerSuite) TestBinlogEnableChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'log_bin'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("log_bin", "OFF"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*log_bin is OFF, and should be ON(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*log_bin is OFF, and should be ON(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'log_bin'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("log_bin", "ON"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestBinlogFormatChecking(c *tc.C) {
Expand All @@ -197,12 +200,12 @@ func (s *testCheckerSuite) TestBinlogFormatChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_format'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_format", "STATEMENT"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*binlog_format is STATEMENT, and should be ROW(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*binlog_format is STATEMENT, and should be ROW(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_format'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_format", "ROW"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestBinlogRowImageChecking(c *tc.C) {
Expand All @@ -217,14 +220,14 @@ func (s *testCheckerSuite) TestBinlogRowImageChecking(c *tc.C) {
AddRow("version", "5.7.26-log"))
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_row_image'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_row_image", "MINIMAL"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*binlog_row_image is MINIMAL, and should be FULL(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*binlog_row_image is MINIMAL, and should be FULL(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "10.1.29-MariaDB"))
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_row_image'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_row_image", "FULL"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestTableSchemaChecking(c *tc.C) {
Expand Down Expand Up @@ -256,7 +259,7 @@ func (s *testCheckerSuite) TestTableSchemaChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*primary/unique key does not exist(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*primary/unique key does not exist(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW DATABASES").WillReturnRows(sqlmock.NewRows([]string{"DATABASE"}).AddRow(schema))
Expand All @@ -265,7 +268,7 @@ func (s *testCheckerSuite) TestTableSchemaChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb2)))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestShardTableSchemaChecking(c *tc.C) {
Expand Down Expand Up @@ -303,15 +306,15 @@ func (s *testCheckerSuite) TestShardTableSchemaChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*different column definition(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*different column definition(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW DATABASES").WillReturnRows(sqlmock.NewRows([]string{"DATABASE"}).AddRow(schema))
mock.ExpectQuery("SHOW FULL TABLES").WillReturnRows(sqlmock.NewRows([]string{"Tables_in_" + schema, "Table_type"}).AddRow(tb1, "BASE TABLE").AddRow(tb2, "BASE TABLE"))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestShardAutoIncrementIDChecking(c *tc.C) {
Expand Down Expand Up @@ -354,15 +357,15 @@ func (s *testCheckerSuite) TestShardAutoIncrementIDChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*instance table .* of sharding .* have auto-increment key(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*instance table .* of sharding .* have auto-increment key(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW DATABASES").WillReturnRows(sqlmock.NewRows([]string{"DATABASE"}).AddRow(schema))
mock.ExpectQuery("SHOW FULL TABLES").WillReturnRows(sqlmock.NewRows([]string{"Tables_in_" + schema, "Table_type"}).AddRow(tb1, "BASE TABLE").AddRow(tb2, "BASE TABLE"))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestSameTargetTableDetection(c *tc.C) {
Expand Down Expand Up @@ -403,5 +406,5 @@ func (s *testCheckerSuite) TestSameTargetTableDetection(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*same table name in case-insensitive(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*same table name in case-insensitive(.|\n)*")
}
22 changes: 19 additions & 3 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ type Checker struct {
sync.RWMutex
detail *check.Results
}
errCnt int64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it make sense to restrict the total length of the errors or the total numbers of error + warn instead of set two different count separately. e.g. if we think be default we only return 20 messages, then if errors + warns <= 20, we needn't truncate any messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think error has a higher priority than warning, so if user gets 20 warnings and 1 errors we should make sure we will display that errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could loop the results twice to make sure errors have higher priority 🤔 I'm OK with current two settings, let's wait glorv

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok, too. I just wonder if this implementation is user-friendly enough to use since the goal is to solve the message too long issue.

BTW, I think maybe there are some cases the user just wants to emit the warning message, thus the --warn parameter can be used.

warnCnt int64
}

// NewChecker returns a checker.
func NewChecker(cfgs []*config.SubTaskConfig, checkingItems map[string]string) *Checker {
func NewChecker(cfgs []*config.SubTaskConfig, checkingItems map[string]string, errCnt, warnCnt int64) *Checker {
c := &Checker{
instances: make([]*mysqlInstance, 0, len(cfgs)),
checkingItems: checkingItems,
logger: log.With(zap.String("unit", "task check")),
errCnt: errCnt,
warnCnt: warnCnt,
}

for _, cfg := range cfgs {
Expand Down Expand Up @@ -261,9 +265,21 @@ func (c *Checker) Process(ctx context.Context, pr chan pb.ProcessResult) {

// remove success result if not pass
results := result.Results[:0]
var warnCnt int64 = 0
var errCnt int64 = 0
for _, r := range result.Results {
if r.State != check.StateSuccess {
results = append(results, r)
switch r.State {
case check.StateFailure:
if c.errCnt >= 0 && errCnt < c.errCnt {
GMHDBJD marked this conversation as resolved.
Show resolved Hide resolved
errCnt++
results = append(results, r)
}
case check.StateWarning:
if c.warnCnt >= 0 && warnCnt < c.warnCnt {
GMHDBJD marked this conversation as resolved.
Show resolved Hide resolved
warnCnt++
results = append(results, r)
}
default:
}
}
result.Results = results
Expand Down
6 changes: 3 additions & 3 deletions checker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ var (
ErrorMsgHeader = "fail to check synchronization configuration with type"

// CheckSyncConfigFunc holds the CheckSyncConfig function.
CheckSyncConfigFunc func(ctx context.Context, cfgs []*config.SubTaskConfig) error
CheckSyncConfigFunc func(ctx context.Context, cfgs []*config.SubTaskConfig, errCnt, warnCnt int64) error
)

func init() {
CheckSyncConfigFunc = CheckSyncConfig
}

// CheckSyncConfig checks synchronization configuration.
func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig) error {
func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig, errCnt, warnCnt int64) error {
if len(cfgs) == 0 {
return nil
}
Expand All @@ -56,7 +56,7 @@ func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig) error {
return nil
}

c := NewChecker(cfgs, checkingItems)
c := NewChecker(cfgs, checkingItems, errCnt, warnCnt)

if err := c.Init(ctx); err != nil {
return terror.Annotate(err, "fail to initial checker")
Expand Down
5 changes: 5 additions & 0 deletions dm/ctl/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const (
keepaliveTimeout = 3 * time.Second
keepaliveTime = 3 * time.Second
syncMasterEndpointsTime = 3 * time.Second

// DefaultErrorCnt represents default count of errors to display for check-task.
DefaultErrorCnt = 10
// DefaultWarnCnt represents count of warns to display for check-task.
DefaultWarnCnt = 10
)

// NewConfig creates a new base config for dmctl.
Expand Down
17 changes: 15 additions & 2 deletions dm/ctl/master/check_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import (
// NewCheckTaskCmd creates a CheckTask command.
func NewCheckTaskCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "check-task <config-file>",
Use: "check-task <config-file> [--error count] [--warn count]",
Short: "Checks the configuration file of the task.",
RunE: checkTaskFunc,
}
cmd.Flags().Int64P("error", "e", common.DefaultErrorCnt, "max count of errors to display")
cmd.Flags().Int64P("warn", "w", common.DefaultWarnCnt, "max count of warns to display")
return cmd
}

Expand All @@ -47,6 +49,15 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) error {
return err
}

errCnt, err := cmd.Flags().GetInt64("error")
if err != nil {
return err
}
warnCnt, err := cmd.Flags().GetInt64("warn")
if err != nil {
return err
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -56,7 +67,9 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) error {
ctx,
"CheckTask",
&pb.CheckTaskRequest{
Task: string(content),
Task: string(content),
ErrCnt: errCnt,
WarnCnt: warnCnt,
},
&resp,
)
Expand Down
Loading