Skip to content

Commit

Permalink
tidb-server: handle deprecated configuration item in config-check (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot committed Nov 8, 2019
1 parent 0b10244 commit 35f3653
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
7 changes: 4 additions & 3 deletions config/config.go
Expand Up @@ -126,11 +126,12 @@ type Security struct {
// This is needed only because logging hasn't been set up at the time we parse the config file.
// This should all be ripped out once strict config checking is made the default behavior.
type ErrConfigValidationFailed struct {
err string
confFile string
UndecodedItems []string
}

func (e *ErrConfigValidationFailed) Error() string {
return e.err
return fmt.Sprintf("config file %s contained unknown configuration options: %s", e.confFile, strings.Join(e.UndecodedItems, ", "))
}

// ToTLSConfig generates tls's config based on security section of the config.
Expand Down Expand Up @@ -536,7 +537,7 @@ func (c *Config) Load(confFile string) error {
for _, item := range undecoded {
undecodedItems = append(undecodedItems, item.String())
}
err = &ErrConfigValidationFailed{fmt.Sprintf("config file %s contained unknown configuration options: %s", confFile, strings.Join(undecodedItems, ", "))}
err = &ErrConfigValidationFailed{confFile, undecodedItems}
}

return err
Expand Down
37 changes: 31 additions & 6 deletions tidb-server/main.go
Expand Up @@ -299,20 +299,45 @@ func flagBoolean(name string, defaultVal bool, usage string) *bool {
return flag.Bool(name, defaultVal, usage)
}

var deprecatedConfig = map[string]struct{}{
"pessimistic-txn.ttl": {},
"log.rotate": {},
}

func isDeprecatedConfigItem(items []string) bool {
for _, item := range items {
if _, ok := deprecatedConfig[item]; !ok {
return false
}
}
return true
}

func loadConfig() string {
cfg = config.GetGlobalConfig()
if *configPath != "" {
// Not all config items are supported now.
config.SetConfReloader(*configPath, reloadConfig, hotReloadConfigItems...)

err := cfg.Load(*configPath)
// This block is to accommodate an interim situation where strict config checking
// is not the default behavior of TiDB. The warning message must be deferred until
// logging has been set up. After strict config checking is the default behavior,
// This should all be removed.
if _, ok := err.(*config.ErrConfigValidationFailed); ok && !*configCheck && !*configStrict {
return err.Error()
if err == nil {
return ""
}

// Unused config item erro turns to warnings.
if tmp, ok := err.(*config.ErrConfigValidationFailed); ok {
if isDeprecatedConfigItem(tmp.UndecodedItems) {
return err.Error()
}
// This block is to accommodate an interim situation where strict config checking
// is not the default behavior of TiDB. The warning message must be deferred until
// logging has been set up. After strict config checking is the default behavior,
// This should all be removed.
if !*configCheck && !*configStrict {
return err.Error()
}
}

terror.MustNil(err)
} else {
// configCheck should have the config file specified.
Expand Down

0 comments on commit 35f3653

Please sign in to comment.