Skip to content

Commit

Permalink
br: skip fresh check when user has specified --filter in restore full (
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Feb 8, 2024
1 parent e9de9a5 commit ee52a5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,8 @@ func (rc *Client) createTablesInWorkerPool(ctx context.Context, dom *domain.Doma
}

// NeedCheckFreshCluster is every time. except restore from a checkpoint or user has not set filter argument.
func (rc *Client) NeedCheckFreshCluster(ExplicitFilter bool, checkpointsMap map[int64]map[string]struct{}) bool {
return rc.IsFull() && !ExplicitFilter && len(checkpointsMap) == 0
func (rc *Client) NeedCheckFreshCluster(ExplicitFilter bool, firstRun bool) bool {
return rc.IsFull() && !ExplicitFilter && firstRun
}

// CheckTargetClusterFresh check whether the target cluster is fresh or not
Expand Down
18 changes: 9 additions & 9 deletions br/pkg/restore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,24 @@ func TestNeedCheckTargetClusterFresh(t *testing.T) {
err := client.Init(g, cluster.Storage)
require.NoError(t, err)

require.True(t, client.NeedCheckFreshCluster(false, nil))
// not set filter and first run with checkpoint
require.True(t, client.NeedCheckFreshCluster(false, true))

checkpointsMap := make(map[int64]map[string]struct{})
require.True(t, client.NeedCheckFreshCluster(false, checkpointsMap))
// skip check when has checkpoint
require.False(t, client.NeedCheckFreshCluster(false, false))

// skip check when has checkpoints
checkpointsMap[1] = make(map[string]struct{})
require.False(t, client.NeedCheckFreshCluster(false, checkpointsMap))
// skip check when set --filter
require.False(t, client.NeedCheckFreshCluster(true, false))

// skip check when has set --filter
require.False(t, client.NeedCheckFreshCluster(true, checkpointsMap))
// skip check when has set --filter and has checkpoint
require.False(t, client.NeedCheckFreshCluster(true, true))

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/br/pkg/restore/mock-incr-backup-data", "return(false)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/br/pkg/restore/mock-incr-backup-data"))
}()
// skip check when increment backup
require.False(t, client.NeedCheckFreshCluster(false, nil))
require.False(t, client.NeedCheckFreshCluster(false, true))
}

func TestCheckTargetClusterFresh(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
}

if isFullRestore(cmdName) {
if client.NeedCheckFreshCluster(cfg.ExplicitFilter, checkpointSetWithTableID) {
if client.NeedCheckFreshCluster(cfg.ExplicitFilter, checkpointFirstRun) {
if err = client.CheckTargetClusterFresh(ctx); err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit ee52a5f

Please sign in to comment.