diff --git a/v4/export/dump.go b/v4/export/dump.go index ed36b207..dc2734db 100755 --- a/v4/export/dump.go +++ b/v4/export/dump.go @@ -71,7 +71,7 @@ func NewDumper(ctx context.Context, conf *Config) (*Dumper, error) { openSQLDB, detectServerInfo, resolveAutoConsistency, - + validateResolveAutoConsistency, tidbSetPDClientForGC, tidbGetSnapshot, tidbStartGCSavepointUpdateService, @@ -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 diff --git a/v4/export/prepare_test.go b/v4/export/prepare_test.go index bfe3fa9b..cb02729b 100644 --- a/v4/export/prepare_test.go +++ b/v4/export/prepare_test.go @@ -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)) + } + } +}