Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning: make OpLevelOptional suppress the error of DoChecksum (#45486) #45865

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions br/pkg/lightning/restore/table_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/multierr"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type TableRestore struct {
Expand Down Expand Up @@ -800,11 +802,27 @@ func (tr *TableRestore) postProcess(
return false, err
}
err = tr.compareChecksum(remoteChecksum, localChecksum)
failpoint.Inject("compareChecksum-error", func() {
tr.logger.Info("failpoint compareChecksum-error injected.")
remoteChecksum = nil
err = status.Error(codes.Unknown, "Compare checksum meets error.")
})
// with post restore level 'optional', we will skip checksum error
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
if err != nil {
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
err = nil
if err != nil {
if rc.cfg.PostRestore.Checksum != config.OpLevelOptional {
return false, err
}
tr.logger.Warn("do checksum failed, will skip this error and go on", log.ShortError(err))
err = nil
}
if remoteChecksum != nil {
err = tr.compareChecksum(remoteChecksum, localChecksum)
// with post restore level 'optional', we will skip checksum error
if rc.cfg.PostRestore.Checksum == config.OpLevelOptional {
if err != nil {
tr.logger.Warn("compare checksum failed, will skip this error and go on", log.ShortError(err))
err = nil
}
}
}
} else {
Expand Down Expand Up @@ -846,11 +864,12 @@ func (tr *TableRestore) postProcess(
case forcePostProcess || !rc.cfg.PostRestore.PostProcessAtLast:
err := tr.analyzeTable(ctx, rc.tidbGlue.GetSQLExecutor())
// witch post restore level 'optional', we will skip analyze error
if rc.cfg.PostRestore.Analyze == config.OpLevelOptional {
if err != nil {
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
err = nil
if err != nil {
if rc.cfg.PostRestore.Analyze != config.OpLevelOptional {
return false, err
}
tr.logger.Warn("analyze table failed, will skip this error and go on", log.ShortError(err))
err = nil
}
saveCpErr := rc.saveStatusCheckpoint(ctx, tr.tableName, checkpoints.WholeTableEngineID, err, checkpoints.CheckpointStatusAnalyzed)
if err = firstErr(err, saveCpErr); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions br/tests/lightning_routes/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ schema-pattern = "routes_a*"
table-pattern = "t*"
target-schema = "routes_b"
target-table = "u"

[post-restore]
checksum = "optional"
5 changes: 5 additions & 0 deletions br/tests/lightning_routes/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

set -eux

echo "testing checksum-error..."
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/lightning/importer/checksum-error=1*return()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/lightning/importer/checksum-error=1*return()"
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/lightning/restore/checksum-error=1*return()"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified


run_sql 'DROP DATABASE IF EXISTS routes_a0;'
run_sql 'DROP DATABASE IF EXISTS routes_a1;'
run_sql 'DROP DATABASE IF EXISTS routes_b;'

run_lightning

echo "test checksum-error success!"

run_sql 'SELECT count(1), sum(x) FROM routes_b.u;'
check_contains 'count(1): 4'
check_contains 'sum(x): 259'
Expand Down