Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
dumpling: fix default values changed when specified extra-args (#1188)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>

Co-authored-by: lance6716 <[email protected]>
  • Loading branch information
ti-srebot and lance6716 authored Oct 21, 2020
1 parent fc28d0c commit 5bfbd8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
9 changes: 7 additions & 2 deletions dumpling/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
30 changes: 28 additions & 2 deletions dumpling/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}

0 comments on commit 5bfbd8a

Please sign in to comment.