diff --git a/dumpling/util.go b/dumpling/util.go index ca436d0141..a1a5880593 100644 --- a/dumpling/util.go +++ b/dumpling/util.go @@ -94,7 +94,12 @@ func parseExtraArgs(logger *log.Logger, dumpCfg *export.Config, args []string) e } } - dumpCfg.FileSize, err = parseFileSize(fileSizeStr) + if fileSizeStr != "" { + dumpCfg.FileSize, err = parseFileSize(fileSizeStr) + if err != nil { + return err + } + } if len(tablesList) > 0 || (len(filters) != 1 || filters[0] != "*.*") { ff, err2 := parseTableFilter(tablesList, filters) @@ -105,7 +110,7 @@ func parseExtraArgs(logger *log.Logger, dumpCfg *export.Config, args []string) e logger.Warn("overwrite `block-allow-list` by `tables-list` or `filter`") } - return err + return nil } func parseFileSize(fileSizeStr string) (uint64, error) { diff --git a/dumpling/util_test.go b/dumpling/util_test.go index 4359737ea8..fc9ab1ce20 100644 --- a/dumpling/util_test.go +++ b/dumpling/util_test.go @@ -16,10 +16,13 @@ package dumpling import ( "strings" + "github.com/docker/go-units" + . "github.com/pingcap/check" + "github.com/pingcap/tidb-tools/pkg/filter" + tfilter "github.com/pingcap/tidb-tools/pkg/table-filter" + "github.com/pingcap/dm/dm/config" "github.com/pingcap/dm/pkg/log" - - . "github.com/pingcap/check" ) func (m *testDumplingSuite) TestParseArgs(c *C) { @@ -86,3 +89,26 @@ func (m *testDumplingSuite) TestParseArgs(c *C) { err = parseExtraArgs(&logger, exportCfg, strings.Fields(extraArgs)) c.Assert(err.Error(), Equals, "cannot both specify `--no-locks` and `--consistency` other than `none`") } + +func (m *testDumplingSuite) TestParseArgsWontOverwrite(c *C) { + cfg := &config.SubTaskConfig{} + cfg.ChunkFilesize = "1" + rules := &filter.Rules{ + DoDBs: []string{"unit_test"}, + } + cfg.BAList = rules + // make sure we enter `parseExtraArgs` + cfg.ExtraArgs = "--statement-size=4000 --consistency lock" + + d := NewDumpling(cfg) + exportCfg, err := d.constructArgs() + c.Assert(err, IsNil) + + c.Assert(exportCfg.FileSize, Equals, uint64(1*units.MiB)) + + f, err2 := tfilter.ParseMySQLReplicationRules(rules) + c.Assert(err2, IsNil) + c.Assert(exportCfg.TableFilter, DeepEquals, tfilter.CaseInsensitive(f)) + + c.Assert(exportCfg.Consistency, Equals, "lock") +}