diff --git a/config/config.go b/config/config.go index d6babffa84bb1..4df542b8483c7 100644 --- a/config/config.go +++ b/config/config.go @@ -127,11 +127,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. @@ -538,7 +539,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 diff --git a/tidb-server/main.go b/tidb-server/main.go index 3396e42fe568b..19f889580d6d5 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -305,6 +305,20 @@ 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 != "" { @@ -312,13 +326,24 @@ func loadConfig() string { 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.