Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore: allow restore accross one major version #33203

Merged
merged 10 commits into from
Mar 17, 2022
2 changes: 1 addition & 1 deletion br/pkg/task/backup_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func RunBackupRaw(c context.Context, g glue.Glue, cmdName string, cfg *RawKvConf
req := backuppb.BackupRequest{
ClusterId: client.GetClusterID(),
StartKey: backupRange.StartKey,
EndKey: backupRange.StartKey,
EndKey: backupRange.EndKey,
StartVersion: 0,
EndVersion: 0,
RateLimit: cfg.RateLimit,
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func CheckClusterVersion(ctx context.Context, client pd.Client, checker VerCheck
// CheckVersionForBackup checks the version for backup and
func CheckVersionForBackup(backupVersion *semver.Version) VerChecker {
return func(store *metapb.Store, ver *semver.Version) error {
if backupVersion.Major > ver.Major {
if backupVersion.Major > ver.Major && backupVersion.Major-ver.Major > 1 {
return errors.Annotatef(berrors.ErrVersionMismatch,
"backup with cluster version %s cannot be restored at cluster of version %s: major version mismatches",
backupVersion, ver)
Expand Down
11 changes: 10 additions & 1 deletion br/pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,20 @@ func TestCheckClusterVersion(t *testing.T) {
}

{
// Restore across major version isn't allowed.
// Restore across one major version allowed.
mock.getAllStores = func() []*metapb.Store {
return []*metapb.Store{{Version: "v4.0.0-rc.1"}}
}
err := CheckClusterVersion(context.Background(), &mock, CheckVersionForBackup(semver.New("5.0.0-rc")))
require.NoError(t, err)
}

{
// Restore across two major versions isn't allowed.
mock.getAllStores = func() []*metapb.Store {
return []*metapb.Store{{Version: "v4.0.0-rc.1"}}
}
err := CheckClusterVersion(context.Background(), &mock, CheckVersionForBackup(semver.New("6.0.0")))
require.Error(t, err)
}

Expand Down
9 changes: 8 additions & 1 deletion ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,21 @@ func checkHistoryJobInTest(ctx sessionctx.Context, historyJob *model.Job) {
if _, ok := st.(*ast.CreatePlacementPolicyStmt); !ok {
panic(fmt.Sprintf("job ID %d, parse ddl job failed, query %s", historyJob.ID, historyJob.Query))
}
case model.ActionCreateTable, model.ActionCreateTables:
case model.ActionCreateTable:
if _, ok := st.(*ast.CreateTableStmt); !ok {
panic(fmt.Sprintf("job ID %d, parse ddl job failed, query %s", historyJob.ID, historyJob.Query))
}
case model.ActionCreateSchema:
if _, ok := st.(*ast.CreateDatabaseStmt); !ok {
panic(fmt.Sprintf("job ID %d, parse ddl job failed, query %s", historyJob.ID, historyJob.Query))
}
case model.ActionCreateTables:
_, isCreateTable := st.(*ast.CreateTableStmt)
_, isCreateSeq := st.(*ast.CreateSequenceStmt)
_, isCreateView := st.(*ast.CreateViewStmt)
if !isCreateTable && !isCreateSeq && !isCreateView {
panic(fmt.Sprintf("job ID %d, parse ddl job failed, query %s", historyJob.ID, historyJob.Query))
}
default:
if _, ok := st.(ast.DDLNode); !ok {
panic(fmt.Sprintf("job ID %d, parse ddl job failed, query %s", historyJob.ID, historyJob.Query))
Expand Down