forked from pingcap/dm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: allow to ignore some checking items (pingcap#65)
- Loading branch information
1 parent
f80e6fb
commit 975b27e
Showing
9 changed files
with
270 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package checker | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
tc "github.com/pingcap/check" | ||
"github.com/pingcap/dm/dm/config" | ||
) | ||
|
||
func TestChecker(t *testing.T) { | ||
tc.TestingT(t) | ||
} | ||
|
||
type testChecker struct{} | ||
|
||
var _ = tc.Suite(&testChecker{}) | ||
|
||
func (t *testChecker) TestCheckSyncConfig(c *tc.C) { | ||
c.Assert(CheckSyncConfig(context.Background(), nil), tc.IsNil) | ||
|
||
cfgs := []*config.SubTaskConfig{ | ||
{ | ||
IgnoreCheckingItems: []string{config.AllChecking}, | ||
}, | ||
} | ||
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/pingcap/errors" | ||
) | ||
|
||
// DM definition checking items | ||
// refer github.com/pingcap/tidb-tools/pkg/check | ||
const ( | ||
AllChecking = "all" | ||
DumpPrivilegeChecking = "dump_privilege" | ||
ReplicationPrivilegeChecking = "replication_privilege" | ||
VersionChecking = "version" | ||
BinlogEnableChecking = "binlog_enable" | ||
BinlogFormatChecking = "binlog_format" | ||
BinlogRowImageChecking = "binlog_row_image" | ||
TableSchemaChecking = "table_schema" | ||
ShardTableSchemaChecking = "schema_of_shard_tables" | ||
ShardAutoIncrementIDChecking = "auto_increment_ID" | ||
) | ||
|
||
// AllCheckingItems contains all checking items | ||
var AllCheckingItems = map[string]string{ | ||
AllChecking: "all checking items", | ||
DumpPrivilegeChecking: "dump privileges of source DB checking item", | ||
ReplicationPrivilegeChecking: "replication privileges of source DB checking item", | ||
VersionChecking: "MySQL/MariaDB version checking item", | ||
BinlogEnableChecking: "binlog enable checking item", | ||
BinlogFormatChecking: "binlog format checking item", | ||
BinlogRowImageChecking: "binlog row image checking item", | ||
TableSchemaChecking: "table schema compatibility checking item", | ||
ShardTableSchemaChecking: "consistent schema of shard tables checking item", | ||
ShardAutoIncrementIDChecking: "conflict auto increment ID of shard tables checking item", | ||
} | ||
|
||
// ValidateCheckingItem validates checking item | ||
func ValidateCheckingItem(item string) error { | ||
if _, ok := AllCheckingItems[item]; ok { | ||
return nil | ||
} | ||
|
||
return errors.Errorf("checking item %s is not supported\n%s", item, SupportCheckingItems()) | ||
} | ||
|
||
// SupportCheckingItems returns all supporting checking item | ||
func SupportCheckingItems() string { | ||
var buf bytes.Buffer | ||
fmt.Fprintf(&buf, "************ supporting checking items ************\n name:\t\tdescription\n") | ||
for name, desc := range AllCheckingItems { | ||
fmt.Fprintf(&buf, "%s:\t%s\n", name, desc) | ||
} | ||
fmt.Fprintf(&buf, "************ supporting checking items ************\n") | ||
return buf.String() | ||
} | ||
|
||
// FilterCheckingItems filters ignored items from all checking items | ||
func FilterCheckingItems(ignoredItems []string) map[string]string { | ||
checkingItems := make(map[string]string) | ||
for item, desc := range AllCheckingItems { | ||
checkingItems[item] = desc | ||
} | ||
delete(checkingItems, AllChecking) | ||
|
||
for _, item := range ignoredItems { | ||
if item == AllChecking { | ||
return nil | ||
} | ||
|
||
delete(checkingItems, item) | ||
} | ||
|
||
return checkingItems | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/pingcap/check" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
TestingT(t) | ||
} | ||
|
||
type testConfig struct{} | ||
|
||
var _ = Suite(&testConfig{}) | ||
|
||
func (t *testConfig) TestCheckingItems(c *C) { | ||
for item := range AllCheckingItems { | ||
c.Assert(ValidateCheckingItem(item), IsNil) | ||
} | ||
c.Assert(ValidateCheckingItem("xxx"), NotNil) | ||
|
||
// ignore all checking items | ||
ignoredCheckingItems := []string{AllChecking} | ||
c.Assert(FilterCheckingItems(ignoredCheckingItems), IsNil) | ||
ignoredCheckingItems = append(ignoredCheckingItems, ShardTableSchemaChecking) | ||
c.Assert(FilterCheckingItems(ignoredCheckingItems), IsNil) | ||
|
||
// ignore shard checking items | ||
checkingItems := make(map[string]string) | ||
for item, desc := range AllCheckingItems { | ||
checkingItems[item] = desc | ||
} | ||
delete(checkingItems, AllChecking) | ||
|
||
c.Assert(FilterCheckingItems(ignoredCheckingItems[:0]), DeepEquals, checkingItems) | ||
|
||
delete(checkingItems, ShardTableSchemaChecking) | ||
c.Assert(FilterCheckingItems(ignoredCheckingItems[1:]), DeepEquals, checkingItems) | ||
|
||
ignoredCheckingItems = append(ignoredCheckingItems, ShardAutoIncrementIDChecking) | ||
delete(checkingItems, ShardAutoIncrementIDChecking) | ||
c.Assert(FilterCheckingItems(ignoredCheckingItems[1:]), DeepEquals, checkingItems) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters