Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
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
10 changes: 9 additions & 1 deletion v4/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewDumper(ctx context.Context, conf *Config) (*Dumper, error) {
openSQLDB,
detectServerInfo,
resolveAutoConsistency,

validateResolveAutoConsistency,
tidbSetPDClientForGC,
tidbGetSnapshot,
tidbStartGCSavepointUpdateService,
Expand Down Expand Up @@ -1074,6 +1074,14 @@ func resolveAutoConsistency(d *Dumper) error {
return nil
}

func validateResolveAutoConsistency(d *Dumper) error {
conf := d.conf
if conf.Consistency != consistencyTypeSnapshot && conf.Snapshot != "" {
return errors.Errorf("can't specify --snapshot when --consistency isn't snapshot, resolved consistency: %s", conf.Consistency)
}
return nil
}

// tidbSetPDClientForGC is an initialization step of Dumper.
func tidbSetPDClientForGC(d *Dumper) error {
tctx, si, pool := d.tctx, d.conf.ServerInfo, d.dbHandle
Expand Down
35 changes: 35 additions & 0 deletions v4/export/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

tcontext "github.com/pingcap/dumpling/v4/context"
"github.com/pingcap/errors"
"github.com/stretchr/testify/require"

"github.com/DATA-DOG/go-sqlmock"
Expand Down Expand Up @@ -307,3 +308,37 @@ func TestConfigValidation(t *testing.T) {
conf.FileType = "rand_str"
require.EqualError(t, adjustFileFormat(conf), "unknown config.FileType 'rand_str'")
}

func TestValidateResolveAutoConsistency(t *testing.T) {
Comment thread
lichunzhu marked this conversation as resolved.
t.Parallel()

conf1 := defaultConfigForTest(t)
d := &Dumper{conf: conf1}
conf := d.conf

testCases := []struct {
confConsistency string
confSnapshot string
err error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that using string here is enough.

}{
{consistencyTypeAuto, "", nil},
{consistencyTypeAuto, "123", errors.New("can't specify --snapshot when --consistency isn't snapshot, resolved consistency: auto")},
{consistencyTypeFlush, "", nil},
{consistencyTypeFlush, "456", errors.New("can't specify --snapshot when --consistency isn't snapshot, resolved consistency: flush")},
{consistencyTypeLock, "", nil},
{consistencyTypeLock, "789", errors.New("can't specify --snapshot when --consistency isn't snapshot, resolved consistency: lock")},
{consistencyTypeSnapshot, "", nil},
{consistencyTypeSnapshot, "456", nil},
{consistencyTypeNone, "", nil},
{consistencyTypeNone, "123", errors.New("can't specify --snapshot when --consistency isn't snapshot, resolved consistency: none")},
}
for _, testCase := range testCases {
conf.Consistency = testCase.confConsistency
conf.Snapshot = testCase.confSnapshot
if testCase.err == nil {
require.NoError(t, validateResolveAutoConsistency(d))
} else {
require.EqualError(t, validateResolveAutoConsistency(d), testCase.err.Error())
}
}
}