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

Commit

Permalink
common: adjust config in task RunBackup/RunRestore (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer authored Jul 27, 2020
1 parent d904ae3 commit a475692
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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

0 comments on commit a475692

Please sign in to comment.