From 833bb091e627ce1de67386bee1b6acf22091bcbc Mon Sep 17 00:00:00 2001 From: Jianjun Liao <36503113+Leavrth@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:45:12 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #58525 Signed-off-by: ti-chi-bot --- br/pkg/task/restore.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/br/pkg/task/restore.go b/br/pkg/task/restore.go index 4a1a3e99c24dd..ab8fd2b658d51 100644 --- a/br/pkg/task/restore.go +++ b/br/pkg/task/restore.go @@ -809,6 +809,18 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s if client.IsRawKvMode() { return errors.Annotate(berrors.ErrRestoreModeMismatch, "cannot do transactional restore from raw kv data") } + if client.IsIncremental() { + // don't support checkpoint for the ddl restore + log.Info("the incremental snapshot restore doesn't support checkpoint mode, disable checkpoint.") + cfg.UseCheckpoint = false + } + var checkpointFirstRun = true + if cfg.UseCheckpoint { + // if the checkpoint metadata exists in the checkpoint storage, the restore is not + // for the first time. + existsCheckpointMetadata := checkpoint.ExistsSstRestoreCheckpoint(ctx, mgr.GetDomain(), checkpoint.SnapshotRestoreCheckpointDatabaseName) + checkpointFirstRun = !existsCheckpointMetadata + } if err = CheckRestoreDBAndTable(client.GetDatabases(), cfg); err != nil { return err } @@ -817,7 +829,7 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s return errors.Annotate(berrors.ErrRestoreInvalidBackup, "contain tables but no databases") } - if cfg.CheckRequirements { + if cfg.CheckRequirements && checkpointFirstRun { if err := checkDiskSpace(ctx, mgr, files, tables); err != nil { return errors.Trace(err) } @@ -837,12 +849,6 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s return checkInfo.FullRestoreCheckErr } - if client.IsIncremental() { - // don't support checkpoint for the ddl restore - log.Info("the incremental snapshot restore doesn't support checkpoint mode, disable checkpoint.") - cfg.UseCheckpoint = false - } - importModeSwitcher := restore.NewImportModeSwitcher(mgr.GetPDClient(), cfg.Config.SwitchModeInterval, mgr.GetTLSConfig()) restoreSchedulers, schedulersConfig, err := restore.RestorePreWork(ctx, mgr, importModeSwitcher, cfg.Online, true) if err != nil { @@ -863,6 +869,7 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s log.Info("finish removing pd scheduler") }() +<<<<<<< HEAD var checkpointFirstRun = true if cfg.UseCheckpoint { // if the checkpoint metadata exists in the checkpoint storage, the restore is not @@ -871,6 +878,8 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s checkpointFirstRun = !existsCheckpointMetadata } +======= +>>>>>>> 444a1b9dab1 (br: precheck disk space only when checkpoint first run (#58525)) if isFullRestore(cmdName) { if client.NeedCheckFreshCluster(cfg.ExplicitFilter, checkpointFirstRun) { if err = client.CheckTargetClusterFresh(ctx); err != nil { From f5e9baf3def9a32490b857937612665085a1c574 Mon Sep 17 00:00:00 2001 From: Jianjun Liao Date: Thu, 16 Jan 2025 16:17:42 +0800 Subject: [PATCH 2/2] resolve conflicts Signed-off-by: Jianjun Liao --- br/pkg/task/restore.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/br/pkg/task/restore.go b/br/pkg/task/restore.go index ab8fd2b658d51..f3ecf5307d60c 100644 --- a/br/pkg/task/restore.go +++ b/br/pkg/task/restore.go @@ -818,7 +818,7 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s if cfg.UseCheckpoint { // if the checkpoint metadata exists in the checkpoint storage, the restore is not // for the first time. - existsCheckpointMetadata := checkpoint.ExistsSstRestoreCheckpoint(ctx, mgr.GetDomain(), checkpoint.SnapshotRestoreCheckpointDatabaseName) + existsCheckpointMetadata := checkpoint.ExistsSnapshotRestoreCheckpoint(ctx, mgr.GetDomain()) checkpointFirstRun = !existsCheckpointMetadata } if err = CheckRestoreDBAndTable(client.GetDatabases(), cfg); err != nil { @@ -869,17 +869,6 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s log.Info("finish removing pd scheduler") }() -<<<<<<< HEAD - var checkpointFirstRun = true - if cfg.UseCheckpoint { - // if the checkpoint metadata exists in the checkpoint storage, the restore is not - // for the first time. - existsCheckpointMetadata := checkpoint.ExistsSnapshotRestoreCheckpoint(ctx, mgr.GetDomain()) - checkpointFirstRun = !existsCheckpointMetadata - } - -======= ->>>>>>> 444a1b9dab1 (br: precheck disk space only when checkpoint first run (#58525)) if isFullRestore(cmdName) { if client.NeedCheckFreshCluster(cfg.ExplicitFilter, checkpointFirstRun) { if err = client.CheckTargetClusterFresh(ctx); err != nil {