Skip to content

Commit aa21365

Browse files
Tristan1900ti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#56712
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 8e150a5 commit aa21365

File tree

19 files changed

+1776
-56
lines changed

19 files changed

+1776
-56
lines changed

br/cmd/br/backup.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import (
2222

2323
func runBackupCommand(command *cobra.Command, cmdName string) error {
2424
cfg := task.BackupConfig{Config: task.Config{LogProgress: HasLogFile()}}
25-
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
25+
if err := cfg.ParseFromFlags(command.Flags(), false); err != nil {
2626
command.SilenceUsage = false
2727
return errors.Trace(err)
2828
}
29+
overrideDefaultBackupConfigIfNeeded(&cfg, command)
2930

3031
if err := metricsutil.RegisterMetricsForBR(cfg.PD, cfg.KeyspaceName); err != nil {
3132
return errors.Trace(err)
@@ -211,3 +212,10 @@ func newTxnBackupCommand() *cobra.Command {
211212
task.DefineTxnBackupFlags(command)
212213
return command
213214
}
215+
216+
func overrideDefaultBackupConfigIfNeeded(config *task.BackupConfig, cmd *cobra.Command) {
217+
// override only if flag not set by user
218+
if !cmd.Flags().Changed(task.FlagChecksum) {
219+
config.Checksum = false
220+
}
221+
}

br/cmd/br/cmd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func timestampLogFileName() string {
8181
return filepath.Join(os.TempDir(), time.Now().Format("br.log.2006-01-02T15.04.05Z0700"))
8282
}
8383

84-
// AddFlags adds flags to the given cmd.
85-
func AddFlags(cmd *cobra.Command) {
84+
// DefineCommonFlags defines the common flags for all BR cmd operation.
85+
func DefineCommonFlags(cmd *cobra.Command) {
8686
cmd.Version = build.Info()
8787
cmd.Flags().BoolP(flagVersion, flagVersionShort, false, "Display version information about BR")
8888
cmd.SetVersionTemplate("{{printf \"%s\" .Version}}\n")
@@ -99,6 +99,8 @@ func AddFlags(cmd *cobra.Command) {
9999
"Set whether to redact sensitive info in log")
100100
cmd.PersistentFlags().String(FlagStatusAddr, "",
101101
"Set the HTTP listening address for the status report service. Set to empty string to disable")
102+
103+
// defines BR task common flags, this is shared by cmd and sql(brie)
102104
task.DefineCommonFlags(cmd.PersistentFlags())
103105

104106
cmd.PersistentFlags().StringP(FlagSlowLogFile, "", "",

br/cmd/br/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func main() {
2020
TraverseChildren: true,
2121
SilenceUsage: true,
2222
}
23-
AddFlags(rootCmd)
23+
DefineCommonFlags(rootCmd)
2424
SetDefaultContext(ctx)
2525
rootCmd.AddCommand(
2626
NewDebugCommand(),

br/cmd/br/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
func runRestoreCommand(command *cobra.Command, cmdName string) error {
2727
cfg := task.RestoreConfig{Config: task.Config{LogProgress: HasLogFile()}}
28-
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
28+
if err := cfg.ParseFromFlags(command.Flags(), false); err != nil {
2929
command.SilenceUsage = false
3030
return errors.Trace(err)
3131
}

br/pkg/backup/schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (ss *Schemas) BackupSchemas(
106106
}
107107

108108
var checksum *checkpoint.ChecksumItem
109-
var exists bool = false
109+
var exists = false
110110
if ss.checkpointChecksum != nil && schema.tableInfo != nil {
111111
checksum, exists = ss.checkpointChecksum[schema.tableInfo.ID]
112112
}
@@ -145,7 +145,7 @@ func (ss *Schemas) BackupSchemas(
145145
zap.Uint64("Crc64Xor", schema.crc64xor),
146146
zap.Uint64("TotalKvs", schema.totalKvs),
147147
zap.Uint64("TotalBytes", schema.totalBytes),
148-
zap.Duration("calculate-take", calculateCost))
148+
zap.Duration("TimeTaken", calculateCost))
149149
}
150150
}
151151
if statsHandle != nil {

br/pkg/metautil/metafile.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ type Table struct {
171171
StatsFileIndexes []*backuppb.StatsFileIndex
172172
}
173173

174-
// NoChecksum checks whether the table has a calculated checksum.
175-
func (tbl *Table) NoChecksum() bool {
176-
return tbl.Crc64Xor == 0 && tbl.TotalKvs == 0 && tbl.TotalBytes == 0
177-
}
178-
179174
// MetaReader wraps a reader to read both old and new version of backupmeta.
180175
type MetaReader struct {
181176
storage storage.ExternalStorage
@@ -240,14 +235,38 @@ func (reader *MetaReader) readDataFiles(ctx context.Context, output func(*backup
240235
}
241236

242237
// ArchiveSize return the size of Archive data
243-
func (*MetaReader) ArchiveSize(_ context.Context, files []*backuppb.File) uint64 {
238+
func ArchiveSize(files []*backuppb.File) uint64 {
244239
total := uint64(0)
245240
for _, file := range files {
246241
total += file.Size_
247242
}
248243
return total
249244
}
250245

246+
type ChecksumStats struct {
247+
Crc64Xor uint64
248+
TotalKvs uint64
249+
TotalBytes uint64
250+
}
251+
252+
func (stats ChecksumStats) ChecksumExists() bool {
253+
if stats.Crc64Xor == 0 && stats.TotalKvs == 0 && stats.TotalBytes == 0 {
254+
return false
255+
}
256+
return true
257+
}
258+
259+
// CalculateChecksumStatsOnFiles returns the ChecksumStats for the given files
260+
func CalculateChecksumStatsOnFiles(files []*backuppb.File) ChecksumStats {
261+
var stats ChecksumStats
262+
for _, file := range files {
263+
stats.Crc64Xor ^= file.Crc64Xor
264+
stats.TotalKvs += file.TotalKvs
265+
stats.TotalBytes += file.TotalBytes
266+
}
267+
return stats
268+
}
269+
251270
// ReadDDLs reads the ddls from the backupmeta.
252271
// This function is compatible with the old backupmeta.
253272
func (reader *MetaReader) ReadDDLs(ctx context.Context) ([]byte, error) {

0 commit comments

Comments
 (0)