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 1 commit
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
8 changes: 8 additions & 0 deletions v4/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewDumper(ctx context.Context, conf *Config) (*Dumper, error) {
err := adjustConfig(conf,
registerTLSConfig,
validateSpecifiedSQL,
validateResolveAutoConsistency,

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.

Function validateResolveAutoConsistency should be after resolveAutoConsistency.

adjustFileFormat)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1074,6 +1075,13 @@ func resolveAutoConsistency(d *Dumper) error {
return nil
}

func validateResolveAutoConsistency(conf *Config) error {
if conf.Consistency == consistencyTypeSnapshot || conf.Snapshot != "" {

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.

function validateResolveAutoConsistency should be checked after resolveAutoConsistency.

Suggested change
if conf.Consistency == consistencyTypeSnapshot || conf.Snapshot != "" {
if conf.Consistency != consistencyTypeSnapshot && conf.Snapshot != "" {

return errors.New("can't specify both --consistency and --snapshot at the same time. snapshot consistency is not supported for this server")

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.

Suggested change
return errors.New("can't specify both --consistency and --snapshot at the same time. snapshot consistency is not supported for this server")
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
29 changes: 29 additions & 0 deletions v4/export/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,32 @@ 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()

conf := defaultConfigForTest(t)
conf.Consistency = consistencyTypeSnapshot
conf.Snapshot = "snapshot"
require.EqualError(t, validateResolveAutoConsistency(conf), "can't specify both --consistency and --snapshot at the same time. snapshot consistency is not supported for this server")

conf.Consistency = consistencyTypeSnapshot
conf.Snapshot = ""
require.EqualError(t, validateResolveAutoConsistency(conf), "can't specify both --consistency and --snapshot at the same time. snapshot consistency is not supported for this server")

conf.Consistency = consistencyTypeFlush
conf.Snapshot = ""
require.NoError(t, validateResolveAutoConsistency(conf))

conf.Consistency = consistencyTypeFlush
Comment thread
Ehco1996 marked this conversation as resolved.
Outdated
conf.Snapshot = "snapshot"
require.EqualError(t, validateResolveAutoConsistency(conf), "can't specify both --consistency and --snapshot at the same time. snapshot consistency is not supported for this server")

conf.Consistency = consistencyTypeNone
conf.Snapshot = ""
require.NoError(t, validateResolveAutoConsistency(conf))

conf.Consistency = consistencyTypeNone
conf.Snapshot = "snapshot"
require.EqualError(t, validateResolveAutoConsistency(conf), "can't specify both --consistency and --snapshot at the same time. snapshot consistency is not supported for this server")
}