Skip to content

Commit

Permalink
config: completely remove the deprecated field from the PD server con…
Browse files Browse the repository at this point in the history
…fig (#8981) (#9059)

close #8980

server/config: completely remove the deprecated field from the PD server config

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: nolouch <nolouch@gmail.com>

Co-authored-by: ShuNing <nolouch@gmail.com>
Co-authored-by: nolouch <nolouch@gmail.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 12, 2025
1 parent ca61765 commit 370c4ce
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
30 changes: 6 additions & 24 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"math"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -507,9 +506,6 @@ type PDServerConfig struct {
MetricStorage string `toml:"metric-storage" json:"metric-storage"`
// There are some values supported: "auto", "none", or a specific address, default: "auto"
DashboardAddress string `toml:"dashboard-address" json:"dashboard-address"`
// TraceRegionFlow the option to update flow information of regions.
// WARN: TraceRegionFlow is deprecated.
TraceRegionFlow bool `toml:"trace-region-flow" json:"trace-region-flow,string,omitempty"`
// FlowRoundByDigit used to discretization processing flow information.
FlowRoundByDigit int `toml:"flow-round-by-digit" json:"flow-round-by-digit"`
// MinResolvedTSPersistenceInterval is the interval to save the min resolved ts.
Expand Down Expand Up @@ -573,35 +569,21 @@ func (c *PDServerConfig) adjust(meta *configutil.ConfigMetaData) error {
} else if c.GCTunerThreshold > maxGCTunerThreshold {
c.GCTunerThreshold = maxGCTunerThreshold
}
c.migrateConfigurationFromFile(meta)
migrateConfigurationFromFile(meta)
return c.Validate()
}

func (c *PDServerConfig) migrateConfigurationFromFile(meta *configutil.ConfigMetaData) error {
func migrateConfigurationFromFile(meta *configutil.ConfigMetaData) error {
oldName, newName := "trace-region-flow", "flow-round-by-digit"
defineOld, defineNew := meta.IsDefined(oldName), meta.IsDefined(newName)
defineOld := meta.IsDefined(oldName)
switch {
case defineOld && defineNew:
if c.TraceRegionFlow && (c.FlowRoundByDigit == defaultFlowRoundByDigit) {
return errors.Errorf("config item %s and %s(deprecated) are conflict", newName, oldName)
}
case defineOld && !defineNew:
if !c.TraceRegionFlow {
c.FlowRoundByDigit = math.MaxInt8
}
case defineOld:
return errors.Errorf("config item %s and %s(deprecated) are conflict", newName, oldName)
default:
}
return nil
}

// MigrateDeprecatedFlags updates new flags according to deprecated flags.
func (c *PDServerConfig) MigrateDeprecatedFlags() {
if !c.TraceRegionFlow {
c.FlowRoundByDigit = math.MaxInt8
}
// json omity the false. next time will not persist to the kv.
c.TraceRegionFlow = false
}

// Clone returns a cloned PD server config.
func (c *PDServerConfig) Clone() *PDServerConfig {
runtimeServices := append(c.RuntimeServices[:0:0], c.RuntimeServices...)
Expand Down
2 changes: 1 addition & 1 deletion server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func TestMigrateFlags(t *testing.T) {
}
cfg, err := load(`
[pd-server]
trace-region-flow = false
flow-round-by-digit = 127
[schedule]
disable-remove-down-replica = true
enable-make-up-replica = false
Expand Down
1 change: 0 additions & 1 deletion server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,6 @@ func (o *PersistOptions) Reload(storage endpoint.ConfigStorage) error {
o.adjustScheduleCfg(&cfg.Schedule)
// Some fields may not be stored in the storage, we need to calculate them manually.
cfg.StoreConfig.Adjust()
cfg.PDServerCfg.MigrateDeprecatedFlags()
if isExist {
o.schedule.Store(&cfg.Schedule)
o.replication.Store(&cfg.Replication)
Expand Down
1 change: 0 additions & 1 deletion tests/pdctl/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func TestConfig(t *testing.T) {
args = []string{"-u", pdAddr, "config", "set", "trace-region-flow", "false"}
_, err = pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
re.False(svr.GetPDServerConfig().TraceRegionFlow)

args = []string{"-u", pdAddr, "config", "set", "flow-round-by-digit", "10"}
_, err = pdctl.ExecuteCommand(cmd, args...)
Expand Down

0 comments on commit 370c4ce

Please sign in to comment.