From 674375a99f83f530af28007f58ac5ffd15b129d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B7=E6=B2=8CDM?= Date: Fri, 11 Nov 2022 15:25:53 +0800 Subject: [PATCH] scheduler: keep rank-formula-version at v1 when upgrading from a lower version (#5699) close tikv/pd#5698 Signed-off-by: HunDunDM Co-authored-by: Ti Chi Robot --- server/schedulers/hot_region.go | 4 +++ server/schedulers/hot_region_test.go | 42 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/server/schedulers/hot_region.go b/server/schedulers/hot_region.go index 0916f7d6cb1..a504a29f4fa 100644 --- a/server/schedulers/hot_region.go +++ b/server/schedulers/hot_region.go @@ -53,8 +53,12 @@ func init() { } if len(data) != 0 { // After upgrading, use compatible config. + // For clusters with the initial version >= v5.2, it will be overwritten by the default config. conf.applyPrioritiesConfig(compatiblePrioritiesConfig) + // For clusters with the initial version >= v6.4, it will be overwritten by the default config. + conf.SetRankFormulaVersion("") + if err := decoder(conf); err != nil { return nil, err } diff --git a/server/schedulers/hot_region_test.go b/server/schedulers/hot_region_test.go index b4e148aaac4..4e937c07302 100644 --- a/server/schedulers/hot_region_test.go +++ b/server/schedulers/hot_region_test.go @@ -67,6 +67,48 @@ func clearPendingInfluence(h *hotScheduler) { h.regionPendings = make(map[uint64]*pendingInfluence) } +func TestUpgrade(t *testing.T) { + re := require.New(t) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + opt := config.NewTestOptions() + tc := mockcluster.NewCluster(ctx, opt) + // new + sche, err := schedule.CreateScheduler(HotRegionType, schedule.NewOperatorController(ctx, tc, nil), storage.NewStorageWithMemoryBackend(), schedule.ConfigSliceDecoder(HotRegionType, nil)) + re.NoError(err) + hb := sche.(*hotScheduler) + re.Equal([]string{statistics.QueryPriority, statistics.BytePriority}, hb.conf.GetReadPriorities()) + re.Equal([]string{statistics.QueryPriority, statistics.BytePriority}, hb.conf.GetWriteLeaderPriorities()) + re.Equal([]string{statistics.BytePriority, statistics.KeyPriority}, hb.conf.GetWritePeerPriorities()) + re.Equal("v2", hb.conf.GetRankFormulaVersion()) + // upgrade from json(null) + sche, err = schedule.CreateScheduler(HotRegionType, schedule.NewOperatorController(ctx, tc, nil), storage.NewStorageWithMemoryBackend(), schedule.ConfigJSONDecoder([]byte("null"))) + re.NoError(err) + hb = sche.(*hotScheduler) + re.Equal([]string{statistics.QueryPriority, statistics.BytePriority}, hb.conf.GetReadPriorities()) + re.Equal([]string{statistics.QueryPriority, statistics.BytePriority}, hb.conf.GetWriteLeaderPriorities()) + re.Equal([]string{statistics.BytePriority, statistics.KeyPriority}, hb.conf.GetWritePeerPriorities()) + re.Equal("v2", hb.conf.GetRankFormulaVersion()) + // upgrade from < 5.2 + config51 := `{"min-hot-byte-rate":100,"min-hot-key-rate":10,"min-hot-query-rate":10,"max-zombie-rounds":5,"max-peer-number":1000,"byte-rate-rank-step-ratio":0.05,"key-rate-rank-step-ratio":0.05,"query-rate-rank-step-ratio":0.05,"count-rank-step-ratio":0.01,"great-dec-ratio":0.95,"minor-dec-ratio":0.99,"src-tolerance-ratio":1.05,"dst-tolerance-ratio":1.05,"strict-picking-store":"true","enable-for-tiflash":"true"}` + sche, err = schedule.CreateScheduler(HotRegionType, schedule.NewOperatorController(ctx, tc, nil), storage.NewStorageWithMemoryBackend(), schedule.ConfigJSONDecoder([]byte(config51))) + re.NoError(err) + hb = sche.(*hotScheduler) + re.Equal([]string{statistics.BytePriority, statistics.KeyPriority}, hb.conf.GetReadPriorities()) + re.Equal([]string{statistics.KeyPriority, statistics.BytePriority}, hb.conf.GetWriteLeaderPriorities()) + re.Equal([]string{statistics.BytePriority, statistics.KeyPriority}, hb.conf.GetWritePeerPriorities()) + re.Equal("v1", hb.conf.GetRankFormulaVersion()) + // upgrade from < 6.4 + config54 := `{"min-hot-byte-rate":100,"min-hot-key-rate":10,"min-hot-query-rate":10,"max-zombie-rounds":5,"max-peer-number":1000,"byte-rate-rank-step-ratio":0.05,"key-rate-rank-step-ratio":0.05,"query-rate-rank-step-ratio":0.05,"count-rank-step-ratio":0.01,"great-dec-ratio":0.95,"minor-dec-ratio":0.99,"src-tolerance-ratio":1.05,"dst-tolerance-ratio":1.05,"read-priorities":["query","byte"],"write-leader-priorities":["query","byte"],"write-peer-priorities":["byte","key"],"strict-picking-store":"true","enable-for-tiflash":"true","forbid-rw-type":"none"}` + sche, err = schedule.CreateScheduler(HotRegionType, schedule.NewOperatorController(ctx, tc, nil), storage.NewStorageWithMemoryBackend(), schedule.ConfigJSONDecoder([]byte(config54))) + re.NoError(err) + hb = sche.(*hotScheduler) + re.Equal([]string{statistics.QueryPriority, statistics.BytePriority}, hb.conf.GetReadPriorities()) + re.Equal([]string{statistics.QueryPriority, statistics.BytePriority}, hb.conf.GetWriteLeaderPriorities()) + re.Equal([]string{statistics.BytePriority, statistics.KeyPriority}, hb.conf.GetWritePeerPriorities()) + re.Equal("v1", hb.conf.GetRankFormulaVersion()) +} + func TestGCPendingOpInfos(t *testing.T) { re := require.New(t) ctx, cancel := context.WithCancel(context.Background())