Skip to content

Commit aca8731

Browse files
committed
This is an automated cherry-pick of pingcap#56712
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 7f86cec commit aca8731

File tree

19 files changed

+2029
-46
lines changed

19 files changed

+2029
-46
lines changed

br/cmd/br/backup.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020

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

2829
ctx := GetDefaultContext()
2930
if cfg.EnableOpenTracing {
@@ -165,3 +166,28 @@ func newRawBackupCommand() *cobra.Command {
165166
task.DefineRawBackupFlags(command)
166167
return command
167168
}
169+
<<<<<<< HEAD
170+
=======
171+
172+
// newTxnBackupCommand return a txn kv range backup subcommand.
173+
func newTxnBackupCommand() *cobra.Command {
174+
command := &cobra.Command{
175+
Use: "txn",
176+
Short: "(experimental) backup a txn kv range from TiKV cluster",
177+
Args: cobra.NoArgs,
178+
RunE: func(command *cobra.Command, _ []string) error {
179+
return runBackupTxnCommand(command, task.TxnBackupCmd)
180+
},
181+
}
182+
183+
task.DefineTxnBackupFlags(command)
184+
return command
185+
}
186+
187+
func overrideDefaultBackupConfigIfNeeded(config *task.BackupConfig, cmd *cobra.Command) {
188+
// override only if flag not set by user
189+
if !cmd.Flags().Changed(task.FlagChecksum) {
190+
config.Checksum = false
191+
}
192+
}
193+
>>>>>>> 4f047be191b (br: restore checksum shouldn't rely on backup checksum (#56712))

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
@@ -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
@@ -22,7 +22,7 @@ import (
2222

2323
func runRestoreCommand(command *cobra.Command, cmdName string) error {
2424
cfg := task.RestoreConfig{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
}

br/pkg/backup/schema.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (ss *Schemas) BackupSchemas(
111111
}
112112

113113
var checksum *checkpoint.ChecksumItem
114-
var exists bool = false
114+
var exists = false
115115
if ss.checkpointChecksum != nil && schema.tableInfo != nil {
116116
checksum, exists = ss.checkpointChecksum[schema.tableInfo.ID]
117117
}
@@ -153,8 +153,12 @@ func (ss *Schemas) BackupSchemas(
153153
zap.Uint64("Crc64Xor", schema.crc64xor),
154154
zap.Uint64("TotalKvs", schema.totalKvs),
155155
zap.Uint64("TotalBytes", schema.totalBytes),
156+
<<<<<<< HEAD
156157
zap.Duration("calculate-take", calculateCost),
157158
zap.Duration("flush-take", flushCost))
159+
=======
160+
zap.Duration("TimeTaken", calculateCost))
161+
>>>>>>> 4f047be191b (br: restore checksum shouldn't rely on backup checksum (#56712))
158162
}
159163
}
160164
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 *handle.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)