Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into remove__password
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Dec 19, 2024
2 parents a9dca17 + a3c9b79 commit 8c51587
Show file tree
Hide file tree
Showing 62 changed files with 826 additions and 412 deletions.
12 changes: 6 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6933,13 +6933,13 @@ def go_deps():
name = "com_github_tikv_client_go_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/client-go/v2",
sha256 = "4bc779621156c4ee6f46b57235da9c34c8ec0ee6d3be5f52e33da4c47098eeed",
strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20241120024459-05d115b3e88b",
sha256 = "844684ee6ae7decc5cadcab3f95c526b66878f8401c71cf82af68ec0cc5257d5",
strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20241209094930-06d7f4b9233b",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241120024459-05d115b3e88b.zip",
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241120024459-05d115b3e88b.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241120024459-05d115b3e88b.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241120024459-05d115b3e88b.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241209094930-06d7f4b9233b.zip",
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241209094930-06d7f4b9233b.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241209094930-06d7f4b9233b.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241209094930-06d7f4b9233b.zip",
],
)
go_repository(
Expand Down
23 changes: 18 additions & 5 deletions br/pkg/restore/snap_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const minBatchDdlSize = 1

type SnapClient struct {
restorer restore.SstRestorer
// Use a closure to lazy load checkpoint runner
getRestorerFn func(*checkpoint.CheckpointRunner[checkpoint.RestoreKeyType, checkpoint.RestoreValueType]) restore.SstRestorer
// Tool clients used by SnapClient
pdClient pd.Client
pdHTTPClient pdhttp.Client
Expand Down Expand Up @@ -148,7 +150,8 @@ type SnapClient struct {
rewriteMode RewriteMode

// checkpoint information for snapshot restore
checkpointRunner *checkpoint.CheckpointRunner[checkpoint.RestoreKeyType, checkpoint.RestoreValueType]
checkpointRunner *checkpoint.CheckpointRunner[checkpoint.RestoreKeyType, checkpoint.RestoreValueType]

checkpointChecksum map[int64]*checkpoint.ChecksumItem
}

Expand All @@ -168,7 +171,10 @@ func NewRestoreClient(
}
}

func (rc *SnapClient) GetRestorer() restore.SstRestorer {
func (rc *SnapClient) GetRestorer(checkpointRunner *checkpoint.CheckpointRunner[checkpoint.RestoreKeyType, checkpoint.RestoreValueType]) restore.SstRestorer {
if rc.restorer == nil {
rc.restorer = rc.getRestorerFn(checkpointRunner)
}
return rc.restorer
}

Expand Down Expand Up @@ -389,7 +395,10 @@ func (rc *SnapClient) InitCheckpoint(
return checkpointSetWithTableID, nil, errors.Trace(err)
}
rc.checkpointRunner, err = checkpoint.StartCheckpointRunnerForRestore(ctx, se, checkpoint.SnapshotRestoreCheckpointDatabaseName)
return checkpointSetWithTableID, checkpointClusterConfig, errors.Trace(err)
if err != nil {
return checkpointSetWithTableID, nil, errors.Trace(err)
}
return checkpointSetWithTableID, checkpointClusterConfig, nil
}

func (rc *SnapClient) WaitForFinishCheckpoint(ctx context.Context, flush bool) {
Expand Down Expand Up @@ -539,15 +548,19 @@ func (rc *SnapClient) initClients(ctx context.Context, backend *backuppb.Storage
return errors.Trace(err)
}
// Raw/Txn restore are not support checkpoint for now
rc.restorer = restore.NewSimpleSstRestorer(ctx, fileImporter, rc.workerPool, nil)
rc.getRestorerFn = func(checkpointRunner *checkpoint.CheckpointRunner[checkpoint.RestoreKeyType, checkpoint.RestoreValueType]) restore.SstRestorer {
return restore.NewSimpleSstRestorer(ctx, fileImporter, rc.workerPool, nil)
}
} else {
// or create a fileImporter with the cluster API version
fileImporter, err = NewSnapFileImporter(
ctx, rc.dom.Store().GetCodec().GetAPIVersion(), TiDBFull, opt)
if err != nil {
return errors.Trace(err)
}
rc.restorer = restore.NewMultiTablesRestorer(ctx, fileImporter, rc.workerPool, rc.checkpointRunner)
rc.getRestorerFn = func(checkpointRunner *checkpoint.CheckpointRunner[checkpoint.RestoreKeyType, checkpoint.RestoreValueType]) restore.SstRestorer {
return restore.NewMultiTablesRestorer(ctx, fileImporter, rc.workerPool, checkpointRunner)
}
}
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/restore/snap_client/tikv_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ func (rc *SnapClient) RestoreSSTFiles(
}
})

retErr = rc.restorer.GoRestore(onProgress, tableIDWithFilesGroup...)
r := rc.GetRestorer(rc.checkpointRunner)
retErr = r.GoRestore(onProgress, tableIDWithFilesGroup...)
if retErr != nil {
return retErr
}
return rc.restorer.WaitUntilFinish()
return r.WaitUntilFinish()
}
4 changes: 2 additions & 2 deletions br/pkg/task/restore_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ func RunRestoreRaw(c context.Context, g glue.Glue, cmdName string, cfg *RestoreR
defer restore.RestorePostWork(ctx, importModeSwitcher, restoreSchedulers, cfg.Online)

start := time.Now()
err = client.GetRestorer().GoRestore(onProgress, restore.CreateUniqueFileSets(files))
err = client.GetRestorer(nil).GoRestore(onProgress, restore.CreateUniqueFileSets(files))
if err != nil {
return errors.Trace(err)
}
err = client.GetRestorer().WaitUntilFinish()
err = client.GetRestorer(nil).WaitUntilFinish()
if err != nil {
return errors.Trace(err)
}
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/task/restore_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func RunRestoreTxn(c context.Context, g glue.Glue, cmdName string, cfg *Config)
}
defer restore.RestorePostWork(ctx, importModeSwitcher, restoreSchedulers, false)

