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

Commit

Permalink
check-task: precheck server-id for all/incremental mode (#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
GMHDBJD authored Nov 27, 2020
1 parent 9b83088 commit 2b14028
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
19 changes: 19 additions & 0 deletions checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func ignoreExcept(itemMap map[string]struct{}) []string {
config.DumpPrivilegeChecking,
config.ReplicationPrivilegeChecking,
config.VersionChecking,
config.ServerIDChecking,
config.BinlogEnableChecking,
config.BinlogFormatChecking,
config.BinlogRowImageChecking,
Expand Down Expand Up @@ -145,6 +146,24 @@ func (s *testCheckerSuite) TestVersionChecking(c *tc.C) {
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*version required at least .* but got 10.0.0(.|\n)*")
}

func (s *testCheckerSuite) TestServerIDChecking(c *tc.C) {
cfgs := []*config.SubTaskConfig{
{
IgnoreCheckingItems: ignoreExcept(map[string]struct{}{config.ServerIDChecking: {}}),
},
}

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)*")

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)
}

func (s *testCheckerSuite) TestBinlogEnableChecking(c *tc.C) {
cfgs := []*config.SubTaskConfig{
{
Expand Down
3 changes: 3 additions & 0 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func (c *Checker) Init(ctx context.Context) (err error) {
if _, ok := c.checkingItems[config.VersionChecking]; ok {
c.checkList = append(c.checkList, check.NewMySQLVersionChecker(instance.sourceDB.DB, instance.sourceDBinfo))
}
if _, ok := c.checkingItems[config.ServerIDChecking]; ok {
c.checkList = append(c.checkList, check.NewMySQLServerIDChecker(instance.sourceDB.DB, instance.sourceDBinfo))
}
if _, ok := c.checkingItems[config.BinlogEnableChecking]; ok {
c.checkList = append(c.checkList, check.NewMySQLBinlogEnableChecker(instance.sourceDB.DB, instance.sourceDBinfo))
}
Expand Down
2 changes: 1 addition & 1 deletion checker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig) error {
switch cfgs[0].Mode {
case config.ModeFull:
ignoreCheckingItems = append(ignoreCheckingItems, config.ReplicationPrivilegeChecking,
config.BinlogEnableChecking, config.BinlogFormatChecking, config.BinlogRowImageChecking)
config.BinlogEnableChecking, config.BinlogFormatChecking, config.BinlogRowImageChecking, config.ServerIDChecking)
case config.ModeIncrement:
ignoreCheckingItems = append(ignoreCheckingItems, config.DumpPrivilegeChecking)
}
Expand Down
2 changes: 2 additions & 0 deletions dm/config/checking_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
DumpPrivilegeChecking = "dump_privilege"
ReplicationPrivilegeChecking = "replication_privilege"
VersionChecking = "version"
ServerIDChecking = "server_id"
BinlogEnableChecking = "binlog_enable"
BinlogFormatChecking = "binlog_format"
BinlogRowImageChecking = "binlog_row_image"
Expand All @@ -41,6 +42,7 @@ var AllCheckingItems = map[string]string{
DumpPrivilegeChecking: "dump privileges of source DB checking item",
ReplicationPrivilegeChecking: "replication privileges of source DB checking item",
VersionChecking: "MySQL/MariaDB version checking item",
ServerIDChecking: "server_id checking item",
BinlogEnableChecking: "binlog enable checking item",
BinlogFormatChecking: "binlog format checking item",
BinlogRowImageChecking: "binlog row image checking item",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8
github.com/pingcap/parser v0.0.0-20201123080035-8f4c6ab94e11
github.com/pingcap/tidb v1.1.0-beta.0.20201119113654-22feeb4aef75
github.com/pingcap/tidb-tools v4.0.7-0.20200927084250-e47e0e12c7f3+incompatible
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible
github.com/prometheus/client_golang v1.5.1
github.com/rakyll/statik v0.1.6
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ github.com/pingcap/tidb-tools v4.0.0+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnw
github.com/pingcap/tidb-tools v4.0.1+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb-tools v4.0.5-0.20200820082341-afeaaaaaa153+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb-tools v4.0.5-0.20200820092506-34ea90c93237+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb-tools v4.0.7-0.20200927084250-e47e0e12c7f3+incompatible h1:4SG8o8YyuhNbiAZS0eyArroyl0EpwbUE9QE6CXzjs6Y=
github.com/pingcap/tidb-tools v4.0.7-0.20200927084250-e47e0e12c7f3+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible h1:ceznmu/lLseGHP/jKyOa/3u/5H3wtLLLqkH2V3ssSjg=
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330 h1:rRMLMjIMFulCX9sGKZ1hoov/iROMsKyC8Snc02nSukw=
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
github.com/pingcap/tipb v0.0.0-20200417094153-7316d94df1ee h1:XJQ6/LGzOSc/jo33AD8t7jtc4GohxcyODsYnb+kZXJM=
Expand Down

0 comments on commit 2b14028

Please sign in to comment.