Skip to content

Commit 95956e2

Browse files
authored
lightning: make OpLevelOptional suppress the error of DoChecksum (#45486) (#45865)
close #45382
1 parent c4b5de9 commit 95956e2

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

br/pkg/lightning/restore/table_restore.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import (
4343
"github.com/pingcap/tidb/util/mathutil"
4444
"go.uber.org/multierr"
4545
"go.uber.org/zap"
46+
"google.golang.org/grpc/codes"
47+
"google.golang.org/grpc/status"
4648
)
4749

4850
type TableRestore struct {
@@ -800,11 +802,27 @@ func (tr *TableRestore) postProcess(
800802
return false, err
801803
}
802804
err = tr.compareChecksum(remoteChecksum, localChecksum)
805+
failpoint.Inject("checksum-error", func() {
806+
tr.logger.Info("failpoint checksum-error injected.")
807+
remoteChecksum = nil
808+
err = status.Error(codes.Unknown, "Compare checksum meets error.")
809+
})
803810
// with post restore level 'optional', we will skip checksum error
804-
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
805-
if err != nil {
806-
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
807-
err = nil
811+
if err != nil {
812+
if rc.cfg.PostRestore.Checksum != config.OpLevelOptional {
813+
return false, err
814+
}
815+
tr.logger.Warn("do checksum failed, will skip this error and go on", log.ShortError(err))
816+
err = nil
817+
}
818+
if remoteChecksum != nil {
819+
err = tr.compareChecksum(remoteChecksum, localChecksum)
820+
// with post restore level 'optional', we will skip checksum error
821+
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
822+
if err != nil {
823+
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
824+
err = nil
825+
}
808826
}
809827
}
810828
} else {
@@ -846,11 +864,12 @@ func (tr *TableRestore) postProcess(
846864
case forcePostProcess || !rc.cfg.PostRestore.PostProcessAtLast:
847865
err := tr.analyzeTable(ctx, rc.tidbGlue.GetSQLExecutor())
848866
// witch post restore level 'optional', we will skip analyze error
849-
if rc.cfg.PostRestore.Analyze == config.OpLevelOptional {
850-
if err != nil {
851-
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
852-
err = nil
867+
if err != nil {
868+
if rc.cfg.PostRestore.Analyze != config.OpLevelOptional {
869+
return false, err
853870
}
871+
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
872+
err = nil
854873
}
855874
saveCpErr := rc.saveStatusCheckpoint(ctx, tr.tableName, checkpoints.WholeTableEngineID, err, checkpoints.CheckpointStatusAnalyzed)
856875
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)