github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/openapi/fixtures/task.go (about) 1 // Copyright 2021 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 fixtures 15 16 import ( 17 "encoding/json" 18 "math/rand" 19 20 "github.com/pingcap/tiflow/dm/openapi" 21 ) 22 23 var ( 24 noShardTaskJSONStr = ` 25 { 26 "enhance_online_schema_change": true, 27 "meta_schema": "dm_meta", 28 "name": "test", 29 "on_duplicate": "replace", 30 "source_config": { 31 "full_migrate_conf": { 32 "data_dir": "./exported_data", 33 "export_threads": 4, 34 "import_threads": 16 35 }, 36 "incr_migrate_conf": { "repl_batch": 200, "repl_threads": 32 }, 37 "source_conf": [{ "source_name": "mysql-replica-01" }] 38 }, 39 "table_migrate_rule": [ 40 { 41 "source": { 42 "schema": "some_db", 43 "source_name": "mysql-replica-01", 44 "table": "*" 45 }, 46 "target": { "schema": "new_name_db", "table": "*" } 47 } 48 ], 49 "target_config": { 50 "host": "root", 51 "password": "123456", 52 "port": 4000, 53 "security": null, 54 "user": "root" 55 }, 56 "task_mode": "all", 57 "strict_optimistic_shard_mode": false 58 } 59 ` 60 61 noShardErrNameJSONStr = ` 62 { 63 "enhance_online_schema_change": true, 64 "meta_schema": "dm_meta", 65 "name": "a5fb4a7540d343fa853c55ade2d08e6d03681d9e05d6240c0", 66 "on_duplicate": "replace", 67 "source_config": { 68 "full_migrate_conf": { 69 "data_dir": "./exported_data", 70 "export_threads": 4, 71 "import_threads": 16 72 }, 73 "incr_migrate_conf": { "repl_batch": 200, "repl_threads": 32 }, 74 "source_conf": [{ "source_name": "mysql-replica-01" }] 75 }, 76 "table_migrate_rule": [ 77 { 78 "source": { 79 "schema": "some_db", 80 "source_name": "mysql-replica-01", 81 "table": "*" 82 }, 83 "target": { "schema": "new_name_db", "table": "*" } 84 } 85 ], 86 "target_config": { 87 "host": "root", 88 "password": "123456", 89 "port": 4000, 90 "security": null, 91 "user": "root" 92 }, 93 "task_mode": "all", 94 "ignore_checking_items": ["all"] 95 } 96 ` 97 98 shardAndFilterTaskJSONStr = ` 99 { 100 "binlog_filter_rule": { 101 "filterA": { "ignore_event": ["drop database"], "ignore_sql": ["^Drop"] } 102 }, 103 "enhance_online_schema_change": true, 104 "meta_schema": "dm_meta", 105 "name": "test", 106 "on_duplicate": "replace", 107 "shard_mode": "optimistic", 108 "strict_optimistic_shard_mode": true, 109 "source_config": { 110 "full_migrate_conf": { 111 "data_dir": "./exported_data", 112 "export_threads": 4, 113 "import_threads": 16 114 }, 115 "incr_migrate_conf": { "repl_batch": 200, "repl_threads": 32 }, 116 "source_conf": [ 117 { 118 "binlog_gtid": "", 119 "binlog_name": "mysql-bin.001", 120 "binlog_pos": 0, 121 "source_name": "mysql-replica-01" 122 }, 123 { 124 "binlog_gtid": "12e57f06-f360-11eb-8235-585cc2bc66c9:1-24", 125 "binlog_name": "mysql-bin.002", 126 "binlog_pos": 1232, 127 "source_name": "mysql-replica-02" 128 } 129 ] 130 }, 131 "table_migrate_rule": [ 132 { 133 "binlog_filter_rule": ["filterA"], 134 "source": { 135 "schema": "db_*", 136 "source_name": "mysql-replica-01", 137 "table": "tbl_1" 138 }, 139 "target": { "schema": "db1", "table": "tbl" } 140 }, 141 { 142 "source": { 143 "schema": "db_*", 144 "source_name": "mysql-replica-02", 145 "table": "tbl_1" 146 }, 147 "target": { "schema": "db1", "table": "tbl" } 148 } 149 ], 150 "target_config": { 151 "host": "root", 152 "password": "123456", 153 "port": 4000, 154 "security": null, 155 "user": "root" 156 }, 157 "task_mode": "all" 158 } 159 ` 160 ) 161 162 // GenNoShardOpenAPITaskForTest generates a no-shard openapi.Task for test. 163 func GenNoShardOpenAPITaskForTest() (openapi.Task, error) { 164 t := openapi.Task{} 165 err := json.Unmarshal([]byte(noShardTaskJSONStr), &t) 166 return t, err 167 } 168 169 // GenNoShardErrNameOpenAPITaskForTest generates a no-shard openapi.Task with task.Name out of length for test. 170 func GenNoShardErrNameOpenAPITaskForTest() (openapi.Task, error) { 171 generateAnErrorNameFunc := func(length int) string { 172 allowedChars := []rune("1234567890abcdefghijklmnopqrstuvwxyz") 173 errNameString := make([]rune, length) 174 for i := range errNameString { 175 errNameString[i] = allowedChars[rand.Intn(len(allowedChars))] 176 } 177 return string(errNameString) 178 } 179 t := openapi.Task{} 180 err := json.Unmarshal([]byte(noShardErrNameJSONStr), &t) 181 t.Name = generateAnErrorNameFunc(65) 182 return t, err 183 } 184 185 // GenShardAndFilterOpenAPITaskForTest generates a shard-and-filter openapi.Task for test. 186 func GenShardAndFilterOpenAPITaskForTest() (openapi.Task, error) { 187 t := openapi.Task{} 188 err := json.Unmarshal([]byte(shardAndFilterTaskJSONStr), &t) 189 return t, err 190 }