Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dm: fix empty config cause dm-master panic #5298

Merged
merged 7 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions dm/dm/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,11 @@ func (c *TaskConfig) adjust() error {
rule, ok := c.Mydumpers[inst.MydumperConfigName]
if !ok {
return terror.ErrConfigMydumperCfgNotFound.Generate(i, inst.MydumperConfigName)
} else if rule != nil {
globalConfigReferCount[configRefPrefixes[mydumperIdx]+inst.MydumperConfigName]++
inst.Mydumper = new(MydumperConfig)
*inst.Mydumper = *rule // ref mydumper config
}
globalConfigReferCount[configRefPrefixes[mydumperIdx]+inst.MydumperConfigName]++
inst.Mydumper = new(MydumperConfig)
*inst.Mydumper = *rule // ref mydumper config
}
if inst.Mydumper == nil {
if len(c.Mydumpers) != 0 {
Expand All @@ -717,10 +718,11 @@ func (c *TaskConfig) adjust() error {
rule, ok := c.Loaders[inst.LoaderConfigName]
if !ok {
return terror.ErrConfigLoaderCfgNotFound.Generate(i, inst.LoaderConfigName)
} else if rule != nil {
globalConfigReferCount[configRefPrefixes[loaderIdx]+inst.LoaderConfigName]++
inst.Loader = new(LoaderConfig)
*inst.Loader = *rule // ref loader config
}
globalConfigReferCount[configRefPrefixes[loaderIdx]+inst.LoaderConfigName]++
inst.Loader = new(LoaderConfig)
*inst.Loader = *rule // ref loader config
}
if inst.Loader == nil {
if len(c.Loaders) != 0 {
Expand All @@ -737,10 +739,11 @@ func (c *TaskConfig) adjust() error {
rule, ok := c.Syncers[inst.SyncerConfigName]
if !ok {
return terror.ErrConfigSyncerCfgNotFound.Generate(i, inst.SyncerConfigName)
} else if rule != nil {
globalConfigReferCount[configRefPrefixes[syncerIdx]+inst.SyncerConfigName]++
inst.Syncer = new(SyncerConfig)
*inst.Syncer = *rule // ref syncer config
}
globalConfigReferCount[configRefPrefixes[syncerIdx]+inst.SyncerConfigName]++
inst.Syncer = new(SyncerConfig)
*inst.Syncer = *rule // ref syncer config
}
if inst.Syncer == nil {
if len(c.Syncers) != 0 {
Expand Down Expand Up @@ -816,10 +819,7 @@ func (c *TaskConfig) adjust() error {
unusedConfigs = append(unusedConfigs, mydumper)
}
}
for loader, cfg := range c.Loaders {
if err1 := cfg.adjust(); err1 != nil {
return err1
}
for loader := range c.Loaders {
if globalConfigReferCount[configRefPrefixes[loaderIdx]+loader] == 0 {
unusedConfigs = append(unusedConfigs, loader)
}
Expand All @@ -844,6 +844,13 @@ func (c *TaskConfig) adjust() error {
sort.Strings(unusedConfigs)
return terror.ErrConfigGlobalConfigsUnused.Generate(unusedConfigs)
}

for _, cfg := range c.Loaders {
if err1 := cfg.adjust(); err1 != nil {
return err1
}
}

// we postpone default time_zone init in each unit so we won't change the config value in task/sub_task config
if c.Timezone != "" {
if _, err := utils.ParseTimeZone(c.Timezone); err != nil {
Expand Down
28 changes: 28 additions & 0 deletions dm/tests/dmctl_basic/check_list/start_task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,31 @@ function start_task_not_pass_with_message() {
"start-task $task_conf" \
"$2" 1
}

function start_task_empty_config() {
start_task_empty_dump_config $1
start_task_empty_load_config $1
start_task_empty_sync_config $1
}

function start_task_empty_dump_config() {
sed "/threads/d" $1 >/tmp/empty-dump.yaml
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"start-task /tmp/empty-dump.yaml" \
"The configurations as following .* are set in global configuration but instances don't use them" 1
}

function start_task_empty_load_config() {
sed "/pool-size/d" $1 >/tmp/empty-load.yaml
cat /tmp/empty-load.yaml
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"start-task /tmp/empty-load.yaml" \
"The configurations as following .* are set in global configuration but instances don't use them" 1
}

function start_task_empty_sync_config() {
sed "/worker-count/d" $1 >/tmp/empty-sync.yaml
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"start-task /tmp/empty-sync.yaml" \
"The configurations as following .* are set in global configuration but instances don't use them" 1
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
}
27 changes: 27 additions & 0 deletions dm/tests/dmctl_basic/conf/empty-unit-task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: test
task-mode: all

target-database:
host: "127.0.0.1"
port: 4000
user: "root"
password: ""

mysql-instances:
- source-id: "mysql-replica-01"
mydumper-config-name: "global"
loader-config-name: "global"
syncer-config-name: "global"

mydumpers:
global:
threads: 4

loaders:
global:
pool-size: 16

syncers:
global:
worker-count: 32
3 changes: 3 additions & 0 deletions dm/tests/dmctl_basic/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ function run() {
"stop-task $cur/conf/only_warning.yaml" \
"\"result\": true" 2

echo "start task with empty unit config"
start_task_empty_config $cur/conf/empty-unit-task.yaml

cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task-error-database-config.yaml
sed -i "s/password: \"\"/password: \"wrond password\"/g" $WORK_DIR/dm-task-error-database-config.yaml
check_task_error_database_config $WORK_DIR/dm-task-error-database-config.yaml
Expand Down