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 all 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
34 changes: 34 additions & 0 deletions v4/export/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,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) {
t.Parallel()

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

testCases := []struct {
confConsistency string
confSnapshot string
err bool
}{
{consistencyTypeAuto, "", true},
{consistencyTypeAuto, "123", false},
{consistencyTypeFlush, "", true},
{consistencyTypeFlush, "456", false},
{consistencyTypeLock, "", true},
{consistencyTypeLock, "789", false},
{consistencyTypeSnapshot, "", true},
{consistencyTypeSnapshot, "456", true},
{consistencyTypeNone, "", true},
{consistencyTypeNone, "123", false},
}
for _, testCase := range testCases {
conf.Consistency = testCase.confConsistency
conf.Snapshot = testCase.confSnapshot
if testCase.err == true {
require.NoError(t, validateResolveAutoConsistency(d))
} else {
require.EqualError(t, validateResolveAutoConsistency(d), fmt.Sprintf("can't specify --snapshot when --consistency isn't snapshot, resolved consistency: %s", conf.Consistency))
}
}
}