Skip to content

Commit ff0ad33

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 e62cfd5 commit ff0ad33

File tree

19 files changed

+1758
-58
lines changed

19 files changed

+1758
-58
lines changed

br/cmd/br/backup.go

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

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

2930
if err := metricsutil.RegisterMetricsForBR(cfg.PD, cfg.KeyspaceName); err != nil {
3031
return errors.Trace(err)
@@ -206,3 +207,10 @@ func newTxnBackupCommand() *cobra.Command {
206207
task.DefineTxnBackupFlags(command)
207208
return command
208209
}
210+
211+
func overrideDefaultBackupConfigIfNeeded(config *task.BackupConfig, cmd *cobra.Command) {
212+
// override only if flag not set by user
213+
if !cmd.Flags().Changed(task.FlagChecksum) {
214+
config.Checksum = false
215+
}
216+
}

br/cmd/br/cmd.go

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

82-
// AddFlags adds flags to the given cmd.
83-
func AddFlags(cmd *cobra.Command) {
82+
// DefineCommonFlags defines the common flags for all BR cmd operation.
83+
func DefineCommonFlags(cmd *cobra.Command) {
8484
cmd.Version = build.Info()
8585
cmd.Flags().BoolP(flagVersion, flagVersionShort, false, "Display version information about BR")
8686
cmd.SetVersionTemplate("{{printf \"%s\" .Version}}\n")
@@ -97,6 +97,8 @@ func AddFlags(cmd *cobra.Command) {
9797
"Set whether to redact sensitive info in log")
9898
cmd.PersistentFlags().String(FlagStatusAddr, "",
9999
"Set the HTTP listening address for the status report service. Set to empty string to disable")
100+
101+
// defines BR task common flags, this is shared by cmd and sql(brie)
100102
task.DefineCommonFlags(cmd.PersistentFlags())
101103

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

br/cmd/br/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
TraverseChildren: true,
4343
SilenceUsage: true,
4444
}
45-
AddFlags(rootCmd)
45+
DefineCommonFlags(rootCmd)
4646
SetDefaultContext(ctx)
4747
rootCmd.AddCommand(
4848
NewDebugCommand(),

br/cmd/br/restore.go

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

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

br/pkg/backup/schema.go

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

106106
var checksum *checkpoint.ChecksumItem
107-
var exists bool = false
107+
var exists = false
108108
if ss.checkpointChecksum != nil && schema.tableInfo != nil {
109109
checksum, exists = ss.checkpointChecksum[schema.tableInfo.ID]
110110
}
@@ -143,7 +143,7 @@ func (ss *Schemas) BackupSchemas(
143143
zap.Uint64("Crc64Xor", schema.crc64xor),
144144
zap.Uint64("TotalKvs", schema.totalKvs),
145145
zap.Uint64("TotalBytes", schema.totalBytes),
146-
zap.Duration("calculate-take", calculateCost))
146+
zap.Duration("TimeTaken", calculateCost))
147147
}
148148
}
149149
if statsHandle != nil {

br/pkg/metautil/metafile.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ type Table struct {
156156
Stats *util.JSONTable
157157
}
158158

159-
// NoChecksum checks whether the table has a calculated checksum.
160-
func (tbl *Table) NoChecksum() bool {
161-
return tbl.Crc64Xor == 0 && tbl.TotalKvs == 0 && tbl.TotalBytes == 0
162-
}
163-
164159
// MetaReader wraps a reader to read both old and new version of backupmeta.
165160
type MetaReader struct {
166161
storage storage.ExternalStorage
@@ -225,14 +220,38 @@ func (reader *MetaReader) readDataFiles(ctx context.Context, output func(*backup
225220
}
226221

227222
// ArchiveSize return the size of Archive data
228-
func (*MetaReader) ArchiveSize(_ context.Context, files []*backuppb.File) uint64 {
223+
func ArchiveSize(files []*backuppb.File) uint64 {
229224
total := uint64(0)
230225
for _, file := range files {
231226
total += file.Size_
232227
}
233228
return total
234229
}
235230

231+
type ChecksumStats struct {
232+
Crc64Xor uint64
233+
TotalKvs uint64
234+
TotalBytes uint64
235+
}
236+
237+
func (stats ChecksumStats) ChecksumExists() bool {
238+
if stats.Crc64Xor == 0 && stats.TotalKvs == 0 && stats.TotalBytes == 0 {
239+
return false
240+
}
241+
return true
242+
}
243+
244+
// CalculateChecksumStatsOnFiles returns the ChecksumStats for the given files
245+
func CalculateChecksumStatsOnFiles(files []*backuppb.File) ChecksumStats {
246+
var stats ChecksumStats
247+
for _, file := range files {
248+
stats.Crc64Xor ^= file.Crc64Xor
249+
stats.TotalKvs += file.TotalKvs
250+
stats.TotalBytes += file.TotalBytes
251+
}
252+
return stats
253+
}
254+
236255
// ReadDDLs reads the ddls from the backupmeta.
237256
// This function is compatible with the old backupmeta.
238257
func (reader *MetaReader) ReadDDLs(ctx context.Context) ([]byte, error) {

0 commit comments

Comments
 (0)