From 7c4b79b9cedae53ab36b227f5d7cd4a75700534a Mon Sep 17 00:00:00 2001 From: CbcWestwolf <1004626265@qq.com> Date: Wed, 25 May 2022 11:26:46 +0800 Subject: [PATCH] cherry pick #34926 to release-6.1 Signed-off-by: ti-srebot --- config/config.go | 9 +++++++-- config/config_test.go | 26 ++++++++++++++++++++++---- tidb-server/main.go | 11 +++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index b0620728eaf91..0a6f85e66a547 100644 --- a/config/config.go +++ b/config/config.go @@ -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", }, }, { @@ -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. diff --git a/config/config_test.go b/config/config_test.go index 545f8d4d627b6..2ca959fc857b6 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -543,17 +543,28 @@ 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"}, @@ -561,8 +572,15 @@ func TestConflictInstanceConfig(t *testing.T) { "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) diff --git a/tidb-server/main.go b/tidb-server/main.go index a211360d6ec2b..06e26eb2341c6 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -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 { @@ -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: } }