Skip to content

Commit

Permalink
restore: add local checksum log (pingcap#153)
Browse files Browse the repository at this point in the history
* restore: add local checksum log

* Update lightning/restore/restore.go

Co-Authored-By: lonng <[email protected]>
  • Loading branch information
lonng authored and kennytm committed Mar 27, 2019
1 parent c3886a8 commit 80f7c41
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,20 @@ func (t *TableRestore) postProcess(ctx context.Context, rc *RestoreController, c
}

// 4. do table checksum
var localChecksum verify.KVChecksum
for _, engine := range cp.Engines {
for _, chunk := range engine.Chunks {
localChecksum.Add(&chunk.Checksum)
}
}
common.AppLogger.Infof("[%s] local checksum [sum:%d, kvs:%d, size:%v]",
t.tableName, localChecksum.Sum(), localChecksum.SumKVS(), localChecksum.SumSize())
if cp.Status < CheckpointStatusChecksummed {
if !rc.cfg.PostRestore.Checksum {
common.AppLogger.Infof("[%s] Skip checksum.", t.tableName)
rc.saveStatusCheckpoint(t.tableName, wholeTableEngineID, nil, CheckpointStatusChecksumSkipped)
} else {
err := t.compareChecksum(ctx, rc.tidbMgr.db, cp)
err := t.compareChecksum(ctx, rc.tidbMgr.db, localChecksum)
rc.saveStatusCheckpoint(t.tableName, wholeTableEngineID, err, CheckpointStatusChecksummed)
if err != nil {
common.AppLogger.Errorf("[%s] checksum failed: %v", t.tableName, err.Error())
Expand Down Expand Up @@ -1198,14 +1206,7 @@ func (tr *TableRestore) importKV(ctx context.Context, closedEngine *kv.ClosedEng
}

// do checksum for each table.
func (tr *TableRestore) compareChecksum(ctx context.Context, db *sql.DB, cp *TableCheckpoint) error {
var localChecksum verify.KVChecksum
for _, engine := range cp.Engines {
for _, chunk := range engine.Chunks {
localChecksum.Add(&chunk.Checksum)
}
}

func (tr *TableRestore) compareChecksum(ctx context.Context, db *sql.DB, localChecksum verify.KVChecksum) error {
start := time.Now()
remoteChecksum, err := DoChecksum(ctx, db, tr.tableName)
dur := time.Since(start)
Expand Down

0 comments on commit 80f7c41

Please sign in to comment.