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

common: adjust config in task RunBackup/RunRestore #443

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 20 additions & 2 deletions pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,36 @@ func (cfg *BackupConfig) ParseFromFlags(flags *pflag.FlagSet) error {
if err = cfg.Config.ParseFromFlags(flags); err != nil {
return errors.Trace(err)
}

cfg.RemoveSchedulers, err = flags.GetBool(flagRemoveSchedulers)
return err
}

// adjustBackupConfig is use for BR(binary) and BR in TiDB.
// When new config was add and not included in parser.
// we should set proper value in this function.
// so that both binary and TiDB will use same default value.
func (cfg *BackupConfig) adjustBackupConfig() {
if cfg.Config.Concurrency == 0 {
cfg.Config.Concurrency = defaultBackupConcurrency
}
if cfg.Config.Concurrency > maxBackupConcurrency {
cfg.Config.Concurrency = maxBackupConcurrency
}
cfg.RemoveSchedulers, err = flags.GetBool(flagRemoveSchedulers)
return err

if cfg.GCTTL == 0 {
cfg.GCTTL = backup.DefaultBRGCSafePointTTL
}
// Use zstd as default
if cfg.CompressionType == kvproto.CompressionType_UNKNOWN {
cfg.CompressionType = kvproto.CompressionType_ZSTD
}
}

// RunBackup starts a backup task inside the current goroutine.
func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig) error {
cfg.adjustBackupConfig()

defer summary.Summary(cmdName)
ctx, cancel := context.WithCancel(c)
defer cancel()
Expand Down
15 changes: 15 additions & 0 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,23 @@ func (cfg *RestoreConfig) ParseFromFlags(flags *pflag.FlagSet) error {
return nil
}

// adjustRestoreConfig is use for BR(binary) and BR in TiDB.
// When new config was add and not included in parser.
// we should set proper value in this function.
// so that both binary and TiDB will use same default value.
func (cfg *RestoreConfig) adjustRestoreConfig() {
if cfg.Config.Concurrency == 0 {
cfg.Config.Concurrency = defaultRestoreConcurrency
}
if cfg.Config.SwitchModeInterval == 0 {
cfg.Config.SwitchModeInterval = defaultSwitchInterval
}
}

// RunRestore starts a restore task inside the current goroutine.
func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConfig) error {
cfg.adjustRestoreConfig()

defer summary.Summary(cmdName)
ctx, cancel := context.WithCancel(c)
defer cancel()
Expand Down