Skip to content

Commit dc5d539

Browse files
authored
lightning: make OpLevelOptional suppress the error of DoChecksum (#45486)
close #45382
1 parent 209bb09 commit dc5d539

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

br/pkg/lightning/importer/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ go_library(
9191
"@com_github_tikv_pd_client//:client",
9292
"@io_etcd_go_etcd_client_v3//:client",
9393
"@org_golang_google_grpc//:grpc",
94+
"@org_golang_google_grpc//codes",
95+
"@org_golang_google_grpc//status",
9496
"@org_golang_x_exp//maps",
9597
"@org_golang_x_exp//slices",
9698
"@org_golang_x_sync//errgroup",

br/pkg/lightning/importer/table_import.go

Lines changed: 20 additions & 7 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.
@@ -1034,15 +1036,26 @@ func (tr *TableImporter) postProcess(
10341036

10351037
var remoteChecksum *local.RemoteChecksum
10361038
remoteChecksum, err = DoChecksum(ctx, tr.tableInfo)
1039+
failpoint.Inject("checksum-error", func() {
1040+
tr.logger.Info("failpoint checksum-error injected.")
1041+
remoteChecksum = nil
1042+
err = status.Error(codes.Unknown, "Checksum meets error.")
1043+
})
10371044
if err != nil {
1038-
return false, err
1045+
if rc.cfg.PostRestore.Checksum != config.OpLevelOptional {
1046+
return false, err
1047+
}
1048+
tr.logger.Warn("do checksum failed, will skip this error and go on", log.ShortError(err))
1049+
err = nil
10391050
}
1040-
err = tr.compareChecksum(remoteChecksum, localChecksum)
1041-
// with post restore level 'optional', we will skip checksum error
1042-
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
1043-
if err != nil {
1044-
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
1045-
err = nil
1051+
if remoteChecksum != nil {
1052+
err = tr.compareChecksum(remoteChecksum, localChecksum)
1053+
// with post restore level 'optional', we will skip checksum error
1054+
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
1055+
if err != nil {
1056+
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
1057+
err = nil
1058+
}
10461059
}
10471060
}
10481061
} else {

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'

disttask/importinto/subtask_executor.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,26 @@ func verifyChecksum(ctx context.Context, taskMeta *TaskMeta, subtaskMeta *PostPr
120120
}
121121
remoteChecksum, err := checksumTable(ctx, globalTaskManager, taskMeta, logger)
122122
if err != nil {
123-
return err
123+
if taskMeta.Plan.Checksum != config.OpLevelOptional {
124+
return err
125+
}
126+
logger.Warn("checksumTable failed, will skip this error and go on", zap.Error(err))
124127
}
125-
if !remoteChecksum.IsEqual(&localChecksum) {
126-
err2 := common.ErrChecksumMismatch.GenWithStackByArgs(
127-
remoteChecksum.Checksum, localChecksum.Sum(),
128-
remoteChecksum.TotalKVs, localChecksum.SumKVS(),
129-
remoteChecksum.TotalBytes, localChecksum.SumSize(),
130-
)
131-
if taskMeta.Plan.Checksum == config.OpLevelOptional {
132-
logger.Warn("verify checksum failed, but checksum is optional, will skip it", zap.Error(err2))
133-
err2 = nil
128+
if remoteChecksum != nil {
129+
if !remoteChecksum.IsEqual(&localChecksum) {
130+
err2 := common.ErrChecksumMismatch.GenWithStackByArgs(
131+
remoteChecksum.Checksum, localChecksum.Sum(),
132+
remoteChecksum.TotalKVs, localChecksum.SumKVS(),
133+
remoteChecksum.TotalBytes, localChecksum.SumSize(),
134+
)
135+
if taskMeta.Plan.Checksum == config.OpLevelOptional {
136+
logger.Warn("verify checksum failed, but checksum is optional, will skip it", zap.Error(err2))
137+
err2 = nil
138+
}
139+
return err2
134140
}
135-
return err2
141+
logger.Info("checksum pass", zap.Object("local", &localChecksum))
136142
}
137-
logger.Info("checksum pass", zap.Object("local", &localChecksum))
138143
return nil
139144
}
140145

0 commit comments

Comments
 (0)