Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 8c09bb5

Browse files
3pointerYuJuncenkennytm
authored
Merge master to Release 3.1 (#234)
* enable tidb config by default (#230) * enable tidb config by default * backup,restore: fix --checksum flag. (#223) * backup,restore: work on progress to fix a bug that causes --checksum flag won't work properly. Some code of backup and restore ignored the flag (a.k.a. config.Checksum), so when checksum is disabled, we will face failure. * backup: backup will report total bytes and kvs when checksums check disabled. Some code of backup and restore ignored the flag (a.k.a. config.Checksum), so when checksum is disabled, we will face failure. * backup: backup will report total bytes and kvs when checksums check disabled. Some code of backup and restore ignored the flag (a.k.a. config.Checksum), so when checksum is disabled, we will face failure. * backup: add log to ChecksumMatches and new version of FastChecksum. Some of log has been lose. They are in ChecksumMatches now. * restore: restore could find non-checksum tables and skip them automatically. for backup, ChecksumMatches returns error now. * misc: add document for Table::NoChecksum. * backup: omit checksum progress bar when user specify `--checksum=false`. * backup: `CopyMetaFrom` overrides original `client.Schemes` instead of append at its end. * backup: refactor about checksum logic, fix a bug. the bug would cause: when multi tables are backup, the metadata contains only one table. * backup: do some lints. * backup,restore: do some refactor so that cyclomatic complexity won't be too large. * misc: don't use underscore on receiver. * backup: print "quick checksum success" message per table. ...to make br_full_index happy! * backup: refactor a MinInt pattern. * backup: Apply suggestions from code review Co-Authored-By: kennytm <kennytm@gmail.com> Co-authored-by: 3pointer <luancheng@pingcap.com> Co-authored-by: kennytm <kennytm@gmail.com> * fill size in SSTMeta (#233) * Use table info (#231) * create with info during incremental restore * add test * fix log * address comment * fix ci * address commemnt * update 3.1 dependency * remove conf.Experimental.AllowsExpressionIndex Co-authored-by: 山岚 <36239017+YuJuncen@users.noreply.github.com> Co-authored-by: kennytm <kennytm@gmail.com>
1 parent 9b76002 commit 8c09bb5

File tree

18 files changed

+452
-129
lines changed

18 files changed

+452
-129
lines changed

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ require (
1717
github.com/klauspost/cpuid v1.2.0 // indirect
1818
github.com/mattn/go-runewidth v0.0.7 // indirect
1919
github.com/montanaflynn/stats v0.5.0 // indirect
20-
github.com/onsi/ginkgo v1.11.0 // indirect
21-
github.com/onsi/gomega v1.8.1 // indirect
2220
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712
2321
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011
2422
github.com/pingcap/kvproto v0.0.0-20200331072206-c211b473fe43
2523
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd
2624
github.com/pingcap/parser v3.1.0-beta.2.0.20200318061433-f0b8f6cdca0d+incompatible
27-
github.com/pingcap/pd/v3 v3.1.0-beta.2.0.20200312100832-1206736bd050
28-
github.com/pingcap/tidb v1.1.0-beta.0.20200401121410-5854181fbbe0
25+
github.com/pingcap/pd/v3 v3.1.0-rc.0.20200410125843-8b7475c6bfd6
26+
github.com/pingcap/tidb v1.1.0-beta.0.20200410101606-1347df814de0
2927
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200317092225-ed6b2a87af54+incompatible
3028
github.com/pingcap/tipb v0.0.0-20200401093201-cc8b75c53383
3129
github.com/prometheus/client_golang v1.0.0

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,14 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
304304
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
305305
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
306306
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
307+
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
307308
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
308309
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
309310
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
311+
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
310312
github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34=
311313
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
314+
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
312315
github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo=
313316
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
314317
github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg=
@@ -348,8 +351,12 @@ github.com/pingcap/parser v3.1.0-beta.2.0.20200318061433-f0b8f6cdca0d+incompatib
348351
github.com/pingcap/parser v3.1.0-beta.2.0.20200318061433-f0b8f6cdca0d+incompatible/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
349352
github.com/pingcap/pd/v3 v3.1.0-beta.2.0.20200312100832-1206736bd050 h1:mxPdR0pxnUcRfRGX2JnaLyAd9SZWeR42SzvMp4Zv3YI=
350353
github.com/pingcap/pd/v3 v3.1.0-beta.2.0.20200312100832-1206736bd050/go.mod h1:0HfF1LfWLMuGpui0PKhGvkXxfjv1JslMRY6B+cae3dg=
354+
github.com/pingcap/pd/v3 v3.1.0-rc.0.20200410125843-8b7475c6bfd6 h1:N3zllT6rtDYXPeKS/Khide/ClAH1FCNFU6/EStVwb8Y=
355+
github.com/pingcap/pd/v3 v3.1.0-rc.0.20200410125843-8b7475c6bfd6/go.mod h1:su5qKHuRSE0oSO8DBmck0WK17T18OPjCNi3XToM+uCM=
351356
github.com/pingcap/tidb v1.1.0-beta.0.20200401121410-5854181fbbe0 h1:bcl8cbL0K9oZ+vYWNJIgUH2rMkesjfsbJkpZpD2I+lg=
352357
github.com/pingcap/tidb v1.1.0-beta.0.20200401121410-5854181fbbe0/go.mod h1:2cL/Jdq//AUbt/m/VmOwc7wm82oLFn7o/B6fiQtOpQE=
358+
github.com/pingcap/tidb v1.1.0-beta.0.20200410101606-1347df814de0 h1:ZgAk3sPL0p5WEQhyRX8aSCwaDrPLqxMBitT1XP1UvqE=
359+
github.com/pingcap/tidb v1.1.0-beta.0.20200410101606-1347df814de0/go.mod h1:2cL/Jdq//AUbt/m/VmOwc7wm82oLFn7o/B6fiQtOpQE=
353360
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200317092225-ed6b2a87af54+incompatible h1:tYADqdmWwgDOwf/qEN0trJAy6H3c3Tt/QZx1z4qVrRQ=
354361
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200317092225-ed6b2a87af54+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
355362
github.com/pingcap/tipb v0.0.0-20200401093201-cc8b75c53383 h1:y1ayhtouCaO0u74JNMN8s20CGJT0yIuAb8UXOYnCALc=
@@ -588,6 +595,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
588595
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
589596
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
590597
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
598+
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
591599
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 h1:gZpLHxUX5BdYLA08Lj4YCJNN/jk7KtquiArPoeX0WvA=
592600
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
593601
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=

pkg/backup/client.go

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ type ClientMgr interface {
4848
Close()
4949
}
5050

51+
// Checksum is the checksum of some backup files calculated by CollectChecksums.
52+
type Checksum struct {
53+
Crc64Xor uint64
54+
TotalKvs uint64
55+
TotalBytes uint64
56+
}
57+
5158
// Maximum total sleep time(in ms) for kv/cop commands.
5259
const (
5360
backupFineGrainedMaxBackoff = 80000
@@ -747,8 +754,59 @@ func SendBackup(
747754
return nil
748755
}
749756

750-
// FastChecksum check data integrity by xor all(sst_checksum) per table
751-
func (bc *Client) FastChecksum() (bool, error) {
757+
// ChecksumMatches tests whether the "local" checksum matches the checksum from TiKV.
758+
func (bc *Client) ChecksumMatches(local []Checksum) (bool, error) {
759+
if len(local) != len(bc.backupMeta.Schemas) {
760+
return false, nil
761+
}
762+
763+
for i, schema := range bc.backupMeta.Schemas {
764+
localChecksum := local[i]
765+
dbInfo := &model.DBInfo{}
766+
err := json.Unmarshal(schema.Db, dbInfo)
767+
if err != nil {
768+
log.Error("failed in fast checksum, and cannot parse db info.")
769+
return false, err
770+
}
771+
tblInfo := &model.TableInfo{}
772+
err = json.Unmarshal(schema.Table, tblInfo)
773+
if err != nil {
774+
log.Error("failed in fast checksum, and cannot parse table info.")
775+
return false, err
776+
}
777+
if localChecksum.Crc64Xor != schema.Crc64Xor ||
778+
localChecksum.TotalBytes != schema.TotalBytes ||
779+
localChecksum.TotalKvs != schema.TotalKvs {
780+
log.Error("failed in fast checksum",
781+
zap.Stringer("db", dbInfo.Name),
782+
zap.Stringer("table", tblInfo.Name),
783+
zap.Uint64("origin tidb crc64", schema.Crc64Xor),
784+
zap.Uint64("calculated crc64", localChecksum.Crc64Xor),
785+
zap.Uint64("origin tidb total kvs", schema.TotalKvs),
786+
zap.Uint64("calculated total kvs", localChecksum.TotalKvs),
787+
zap.Uint64("origin tidb total bytes", schema.TotalBytes),
788+
zap.Uint64("calculated total bytes", localChecksum.TotalBytes),
789+
)
790+
return false, nil
791+
}
792+
log.Info("fast checksum success",
793+
zap.String("database", dbInfo.Name.L),
794+
zap.String("table", tblInfo.Name.L))
795+
}
796+
return true, nil
797+
}
798+
799+
// CollectFileInfo collects ungrouped file summary information, like kv count and size.
800+
func (bc *Client) CollectFileInfo() {
801+
for _, file := range bc.backupMeta.Files {
802+
summary.CollectSuccessUnit(summary.TotalKV, 1, file.TotalKvs)
803+
summary.CollectSuccessUnit(summary.TotalBytes, 1, file.TotalBytes)
804+
}
805+
}
806+
807+
// CollectChecksums check data integrity by xor all(sst_checksum) per table
808+
// it returns the checksum of all local files.
809+
func (bc *Client) CollectChecksums() ([]Checksum, error) {
752810
start := time.Now()
753811
defer func() {
754812
elapsed := time.Since(start)
@@ -757,19 +815,20 @@ func (bc *Client) FastChecksum() (bool, error) {
757815

758816
dbs, err := utils.LoadBackupTables(&bc.backupMeta)
759817
if err != nil {
760-
return false, err
818+
return nil, err
761819
}
762820

821+
checksums := make([]Checksum, 0, len(bc.backupMeta.Schemas))
763822
for _, schema := range bc.backupMeta.Schemas {
764823
dbInfo := &model.DBInfo{}
765824
err = json.Unmarshal(schema.Db, dbInfo)
766825
if err != nil {
767-
return false, err
826+
return nil, err
768827
}
769828
tblInfo := &model.TableInfo{}
770829
err = json.Unmarshal(schema.Table, tblInfo)
771830
if err != nil {
772-
return false, err
831+
return nil, err
773832
}
774833
tbl := dbs[dbInfo.Name.String()].GetTable(tblInfo.Name.String())
775834

@@ -784,25 +843,16 @@ func (bc *Client) FastChecksum() (bool, error) {
784843

785844
summary.CollectSuccessUnit(summary.TotalKV, 1, totalKvs)
786845
summary.CollectSuccessUnit(summary.TotalBytes, 1, totalBytes)
787-
788-
if schema.Crc64Xor == checksum && schema.TotalKvs == totalKvs && schema.TotalBytes == totalBytes {
789-
log.Info("fast checksum success", zap.Stringer("db", dbInfo.Name), zap.Stringer("table", tblInfo.Name))
790-
} else {
791-
log.Error("failed in fast checksum",
792-
zap.String("database", dbInfo.Name.String()),
793-
zap.String("table", tblInfo.Name.String()),
794-
zap.Uint64("origin tidb crc64", schema.Crc64Xor),
795-
zap.Uint64("calculated crc64", checksum),
796-
zap.Uint64("origin tidb total kvs", schema.TotalKvs),
797-
zap.Uint64("calculated total kvs", totalKvs),
798-
zap.Uint64("origin tidb total bytes", schema.TotalBytes),
799-
zap.Uint64("calculated total bytes", totalBytes),
800-
)
801-
return false, nil
846+
log.Info("fast checksum calculated", zap.Stringer("db", dbInfo.Name), zap.Stringer("table", tblInfo.Name))
847+
localChecksum := Checksum{
848+
Crc64Xor: checksum,
849+
TotalKvs: totalKvs,
850+
TotalBytes: totalBytes,
802851
}
852+
checksums = append(checksums, localChecksum)
803853
}
804854

805-
return true, nil
855+
return checksums, nil
806856
}
807857

808858
// CompleteMeta wait response of admin checksum from TiDB to complete backup meta
@@ -814,3 +864,14 @@ func (bc *Client) CompleteMeta(backupSchemas *Schemas) error {
814864
bc.backupMeta.Schemas = schemas
815865
return nil
816866
}
867+
868+
// CopyMetaFrom copies schema metadata directly from pending backupSchemas, without calculating checksum.
869+
// use this when user skip the checksum generating.
870+
func (bc *Client) CopyMetaFrom(backupSchemas *Schemas) {
871+
schemas := make([]*kvproto.Schema, 0, len(backupSchemas.schemas))
872+
for _, v := range backupSchemas.schemas {
873+
schema := v
874+
schemas = append(schemas, &schema)
875+
}
876+
bc.backupMeta.Schemas = schemas
877+
}

pkg/backup/schema.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type Schemas struct {
3636
backupSchemaCh chan backup.Schema
3737
errCh chan error
3838
wg *sync.WaitGroup
39-
skipChecksum bool
4039
}
4140

4241
func newBackupSchemas() *Schemas {
@@ -57,11 +56,6 @@ func (pending *Schemas) pushPending(
5756
pending.schemas[name] = schema
5857
}
5958

60-
// SetSkipChecksum sets whether it should skip checksum
61-
func (pending *Schemas) SetSkipChecksum(skip bool) {
62-
pending.skipChecksum = skip
63-
}
64-
6559
// Start backups schemas
6660
func (pending *Schemas) Start(
6761
ctx context.Context,
@@ -81,12 +75,6 @@ func (pending *Schemas) Start(
8175
workerPool.Apply(func() {
8276
defer pending.wg.Done()
8377

84-
if pending.skipChecksum {
85-
pending.backupSchemaCh <- schema
86-
updateCh.Inc()
87-
return
88-
}
89-
9078
start := time.Now()
9179
table := model.TableInfo{}
9280
err := json.Unmarshal(schema.Table, &table)

pkg/restore/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,14 @@ func (rc *Client) ValidateChecksum(
650650
workers.Apply(func() {
651651
defer wg.Done()
652652

653+
if table.NoChecksum() {
654+
log.Info("table doesn't have checksum, skipping checksum",
655+
zap.Stringer("db", table.Db.Name),
656+
zap.Stringer("table", table.Info.Name))
657+
updateCh.Inc()
658+
return
659+
}
660+
653661
startTS, err := rc.GetTS(ctx)
654662
if err != nil {
655663
errCh <- errors.Trace(err)

pkg/restore/db.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,27 @@ func NewDB(g glue.Glue, store kv.Storage) (*DB, error) {
4545
// ExecDDL executes the query of a ddl job.
4646
func (db *DB) ExecDDL(ctx context.Context, ddlJob *model.Job) error {
4747
var err error
48-
if ddlJob.BinlogInfo.TableInfo != nil {
48+
tableInfo := ddlJob.BinlogInfo.TableInfo
49+
dbInfo := ddlJob.BinlogInfo.DBInfo
50+
switch ddlJob.Type {
51+
case model.ActionCreateSchema:
52+
err = db.se.CreateDatabase(ctx, dbInfo)
53+
if err != nil {
54+
log.Error("create database failed", zap.Stringer("db", dbInfo.Name), zap.Error(err))
55+
}
56+
return errors.Trace(err)
57+
case model.ActionCreateTable:
58+
err = db.se.CreateTable(ctx, model.NewCIStr(ddlJob.SchemaName), tableInfo)
59+
if err != nil {
60+
log.Error("create table failed",
61+
zap.Stringer("db", dbInfo.Name),
62+
zap.Stringer("table", tableInfo.Name),
63+
zap.Error(err))
64+
}
65+
return errors.Trace(err)
66+
}
67+
68+
if tableInfo != nil {
4969
switchDbSQL := fmt.Sprintf("use %s;", utils.EncloseName(ddlJob.SchemaName))
5070
err = db.se.Execute(ctx, switchDbSQL)
5171
if err != nil {

pkg/restore/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func getSSTMetaFromFile(
115115
Start: rangeStart,
116116
End: rangeEnd,
117117
},
118+
Length: file.GetSize_(),
118119
RegionId: region.GetId(),
119120
RegionEpoch: region.GetRegionEpoch(),
120121
}

pkg/task/backup.go

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"strconv"
88
"time"
99

10+
"github.com/pingcap/br/pkg/utils"
11+
1012
"github.com/pingcap/errors"
1113
kvproto "github.com/pingcap/kvproto/pkg/backup"
1214
"github.com/pingcap/log"
@@ -180,39 +182,32 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
180182
// Backup has finished
181183
updateCh.Close()
182184

183-
// Checksum
184-
backupSchemasConcurrency := backup.DefaultSchemaConcurrency
185-
if backupSchemas.Len() < backupSchemasConcurrency {
186-
backupSchemasConcurrency = backupSchemas.Len()
187-
}
188-
updateCh = g.StartProgress(
189-
ctx, "Checksum", int64(backupSchemas.Len()), !cfg.LogProgress)
190-
backupSchemas.SetSkipChecksum(!cfg.Checksum)
191-
backupSchemas.Start(
192-
ctx, mgr.GetTiKV(), backupTS, uint(backupSchemasConcurrency), updateCh)
193-
194-
err = client.CompleteMeta(backupSchemas)
195-
if err != nil {
196-
return err
197-
}
198-
199-
if cfg.LastBackupTS == 0 {
200-
var valid bool
201-
valid, err = client.FastChecksum()
185+
// Checksum from server, and then fulfill the backup metadata.
186+
if cfg.Checksum {
187+
backupSchemasConcurrency := utils.MinInt(backup.DefaultSchemaConcurrency, backupSchemas.Len())
188+
updateCh = g.StartProgress(
189+
ctx, "Checksum", int64(backupSchemas.Len()), !cfg.LogProgress)
190+
backupSchemas.Start(
191+
ctx, mgr.GetTiKV(), backupTS, uint(backupSchemasConcurrency), updateCh)
192+
err = client.CompleteMeta(backupSchemas)
202193
if err != nil {
203194
return err
204195
}
205-
if !valid {
206-
log.Error("backup FastChecksum mismatch!")
207-
return errors.Errorf("mismatched checksum")
196+
// Checksum has finished
197+
updateCh.Close()
198+
// collect file information.
199+
err = checkChecksums(client, cfg)
200+
if err != nil {
201+
return err
208202
}
209-
210203
} else {
211-
// Since we don't support checksum for incremental data, fast checksum should be skipped.
212-
log.Info("Skip fast checksum in incremental backup")
204+
// When user specified not to calculate checksum, don't calculate checksum.
205+
// Just... copy schemas from origin.
206+
log.Info("Skip fast checksum because user requirement.")
207+
client.CopyMetaFrom(backupSchemas)
208+
// Anyway, let's collect file info for summary.
209+
client.CollectFileInfo()
213210
}
214-
// Checksum has finished
215-
updateCh.Close()
216211

217212
err = client.SaveBackupMeta(ctx, ddlJobs)
218213
if err != nil {
@@ -224,6 +219,30 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
224219
return nil
225220
}
226221

222+
// checkChecksums checks the checksum of the client, once failed,
223+
// returning a error with message: "mismatched checksum".
224+
func checkChecksums(client *backup.Client, cfg *BackupConfig) error {
225+
checksums, err := client.CollectChecksums()
226+
if err != nil {
227+
return err
228+
}
229+
if cfg.LastBackupTS == 0 {
230+
var matches bool
231+
matches, err = client.ChecksumMatches(checksums)
232+
if err != nil {
233+
return err
234+
}
235+
if !matches {
236+
log.Error("backup FastChecksum mismatch!")
237+
return errors.New("mismatched checksum")
238+
}
239+
return nil
240+
}
241+
// Since we don't support checksum for incremental data, fast checksum should be skipped.
242+
log.Info("Skip fast checksum in incremental backup")
243+
return nil
244+
}
245+
227246
// parseTSString port from tidb setSnapshotTS
228247
func parseTSString(ts string) (uint64, error) {
229248
if len(ts) == 0 {

0 commit comments

Comments
 (0)