From 79960e5a8ec504b982196bf3113928fb7ac03659 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 5 Nov 2019 13:30:10 +0800 Subject: [PATCH 1/3] tidb-server: relax the config-check config-check means "check config and exit" config-strict means "enforce config file validity" --- tidb-server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidb-server/main.go b/tidb-server/main.go index 3396e42fe568b..5a4d6575767ef 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -316,7 +316,7 @@ func loadConfig() string { // 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 { + if _, ok := err.(*config.ErrConfigValidationFailed); ok && !*configStrict { return err.Error() } terror.MustNil(err) From 40aec9e727875492ada8e071343a7c1614fd95e6 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 5 Nov 2019 18:31:29 +0800 Subject: [PATCH 2/3] address comment --- config/config.go | 7 ++++--- tidb-server/main.go | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) 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 5a4d6575767ef..5f113514cb7d1 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": struct{}{}, + "log.rotate": struct{}{}, +} + +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 && !*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. From 18da737acd48e08bfbaf2b08726b9c016b945e97 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 5 Nov 2019 20:17:15 +0800 Subject: [PATCH 3/3] go fmt --- tidb-server/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tidb-server/main.go b/tidb-server/main.go index 5f113514cb7d1..19f889580d6d5 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -306,8 +306,8 @@ func flagBoolean(name string, defaultVal bool, usage string) *bool { } var deprecatedConfig = map[string]struct{}{ - "pessimistic-txn.ttl": struct{}{}, - "log.rotate": struct{}{}, + "pessimistic-txn.ttl": {}, + "log.rotate": {}, } func isDeprecatedConfigItem(items []string) bool {