Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidb-server: handle deprecated configuration item in config-check (#13142) #13272

Merged
merged 3 commits into from
Nov 8, 2019
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
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
37 changes: 31 additions & 6 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,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