From d61f8e07b9b3feb051b0c33f1b2de0a5c62dbbc7 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Thu, 17 Mar 2022 19:58:30 +0800 Subject: [PATCH] config(dm): fix can't downgrade config (#4936) ref pingcap/tiflow#4287 --- dm/dm/config/task.go | 23 ++++++++++++++++++++-- dm/tests/new_relay/configs/tasks/test.yaml | 2 -- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dm/dm/config/task.go b/dm/dm/config/task.go index 3b9a7d8d235..3d130de42b4 100644 --- a/dm/dm/config/task.go +++ b/dm/dm/config/task.go @@ -990,6 +990,25 @@ func NewMySQLInstancesForDowngrade(mysqlInstances []*MySQLInstance) []*MySQLInst return mysqlInstancesForDowngrade } +// LoaderConfigForDowngrade is the base configuration for loader in v2.0. +// This config is used for downgrade(config export) from a higher dmctl version. +// When we add any new config item into LoaderConfig, we should update it also. +type LoaderConfigForDowngrade struct { + PoolSize int `yaml:"pool-size" toml:"pool-size" json:"pool-size"` + Dir string `yaml:"dir" toml:"dir" json:"dir"` +} + +func NewLoaderConfigForDowngrade(loaderConfigs map[string]*LoaderConfig) map[string]*LoaderConfigForDowngrade { + loaderConfigsForDowngrade := make(map[string]*LoaderConfigForDowngrade, len(loaderConfigs)) + for k, v := range loaderConfigs { + loaderConfigsForDowngrade[k] = &LoaderConfigForDowngrade{ + PoolSize: v.PoolSize, + Dir: v.Dir, + } + } + return loaderConfigsForDowngrade +} + // SyncerConfigForDowngrade is the base configuration for syncer in v2.0. // This config is used for downgrade(config export) from a higher dmctl version. // When we add any new config item into SyncerConfig, we should update it also. @@ -1057,7 +1076,7 @@ type TaskConfigForDowngrade struct { BWList map[string]*filter.Rules `yaml:"black-white-list"` BAList map[string]*filter.Rules `yaml:"block-allow-list"` Mydumpers map[string]*MydumperConfig `yaml:"mydumpers"` - Loaders map[string]*LoaderConfig `yaml:"loaders"` + Loaders map[string]*LoaderConfigForDowngrade `yaml:"loaders"` Syncers map[string]*SyncerConfigForDowngrade `yaml:"syncers"` CleanDumpFile bool `yaml:"clean-dump-file"` EnableANSIQuotes bool `yaml:"ansi-quotes"` @@ -1092,7 +1111,7 @@ func NewTaskConfigForDowngrade(taskConfig *TaskConfig) *TaskConfigForDowngrade { BWList: taskConfig.BWList, BAList: taskConfig.BAList, Mydumpers: taskConfig.Mydumpers, - Loaders: taskConfig.Loaders, + Loaders: NewLoaderConfigForDowngrade(taskConfig.Loaders), Syncers: NewSyncerConfigsForDowngrade(taskConfig.Syncers), CleanDumpFile: taskConfig.CleanDumpFile, EnableANSIQuotes: taskConfig.EnableANSIQuotes, diff --git a/dm/tests/new_relay/configs/tasks/test.yaml b/dm/tests/new_relay/configs/tasks/test.yaml index 3040c12592c..8c174e41f7b 100644 --- a/dm/tests/new_relay/configs/tasks/test.yaml +++ b/dm/tests/new_relay/configs/tasks/test.yaml @@ -43,8 +43,6 @@ loaders: load-01: pool-size: 16 dir: ./dumped_data - import-mode: sql - on-duplicate: replace syncers: sync-01: meta-file: ""