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 authored Feb 7, 2024
1 parent c532752 commit 9553bc6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,11 @@ func (rc *Client) createTablesInWorkerPool(ctx context.Context, dom *domain.Doma
return eg.Wait()
}

// NeedCheckFreshCluster is every time. except restore from a checkpoint or user has not set filter argument.
func (rc *Client) NeedCheckFreshCluster(ExplicitFilter bool, firstRun bool) bool {
return rc.IsFull() && !ExplicitFilter && firstRun
}

// CheckTargetClusterFresh check whether the target cluster is fresh or not
// if there's no user dbs or tables, we take it as a fresh cluster, although
// user may have created some users or made other changes.
Expand Down
30 changes: 30 additions & 0 deletions br/pkg/restore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ func getStartedMockedCluster(t *testing.T) *mock.Cluster {
return cluster
}

func TestNeedCheckTargetClusterFresh(t *testing.T) {
// cannot use shared `mc`, other parallel case may change it.
cluster := getStartedMockedCluster(t)
defer cluster.Stop()

g := gluetidb.New()
client := restore.NewRestoreClient(cluster.PDClient, cluster.PDHTTPCli, nil, defaultKeepaliveCfg, false)
err := client.Init(g, cluster.Storage)
require.NoError(t, err)

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

// skip check when has checkpoint
require.False(t, client.NeedCheckFreshCluster(false, false))

// skip check when set --filter
require.False(t, client.NeedCheckFreshCluster(true, false))

// 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, true))
}

func TestCheckTargetClusterFresh(t *testing.T) {
// cannot use shared `mc`, other parallel case may change it.
cluster := getStartedMockedCluster(t)
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,7 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
}

if isFullRestore(cmdName) {
// we need check cluster is fresh every time. except restore from a checkpoint.
if client.IsFull() && checkpointFirstRun {
if client.NeedCheckFreshCluster(cfg.ExplicitFilter, checkpointFirstRun) {
if err = client.CheckTargetClusterFresh(ctx); err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit 9553bc6

Please sign in to comment.