Skip to content

Commit

Permalink
cherry pick #34926 to release-6.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
CbcWestwolf authored and ti-srebot committed May 25, 2022
1 parent f876236 commit 7c4b79b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
9 changes: 7 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ var (
map[string]string{
"check-mb4-value-in-utf8": "tidb_check_mb4_value_in_utf8",
"enable-collect-execution-info": "tidb_enable_collect_execution_info",
"plugin.load": "plugin_load",
"plugin.dir": "plugin_dir",
},
},
{
Expand All @@ -134,6 +132,13 @@ var (
"memory-usage-alarm-ratio": "tidb_memory_usage_alarm_ratio",
},
},
{
"plugin",
map[string]string{
"load": "plugin_load",
"dir": "plugin_dir",
},
},
}

// ConflictOptions indicates the conflict config options existing in both [instance] and other sections in config file.
Expand Down
26 changes: 22 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,26 +543,44 @@ func TestConflictInstanceConfig(t *testing.T) {
require.Equal(t, expectedNewName, newName)
}
}
}

err = f.Truncate(0)
require.NoError(t, err)
_, err = f.Seek(0, 0)
func TestDeprecatedConfig(t *testing.T) {
var expectedNewName string
conf := new(Config)
configFile := "config.toml"
_, localFile, _, _ := runtime.Caller(0)
configFile = filepath.Join(filepath.Dir(localFile), configFile)

f, err := os.Create(configFile)
require.NoError(t, err)
defer func(configFile string) {
require.NoError(t, os.Remove(configFile))
}(configFile)

// DeprecatedOptions indicates the options that should be moved to [instance] section.
// The value in conf.Instance.* would be overwritten by the other sections.
expectedDeprecatedOptions := map[string]InstanceConfigSection{
"": {
"", map[string]string{"enable-collect-execution-info": "tidb_enable_collect_execution_info"},
"", map[string]string{
"enable-collect-execution-info": "tidb_enable_collect_execution_info",
},
},
"log": {
"log", map[string]string{"slow-threshold": "tidb_slow_log_threshold"},
},
"performance": {
"performance", map[string]string{"memory-usage-alarm-ratio": "tidb_memory_usage_alarm_ratio"},
},
"plugin": {
"plugin", map[string]string{
"load": "plugin_load",
"dir": "plugin_dir",
},
},
}
_, err = f.WriteString("enable-collect-execution-info = false \n" +
"[plugin] \ndir=\"/plugin-path\" \nload=\"audit-1,whitelist-1\" \n" +
"[log] \nslow-threshold = 100 \n" +
"[performance] \nmemory-usage-alarm-ratio = 0.5")
require.NoError(t, err)
Expand Down
11 changes: 7 additions & 4 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,6 @@ func setGlobalVars() {
cfg.Instance.CheckMb4ValueInUTF8.Store(cfg.CheckMb4ValueInUTF8.Load())
case "enable-collect-execution-info":
cfg.Instance.EnableCollectExecutionInfo = cfg.EnableCollectExecutionInfo
case "plugin.load":
cfg.Instance.PluginLoad = cfg.Plugin.Load
case "plugin.dir":
cfg.Instance.PluginDir = cfg.Plugin.Dir
}
case "log":
switch oldName {
Expand All @@ -575,6 +571,13 @@ func setGlobalVars() {
case "memory-usage-alarm-ratio":
cfg.Instance.MemoryUsageAlarmRatio = cfg.Performance.MemoryUsageAlarmRatio
}
case "plugin":
switch oldName {
case "load":
cfg.Instance.PluginLoad = cfg.Plugin.Load
case "dir":
cfg.Instance.PluginDir = cfg.Plugin.Dir
}
default:
}
}
Expand Down

0 comments on commit 7c4b79b

Please sign in to comment.