Skip to content

Commit adf6de5

Browse files
authored
lightning: make OpLevelOptional suppress the error of DoChecksum (#45486) (#45866)
close #45382
1 parent 4973f87 commit adf6de5

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

br/pkg/lightning/restore/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ go_library(
8282
"@com_github_tikv_pd_client//:client",
8383
"@io_etcd_go_etcd_client_v3//:client",
8484
"@org_golang_google_grpc//:grpc",
85+
"@org_golang_google_grpc//codes",
8586
"@org_golang_google_grpc//keepalive",
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/restore/table_restore.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import (
4444
"go.uber.org/multierr"
4545
"go.uber.org/zap"
4646
"golang.org/x/exp/slices"
47+
"google.golang.org/grpc/codes"
48+
"google.golang.org/grpc/status"
4749
)
4850

4951
type TableRestore struct {
@@ -843,15 +845,26 @@ func (tr *TableRestore) postProcess(
843845

844846
var remoteChecksum *RemoteChecksum
845847
remoteChecksum, err = DoChecksum(ctx, tr.tableInfo)
848+
failpoint.Inject("checksum-error", func() {
849+
tr.logger.Info("failpoint checksum-error injected.")
850+
remoteChecksum = nil
851+
err = status.Error(codes.Unknown, "Checksum meets error.")
852+
})
846853
if err != nil {
847-
return false, err
854+
if rc.cfg.PostRestore.Checksum != config.OpLevelOptional {
855+
return false, err
856+
}
857+
tr.logger.Warn("do checksum failed, will skip this error and go on", log.ShortError(err))
858+
err = nil
848859
}
849-
err = tr.compareChecksum(remoteChecksum, localChecksum)
850-
// with post restore level 'optional', we will skip checksum error
851-
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
852-
if err != nil {
853-
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
854-
err = nil
860+
if remoteChecksum != nil {
861+
err = tr.compareChecksum(remoteChecksum, localChecksum)
862+
// with post restore level 'optional', we will skip checksum error
863+
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
864+
if err != nil {
865+
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
866+
err = nil
867+
}
855868
}
856869
}
857870
} else {
@@ -893,11 +906,12 @@ func (tr *TableRestore) postProcess(
893906
case forcePostProcess || !rc.cfg.PostRestore.PostProcessAtLast:
894907
err := tr.analyzeTable(ctx, rc.tidbGlue.GetSQLExecutor())
895908
// witch post restore level 'optional', we will skip analyze error
896-
if rc.cfg.PostRestore.Analyze == config.OpLevelOptional {
897-
if err != nil {
898-
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
899-
err = nil
909+
if err != nil {
910+
if rc.cfg.PostRestore.Analyze != config.OpLevelOptional {
911+
return false, err
900912
}
913+
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
914+
err = nil
901915
}
902916
saveCpErr := rc.saveStatusCheckpoint(ctx, tr.tableName, checkpoints.WholeTableEngineID, err, checkpoints.CheckpointStatusAnalyzed)
903917
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/restore/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)