github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/config/checking_item.go (about) 1 // Copyright 2019 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package config 15 16 import ( 17 "bytes" 18 "fmt" 19 20 "github.com/pingcap/tiflow/dm/pkg/terror" 21 ) 22 23 // DM definition checking items. Don't forget to update AllCheckingItems and LightningPrechecks. 24 const ( 25 AllChecking = "all" 26 DumpPrivilegeChecking = "dump_privilege" 27 ReplicationPrivilegeChecking = "replication_privilege" 28 VersionChecking = "version" 29 ServerIDChecking = "server_id" 30 BinlogEnableChecking = "binlog_enable" 31 BinlogFormatChecking = "binlog_format" 32 BinlogRowImageChecking = "binlog_row_image" 33 TableSchemaChecking = "table_schema" 34 ShardTableSchemaChecking = "schema_of_shard_tables" 35 ShardAutoIncrementIDChecking = "auto_increment_ID" 36 OnlineDDLChecking = "online_ddl" 37 BinlogDBChecking = "binlog_db" 38 MetaPositionChecking = "meta_position" 39 ConnNumberChecking = "conn_number" 40 TargetDBPrivilegeChecking = "target_privilege" 41 // lighting prechecks. 42 LightningEmptyRegionChecking = "empty_region" 43 LightningRegionDistributionChecking = "region_distribution" 44 LightningDownstreamVersionChecking = "downstream_version" 45 LightningFreeSpaceChecking = "free_space" 46 LightningMutexFeatureChecking = "downstream_mutex_features" 47 LightningTableEmptyChecking = "downstream_table_empty" 48 ) 49 50 // AllCheckingItems contains all checking items. 51 var AllCheckingItems = map[string]string{ 52 AllChecking: "all checking items", 53 DumpPrivilegeChecking: "dump privileges of source DB checking item", 54 ReplicationPrivilegeChecking: "replication privileges of source DB checking item", 55 VersionChecking: "MySQL/MariaDB version checking item", 56 ServerIDChecking: "server_id checking item", 57 BinlogEnableChecking: "binlog enable checking item", 58 BinlogFormatChecking: "binlog format checking item", 59 BinlogRowImageChecking: "binlog row image checking item", 60 TableSchemaChecking: "table schema compatibility checking item", 61 ShardTableSchemaChecking: "consistent schema of shard tables checking item", 62 ShardAutoIncrementIDChecking: "conflict auto increment ID of shard tables checking item", 63 OnlineDDLChecking: "online ddl checking item", 64 BinlogDBChecking: "binlog db checking item", 65 MetaPositionChecking: "meta position valid checking item", 66 ConnNumberChecking: "connection number checking item", 67 TargetDBPrivilegeChecking: "privileges of target DB checking item", 68 // lightning prechecks 69 LightningEmptyRegionChecking: "physical import mode empty region checking item", 70 LightningRegionDistributionChecking: "physical import mode region distribution checking item", 71 LightningDownstreamVersionChecking: "physical import mode downstream TiDB/PD/TiKV version checking item", 72 LightningFreeSpaceChecking: "downstream free space checking item", 73 LightningMutexFeatureChecking: "physical import mode downstream incompatible feature checking item", 74 LightningTableEmptyChecking: "physical import mode downstream table empty checking item", 75 } 76 77 // LightningPrechecks returns all checking items for lightning. 78 var LightningPrechecks = []string{ 79 LightningEmptyRegionChecking, 80 LightningRegionDistributionChecking, 81 LightningDownstreamVersionChecking, 82 LightningFreeSpaceChecking, 83 LightningMutexFeatureChecking, 84 LightningTableEmptyChecking, 85 } 86 87 // MaxSourceIDLength is the max length for dm-worker source id. 88 const MaxSourceIDLength = 32 89 90 // ValidateCheckingItem validates checking item. 91 func ValidateCheckingItem(item string) error { 92 if _, ok := AllCheckingItems[item]; ok { 93 return nil 94 } 95 96 return terror.ErrConfigCheckItemNotSupport.Generate(item, SupportCheckingItems()) 97 } 98 99 // SupportCheckingItems returns all supporting checking item. 100 func SupportCheckingItems() string { 101 var buf bytes.Buffer 102 fmt.Fprintf(&buf, "************ supporting checking items ************\n name:\t\tdescription\n") 103 for name, desc := range AllCheckingItems { 104 fmt.Fprintf(&buf, "%s:\t%s\n", name, desc) 105 } 106 fmt.Fprintf(&buf, "************ supporting checking items ************\n") 107 return buf.String() 108 } 109 110 // FilterCheckingItems filters ignored items from all checking items. 111 func FilterCheckingItems(ignoredItems []string) map[string]string { 112 checkingItems := make(map[string]string) 113 for item, desc := range AllCheckingItems { 114 checkingItems[item] = desc 115 } 116 delete(checkingItems, AllChecking) 117 118 for _, item := range ignoredItems { 119 if item == AllChecking { 120 return nil 121 } 122 123 delete(checkingItems, item) 124 } 125 126 return checkingItems 127 }