Skip to content

Commit 92932ad

Browse files
authored
config: fix precheck blocking the change of other PD configurations (#10132)
close #10114 Signed-off-by: Ryan Leung <rleungx@gmail.com>
1 parent f620e2b commit 92932ad

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

server/server.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,22 +1289,24 @@ func (s *Server) GetPDServerConfig() *config.PDServerConfig {
12891289

12901290
// SetPDServerConfig sets the server config.
12911291
func (s *Server) SetPDServerConfig(cfg config.PDServerConfig) error {
1292-
switch cfg.DashboardAddress {
1293-
case "auto":
1294-
case "none":
1295-
default:
1296-
if !strings.HasPrefix(cfg.DashboardAddress, "http") {
1297-
cfg.DashboardAddress = fmt.Sprintf("%s://%s", s.GetClientScheme(), cfg.DashboardAddress)
1298-
}
1299-
if !cluster.IsClientURL(cfg.DashboardAddress, s.client) {
1300-
return errors.Errorf("%s is not the client url of any member", cfg.DashboardAddress)
1301-
}
1302-
}
13031292
if err := cfg.Validate(); err != nil {
13041293
return err
13051294
}
1306-
13071295
old := s.persistOptions.GetPDServerConfig()
1296+
// See https://github.com/tikv/pd/issues/10114 for more details
1297+
if old.DashboardAddress != cfg.DashboardAddress {
1298+
switch cfg.DashboardAddress {
1299+
case "auto":
1300+
case "none":
1301+
default:
1302+
if !strings.HasPrefix(cfg.DashboardAddress, "http") {
1303+
cfg.DashboardAddress = fmt.Sprintf("%s://%s", s.GetClientScheme(), cfg.DashboardAddress)
1304+
}
1305+
if !cluster.IsClientURL(cfg.DashboardAddress, s.client) {
1306+
return errors.Errorf("dashboard address %s is not the client url of any member", cfg.DashboardAddress)
1307+
}
1308+
}
1309+
}
13081310
s.persistOptions.SetPDServerConfig(&cfg)
13091311
if err := s.persistOptions.Persist(s.storage); err != nil {
13101312
s.persistOptions.SetPDServerConfig(old)

tests/server/server_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,40 @@ func TestMeteringWriter(t *testing.T) {
581581
re.True(ok)
582582
re.Equal(rmserver.ResourceManagerCategory, ruCollector.Category())
583583
}
584+
585+
func TestSetPDServerConfigWithDashboard(t *testing.T) {
586+
re := require.New(t)
587+
ctx, cancel := context.WithCancel(context.Background())
588+
defer cancel()
589+
590+
cluster, err := tests.NewTestCluster(ctx, 1)
591+
defer cluster.Destroy()
592+
re.NoError(err)
593+
594+
err = cluster.RunInitialServers()
595+
re.NoError(err)
596+
597+
leader := cluster.WaitLeader()
598+
re.NotEmpty(leader)
599+
svr := cluster.GetServer(leader).GetServer()
600+
601+
// Test updating config without changing dashboard address
602+
cfg := svr.GetPDServerConfig()
603+
originalDashboard := cfg.DashboardAddress
604+
originalUseRegionStorage := cfg.UseRegionStorage
605+
606+
// Change some other field but keep dashboard the same
607+
cfg.UseRegionStorage = !cfg.UseRegionStorage
608+
err = svr.SetPDServerConfig(*cfg)
609+
re.NoError(err)
610+
611+
newCfg := svr.GetPDServerConfig()
612+
re.Equal(originalDashboard, newCfg.DashboardAddress)
613+
re.NotEqual(originalUseRegionStorage, newCfg.UseRegionStorage)
614+
615+
// Change both other field and dashboard
616+
cfg.UseRegionStorage = !cfg.UseRegionStorage
617+
cfg.DashboardAddress = "https://new-dashboard-address:1234"
618+
err = svr.SetPDServerConfig(*cfg)
619+
re.ErrorContains(err, "is not the client url of any member")
620+
}

0 commit comments

Comments
 (0)