err = client.GetRestorer().GoRestore(onProgress, restore.CreateUniqueFileSets(files))
err = client.GetRestorer(nil).GoRestore(onProgress, restore.CreateUniqueFileSets(files))
if err != nil {
return errors.Trace(err)
}
err = client.GetRestorer().WaitUntilFinish()
err = client.GetRestorer(nil).WaitUntilFinish()
if err != nil {
return errors.Trace(err)
}
Expand Down
10 changes: 7 additions & 3 deletions br/tests/br_restore_checkpoint/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ if [ $restore_fail -ne 1 ]; then
fi

# PITR with checkpoint but failed in the log restore metakv stage
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/restore/snap_client/corrupt-files=return(\"only-last-table-files\");\
github.com/pingcap/tidb/br/pkg/restore/log_client/failed-after-id-maps-saved=return(true)"
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/restore/snap_client/corrupt-files=return(\"only-last-table-files\")"
export GO_FAILPOINTS=$GO_FAILPOINTS";github.com/pingcap/tidb/br/pkg/restore/log_client/failed-after-id-maps-saved=return(true)"
restore_fail=0
run_br --pd $PD_ADDR restore point --full-backup-storage "local://$TEST_DIR/$PREFIX/full" -s "local://$TEST_DIR/$PREFIX/log" || restore_fail=1
export GO_FAILPOINTS=""
if [ $restore_fail -ne 1 ]; then
echo 'PITR success'
echo 'PITR success, but should fail'
exit 1
fi

# check the snapshot restore has checkpoint data
run_sql 'select count(*) from '"__TiDB_BR_Temporary_Snapshot_Restore_Checkpoint"'.`cpt_data`;'
check_contains "count(*): 1"

# PITR with checkpoint but failed in the log restore datakv stage
# skip the snapshot restore stage
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/task/corrupt-files=return(\"corrupt-last-table-files\")"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ require (
github.com/tdakkota/asciicheck v0.2.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tidwall/btree v1.7.0
github.com/tikv/client-go/v2 v2.0.8-0.20241120024459-05d115b3e88b
github.com/tikv/client-go/v2 v2.0.8-0.20241209094930-06d7f4b9233b
github.com/tikv/pd/client v0.0.0-20241111073742-238d4d79ea31
github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a
github.com/twmb/murmur3 v1.1.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tikv/client-go/v2 v2.0.8-0.20241120024459-05d115b3e88b h1:/hmt2FCt34rCVBX9dswiSdHOkppP67VWaESryTxDKc8=
github.com/tikv/client-go/v2 v2.0.8-0.20241120024459-05d115b3e88b/go.mod h1:NI2GfVlB9n7DsIGCxrKcD4psrcuFNEV8m1BgyzK1Amc=
github.com/tikv/client-go/v2 v2.0.8-0.20241209094930-06d7f4b9233b h1:x8E2J8UuUa2ysUkgVfNGgiXxZ9nfqBpQ43PBLwmCitU=
github.com/tikv/client-go/v2 v2.0.8-0.20241209094930-06d7f4b9233b/go.mod h1:NI2GfVlB9n7DsIGCxrKcD4psrcuFNEV8m1BgyzK1Amc=
github.com/tikv/pd/client v0.0.0-20241111073742-238d4d79ea31 h1:oAYc4m5Eu1OY9ogJ103VO47AYPHvhtzbUPD8L8B67Qk=
github.com/tikv/pd/client v0.0.0-20241111073742-238d4d79ea31/go.mod h1:W5a0sDadwUpI9k8p7M77d3jo253ZHdmua+u4Ho4Xw8U=
github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a h1:A6uKudFIfAEpoPdaal3aSqGxBzLyU8TqyXImLwo6dIo=
Expand Down
2 changes: 1 addition & 1 deletion pkg/bindinfo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ go_test(
srcs = [
"binding_cache_test.go",
"binding_match_test.go",
"fuzzy_binding_test.go",
"cross_db_binding_test.go",
"global_handle_test.go",
"main_test.go",
"optimize_test.go",
Expand Down
4 changes: 2 additions & 2 deletions pkg/bindinfo/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Binding struct {
SQLDigest string
PlanDigest string

// TableNames records all schema and table names in this binding statement, which are used for fuzzy matching.
// TableNames records all schema and table names in this binding statement, which are used for cross-db matching.
TableNames []*ast.TableName `json:"-"`
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func prepareHints(sctx sessionctx.Context, binding *Binding) (rerr error) {
return err
}
tableNames := CollectTableNames(bindingStmt)
isFuzzy := isFuzzyBinding(bindingStmt)
isFuzzy := isCrossDBBinding(bindingStmt)
if isFuzzy {
dbName = "*" // ues '*' for universal bindings
}
Expand Down
Loading

0 comments on commit 8c51587

Please sign in to comment.