Skip to content

Commit 8215b0c

Browse files
authored
lightning: make OpLevelOptional suppress the error of DoChecksum (#45486) (#45867)
close #45382
1 parent 9162286 commit 8215b0c

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

br/pkg/lightning/importer/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ go_library(
8383
"@com_github_tikv_pd_client//:client",
8484
"@io_etcd_go_etcd_client_v3//:client",
8585
"@org_golang_google_grpc//:grpc",
86+
"@org_golang_google_grpc//codes",
87+
"@org_golang_google_grpc//status",
8688
"@org_golang_x_exp//maps",
8789
"@org_golang_x_exp//slices",
8890
"@org_golang_x_sync//errgroup",

br/pkg/lightning/importer/table_import.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import (
5454
"go.uber.org/multierr"
5555
"go.uber.org/zap"
5656
"golang.org/x/exp/slices"
57+
"google.golang.org/grpc/codes"
58+
"google.golang.org/grpc/status"
5759
)
5860

5961
// TableImporter is a helper struct to import a table.
@@ -988,15 +990,26 @@ func (tr *TableImporter) postProcess(
988990

989991
var remoteChecksum *local.RemoteChecksum
990992
remoteChecksum, err = DoChecksum(ctx, tr.tableInfo)
993+
failpoint.Inject("checksum-error", func() {
994+
tr.logger.Info("failpoint checksum-error injected.")
995+
remoteChecksum = nil
996+
err = status.Error(codes.Unknown, "Checksum meets error.")
997+
})
991998
if err != nil {
992-
return false, err
999+
if rc.cfg.PostRestore.Checksum != config.OpLevelOptional {
1000+
return false, err
1001+
}
1002+
tr.logger.Warn("do checksum failed, will skip this error and go on", log.ShortError(err))
1003+
err = nil
9931004
}
994-
err = tr.compareChecksum(remoteChecksum, localChecksum)
995-
// with post restore level 'optional', we will skip checksum error
996-
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
997-
if err != nil {
998-
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
999-
err = nil
1005+
if remoteChecksum != nil {
1006+
err = tr.compareChecksum(remoteChecksum, localChecksum)
1007+
// with post restore level 'optional', we will skip checksum error
1008+
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
1009+
if err != nil {
1010+
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
1011+
err = nil
1012+
}
10001013
}
10011014
}
10021015
} else {
@@ -1054,11 +1067,12 @@ func (tr *TableImporter) postProcess(
10541067
case forcePostProcess || !rc.cfg.PostRestore.PostProcessAtLast:
10551068
err := tr.analyzeTable(ctx, rc.db)
10561069
// witch post restore level 'optional', we will skip analyze error
1057-
if rc.cfg.PostRestore.Analyze == config.OpLevelOptional {
1058-
if err != nil {
1059-
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
1060-
err = nil
1070+
if err != nil {
1071+
if rc.cfg.PostRestore.Analyze != config.OpLevelOptional {
1072+
return false, err
10611073
}
1074+
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
1075+
err = nil
10621076
}
10631077
saveCpErr := rc.saveStatusCheckpoint(ctx, tr.tableName, checkpoints.WholeTableEngineID, err, checkpoints.CheckpointStatusAnalyzed)
10641078
if err = firstErr(err, saveCpErr); err != nil {

br/tests/lightning_routes/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ schema-pattern = "routes_a*"
88
table-pattern = "t*"
99
target-schema = "routes_b"
1010
target-table = "u"
11+
12+
[post-restore]
13+
checksum = "optional"

br/tests/lightning_routes/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
set -eux
66

7+
echo "testing checksum-error..."
8+
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/lightning/importer/checksum-error=1*return()"
9+
710
run_sql 'DROP DATABASE IF EXISTS routes_a0;'
811
run_sql 'DROP DATABASE IF EXISTS routes_a1;'
912
run_sql 'DROP DATABASE IF EXISTS routes_b;'
1013

1114
run_lightning
1215

16+
echo "test checksum-error success!"
17+
1318
run_sql 'SELECT count(1), sum(x) FROM routes_b.u;'
1419
check_contains 'count(1): 4'
1520
check_contains 'sum(x): 259'

0 commit comments

Comments
 (0)