Skip to content

Commit

Permalink
dm: fix start task check when both shard-mode and TLS are configured (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxiaoguang authored Dec 11, 2024
1 parent b8e69ab commit 19fc702
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dm/ctl/master/start_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ func startTaskFunc(cmd *cobra.Command, _ []string) error {
if yamlErr != nil {
return yamlErr
}
if task.TargetDB != nil && task.TargetDB.Security != nil {
loadErr := task.TargetDB.Security.LoadTLSContent()
if loadErr != nil {
log.L().Warn("load tls content failed", zap.Error(terror.ErrCtlLoadTLSCfg.Generate(loadErr)))
}
content = []byte(task.String())
}

lines := bytes.Split(content, []byte("\n"))
// we check if `is-sharding` is explicitly set, to distinguish between `false` from default value
Expand Down Expand Up @@ -95,6 +88,14 @@ func startTaskFunc(cmd *cobra.Command, _ []string) error {
return errors.New("please check output to see error")
}

if task.TargetDB != nil && task.TargetDB.Security != nil {
loadErr := task.TargetDB.Security.LoadTLSContent()
if loadErr != nil {
log.L().Warn("load tls content failed", zap.Error(terror.ErrCtlLoadTLSCfg.Generate(loadErr)))
}
content = []byte(task.String())
}

sources, err := common.GetSourceArgs(cmd)
if err != nil {
return err
Expand Down
49 changes: 49 additions & 0 deletions dm/tests/tls/conf/dm-task-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: test3
task-mode: all
shard-mode: "pessimistic"
meta-schema: "dm_meta"

target-database:
host: "127.0.0.1"
port: 4400
user: "root"
password: ""
security:
ssl-ca: "dir-placeholer/task-ca.pem"
ssl-cert: "dir-placeholer/dm.pem"
ssl-key: "dir-placeholer/dm.key"

mysql-instances:
- source-id: "mysql-replica-01"
black-white-list: "instance"
route-rules: ["route-rule-1"]
mydumper-config-name: "global"
loader-config-name: "global"
syncer-config-name: "global"

black-white-list:
instance:
do-dbs: ["tls"]

routes:
route-rule-1:
schema-pattern: "tls"
target-schema: "tls3"

mydumpers:
global:
threads: 4
chunk-filesize: 0
skip-tz-utc: true
extra-args: "--statement-size=100"

loaders:
global:
pool-size: 16
dir: "./dumped_data"

syncers:
global:
worker-count: 16
batch: 100
8 changes: 8 additions & 0 deletions dm/tests/tls/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function test_worker_handle_multi_tls_tasks() {
cp $cur/conf/dm-worker2.toml $WORK_DIR/
cp $cur/conf/dm-task.yaml $WORK_DIR/
cp $cur/conf/dm-task-2.yaml $WORK_DIR/
cp $cur/conf/dm-task-3.yaml $WORK_DIR/

sed -i "s%dir-placeholer%$cur\/conf%g" $WORK_DIR/dm-master1.toml
sed -i "s%dir-placeholer%$cur\/conf%g" $WORK_DIR/dm-master2.toml
Expand All @@ -116,6 +117,7 @@ function test_worker_handle_multi_tls_tasks() {
sed -i "s%dir-placeholer%$cur\/conf%g" $WORK_DIR/dm-worker2.toml
sed -i "s%dir-placeholer%$cur\/conf%g" $WORK_DIR/dm-task.yaml
sed -i "s%dir-placeholer%$cur\/conf%g" $WORK_DIR/dm-task-2.yaml
sed -i "s%dir-placeholer%$cur\/conf%g" $WORK_DIR/dm-task-3.yaml

run_dm_master $WORK_DIR/master1 $MASTER_PORT1 $WORK_DIR/dm-master1.toml
run_dm_master $WORK_DIR/master2 $MASTER_PORT2 $WORK_DIR/dm-master2.toml
Expand All @@ -138,6 +140,8 @@ function test_worker_handle_multi_tls_tasks() {
"start-task $WORK_DIR/dm-task.yaml --remove-meta=true"
run_dm_ctl_with_tls_and_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" $cur/conf/ca.pem $cur/conf/dm.pem $cur/conf/dm.key \
"start-task $WORK_DIR/dm-task-2.yaml --remove-meta=true"
run_dm_ctl_with_tls_and_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" $cur/conf/ca.pem $cur/conf/dm.pem $cur/conf/dm.key \
"start-task $WORK_DIR/dm-task-3.yaml --remove-meta=true"

run_dm_ctl_with_tls_and_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" $cur/conf/ca.pem $cur/conf/dm.pem $cur/conf/dm.key \
"query-status test" \
Expand All @@ -147,6 +151,10 @@ function test_worker_handle_multi_tls_tasks() {
"query-status test2" \
"\"result\": true" 2 \
"\"unit\": \"Sync\"" 1
run_dm_ctl_with_tls_and_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" $cur/conf/ca.pem $cur/conf/dm.pem $cur/conf/dm.key \
"query-status test3" \
"\"result\": true" 2 \
"\"unit\": \"Sync\"" 1

echo "check data"
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
Expand Down

0 comments on commit 19fc702

Please sign in to comment.