-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
br: restore checksum shouldn't rely on backup checksum #56712
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8b843bd
initial commit to fix restore checksum
Tristan1900 829e6bc
add tests, disable default checksum in backup
Tristan1900 03b2bf9
fix tests
Tristan1900 134692b
fix again
Tristan1900 a835140
Merge branch 'master' into checksum
Tristan1900 9fa90b9
fix
Tristan1900 3e9053d
address comments
Tristan1900 6b28638
address comments
Tristan1900 06276b3
fix bazel
Tristan1900 668fe54
fix
Tristan1900 ac5a12b
fix int tests
Tristan1900 ffd6082
fix again
Tristan1900 95059bc
revert accidental change
Tristan1900 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -467,8 +467,8 @@ func (rc *SnapClient) needLoadSchemas(backupMeta *backuppb.BackupMeta) bool { | |
return !(backupMeta.IsRawKv || backupMeta.IsTxnKv) | ||
} | ||
|
||
// InitBackupMeta loads schemas from BackupMeta to initialize RestoreClient. | ||
func (rc *SnapClient) InitBackupMeta( | ||
// LoadSchemaIfNeededAndInitClient loads schemas from BackupMeta to initialize RestoreClient. | ||
func (rc *SnapClient) LoadSchemaIfNeededAndInitClient( | ||
c context.Context, | ||
backupMeta *backuppb.BackupMeta, | ||
backend *backuppb.StorageBackend, | ||
|
@@ -989,7 +989,7 @@ func (rc *SnapClient) setSpeedLimit(ctx context.Context, rateLimit uint64) error | |
return nil | ||
} | ||
|
||
func (rc *SnapClient) execChecksum( | ||
func (rc *SnapClient) execAndValidateChecksum( | ||
ctx context.Context, | ||
tbl *CreatedTable, | ||
kvClient kv.Client, | ||
|
@@ -1000,13 +1000,14 @@ func (rc *SnapClient) execChecksum( | |
zap.String("table", tbl.OldTable.Info.Name.O), | ||
) | ||
|
||
if tbl.OldTable.NoChecksum() { | ||
expectedChecksumStats := metautil.CalculateChecksumStatsOnFiles(tbl.OldTable.Files) | ||
if !expectedChecksumStats.ChecksumExists() { | ||
logger.Warn("table has no checksum, skipping checksum") | ||
return nil | ||
} | ||
|
||
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil { | ||
span1 := span.Tracer().StartSpan("Client.execChecksum", opentracing.ChildOf(span.Context())) | ||
span1 := span.Tracer().StartSpan("Client.execAndValidateChecksum", opentracing.ChildOf(span.Context())) | ||
defer span1.Finish() | ||
ctx = opentracing.ContextWithSpan(ctx, span1) | ||
} | ||
|
@@ -1046,21 +1047,24 @@ func (rc *SnapClient) execChecksum( | |
} | ||
} | ||
} | ||
table := tbl.OldTable | ||
if item.Crc64xor != table.Crc64Xor || | ||
item.TotalKvs != table.TotalKvs || | ||
item.TotalBytes != table.TotalBytes { | ||
checksumMatch := item.Crc64xor == expectedChecksumStats.Crc64Xor && | ||
item.TotalKvs == expectedChecksumStats.TotalKvs && | ||
item.TotalBytes == expectedChecksumStats.TotalBytes | ||
failpoint.Inject("full-restore-validate-checksum", func(_ failpoint.Value) { | ||
checksumMatch = false | ||
}) | ||
if !checksumMatch { | ||
logger.Error("failed in validate checksum", | ||
zap.Uint64("origin tidb crc64", table.Crc64Xor), | ||
zap.Uint64("expected tidb crc64", expectedChecksumStats.Crc64Xor), | ||
zap.Uint64("calculated crc64", item.Crc64xor), | ||
zap.Uint64("origin tidb total kvs", table.TotalKvs), | ||
zap.Uint64("expected tidb total kvs", expectedChecksumStats.TotalKvs), | ||
zap.Uint64("calculated total kvs", item.TotalKvs), | ||
zap.Uint64("origin tidb total bytes", table.TotalBytes), | ||
zap.Uint64("expected tidb total bytes", expectedChecksumStats.TotalBytes), | ||
zap.Uint64("calculated total bytes", item.TotalBytes), | ||
) | ||
return errors.Annotate(berrors.ErrRestoreChecksumMismatch, "failed to validate checksum") | ||
} | ||
logger.Info("success in validate checksum") | ||
logger.Info("success in validating checksum") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you also add the table / database name to this log? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
return nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we need to do the check here, if an empty table is backed up, should we check after restore if it's still empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the error log is misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I remove the checking here at all?