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

--checksum=false won't work. #223

Merged
merged 17 commits into from
Apr 10, 2020
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
43 changes: 22 additions & 21 deletions pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,23 @@ func SendBackup(
return nil
}

// ChecksumMatches tests whether the "local" checksum matches the checksum from TiKV.
func (bc *Client) ChecksumMatches(local []uint64) bool {
if len(local) != len(bc.backupMeta.Schemas) {
3pointer marked this conversation as resolved.
Show resolved Hide resolved
return false
}

for i, schema := range bc.backupMeta.Schemas {
if local[i] != schema.Crc64Xor {
kennytm marked this conversation as resolved.
Show resolved Hide resolved
return false
}
}
return true
}

// FastChecksum check data integrity by xor all(sst_checksum) per table
func (bc *Client) FastChecksum() (bool, error) {
// it returns the checksum of all local files.
func (bc *Client) FastChecksum() ([]uint64, error) {
start := time.Now()
defer func() {
elapsed := time.Since(start)
Expand All @@ -758,19 +773,20 @@ func (bc *Client) FastChecksum() (bool, error) {

dbs, err := utils.LoadBackupTables(&bc.backupMeta)
if err != nil {
return false, err
return nil, err
}

checksums := make([]uint64, 0, len(bc.backupMeta.Schemas))
for _, schema := range bc.backupMeta.Schemas {
dbInfo := &model.DBInfo{}
err = json.Unmarshal(schema.Db, dbInfo)
if err != nil {
return false, err
return nil, err
}
tblInfo := &model.TableInfo{}
err = json.Unmarshal(schema.Table, tblInfo)
if err != nil {
return false, err
return nil, err
}
tbl := dbs[dbInfo.Name.String()].GetTable(tblInfo.Name.String())

Expand All @@ -785,25 +801,10 @@ func (bc *Client) FastChecksum() (bool, error) {

summary.CollectSuccessUnit(summary.TotalKV, 1, totalKvs)
summary.CollectSuccessUnit(summary.TotalBytes, 1, totalBytes)

if schema.Crc64Xor == checksum && schema.TotalKvs == totalKvs && schema.TotalBytes == totalBytes {
log.Info("fast checksum success", zap.Stringer("db", dbInfo.Name), zap.Stringer("table", tblInfo.Name))
} else {
log.Error("failed in fast checksum",
zap.String("database", dbInfo.Name.String()),
zap.String("table", tblInfo.Name.String()),
zap.Uint64("origin tidb crc64", schema.Crc64Xor),
zap.Uint64("calculated crc64", checksum),
zap.Uint64("origin tidb total kvs", schema.TotalKvs),
zap.Uint64("calculated total kvs", totalKvs),
zap.Uint64("origin tidb total bytes", schema.TotalBytes),
zap.Uint64("calculated total bytes", totalBytes),
)
return false, nil
}
checksums = append(checksums, checksum)
}

return true, nil
return checksums, nil
}

// CompleteMeta wait response of admin checksum from TiDB to complete backup meta
Expand Down
19 changes: 9 additions & 10 deletions pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,20 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
if err != nil {
return err
}

if cfg.LastBackupTS == 0 {
var valid bool
valid, err = client.FastChecksum()
if err != nil {
return err
}
if !valid {
checksums, err := client.FastChecksum()
3pointer marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
if cfg.LastBackupTS == 0 && cfg.Checksum {
if !client.ChecksumMatches(checksums) {
log.Error("backup FastChecksum mismatch!")
return errors.Errorf("mismatched checksum")
YuJuncen marked this conversation as resolved.
Show resolved Hide resolved
}

} else {
} else if cfg.Checksum {
// Since we don't support checksum for incremental data, fast checksum should be skipped.
log.Info("Skip fast checksum in incremental backup")
} else {
log.Info("Skip fast checksum because user requirement.")
}
// Checksum has finished
updateCh.Close()
Expand Down
19 changes: 11 additions & 8 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,18 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
// Restore has finished.
updateCh.Close()

// Checksum
updateCh = g.StartProgress(
ctx, "Checksum", int64(len(newTables)), !cfg.LogProgress)
err = client.ValidateChecksum(
ctx, mgr.GetTiKV().GetClient(), tables, newTables, updateCh)
if err != nil {
return err
// Don't do checksum if user specified.
if cfg.Checksum {
3pointer marked this conversation as resolved.
Show resolved Hide resolved
// Checksum
updateCh = g.StartProgress(
ctx, "Checksum", int64(len(newTables)), !cfg.LogProgress)
err = client.ValidateChecksum(
ctx, mgr.GetTiKV().GetClient(), tables, newTables, updateCh)
if err != nil {
return err
}
updateCh.Close()
}
updateCh.Close()

// Set task summary to success status.
summary.SetSuccessStatus(true)
Expand Down
64 changes: 64 additions & 0 deletions tests/br_skip_checksum/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh
#
# Copyright 2020 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu
DB="$TEST_NAME"
TABLE="usertable"
DB_COUNT=3

for i in $(seq $DB_COUNT); do
run_sql "CREATE DATABASE $DB${i};"
go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB${i}
done

for i in $(seq $DB_COUNT); do
row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}')
done

# backup full
echo "backup start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --ratelimit 5 --concurrency 4 --checksum=false

for i in $(seq $DB_COUNT); do
run_sql "DROP DATABASE $DB${i};"
done

# restore full
echo "restore start..."
run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --ratelimit 1024 --checksum=false

for i in $(seq $DB_COUNT); do
row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}')
done

for i in $(seq $DB_COUNT); do
if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then
fail=true
echo "TEST: [$TEST_NAME] fail on database $DB${i}"
fi
echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}"
done

fail=false
if $fail; then
echo "TEST: [$TEST_NAME] failed!"
exit 1
else
echo "TEST: [$TEST_NAME] successed!"
fi

for i in $(seq $DB_COUNT); do
run_sql "DROP DATABASE $DB${i};"
done
12 changes: 12 additions & 0 deletions tests/br_skip_checksum/workload
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
recordcount=100
operationcount=0
workload=core

readallfields=true

readproportion=0
updateproportion=0
scanproportion=0
insertproportion=0

requestdistribution=uniform