Skip to content

Commit

Permalink
Merge branch 'master' into testify_server
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jun 17, 2022
2 parents 560dbee + 9acd56a commit 4950757
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
1 change: 0 additions & 1 deletion server/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ func (h *confHandler) SetReplicationConfig(w http.ResponseWriter, r *http.Reques
// @Summary Get label property config.
// @Produce json
// @Success 200 {object} config.LabelPropertyConfig
// @Failure 400 {string} string "The input is invalid."
// @Router /config/label-property [get]
func (h *confHandler) GetLabelPropertyConfig(w http.ResponseWriter, r *http.Request) {
h.rd.JSON(w, http.StatusOK, h.svr.GetLabelProperty())
Expand Down
18 changes: 9 additions & 9 deletions server/cluster/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,10 @@ func collectHotMetrics(cluster *RaftCluster, stores []*core.StoreInfo, typ stati
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_query_as_leader").Set(stat.TotalLoads[queryTyp])
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "hot_"+kind+"_region_as_leader").Set(float64(stat.Count))
} else {
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_bytes_as_leader").Set(0)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_keys_as_leader").Set(0)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_query_as_leader").Set(0)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "hot_"+kind+"_region_as_leader").Set(0)
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "total_"+kind+"_bytes_as_leader")
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "total_"+kind+"_keys_as_leader")
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "total_"+kind+"_query_as_leader")
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "hot_"+kind+"_region_as_leader")
}

stat, ok = status.AsPeer[storeID]
Expand All @@ -594,10 +594,10 @@ func collectHotMetrics(cluster *RaftCluster, stores []*core.StoreInfo, typ stati
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_query_as_peer").Set(stat.TotalLoads[queryTyp])
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "hot_"+kind+"_region_as_peer").Set(float64(stat.Count))
} else {
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_bytes_as_peer").Set(0)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_keys_as_peer").Set(0)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "total_"+kind+"_query_as_peer").Set(0)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "hot_"+kind+"_region_as_peer").Set(0)
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "total_"+kind+"_bytes_as_peer")
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "total_"+kind+"_keys_as_peer")
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "total_"+kind+"_query_as_peer")
hotSpotStatusGauge.DeleteLabelValues(storeAddress, storeLabel, "hot_"+kind+"_region_as_peer")
}
}
}
Expand Down Expand Up @@ -673,7 +673,7 @@ func (c *coordinator) removeScheduler(name string) error {
}

s.Stop()
schedulerStatusGauge.WithLabelValues(name, "allow").Set(0)
schedulerStatusGauge.DeleteLabelValues(name, "allow")
delete(c.schedulers, name)

return nil
Expand Down
4 changes: 3 additions & 1 deletion server/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ func (conf *balanceLeaderSchedulerConfig) validate() bool {
func (conf *balanceLeaderSchedulerConfig) Clone() *balanceLeaderSchedulerConfig {
conf.mu.RLock()
defer conf.mu.RUnlock()
ranges := make([]core.KeyRange, len(conf.Ranges))
copy(ranges, conf.Ranges)
return &balanceLeaderSchedulerConfig{
Ranges: conf.Ranges,
Ranges: ranges,
Batch: conf.Batch,
}
}
Expand Down
38 changes: 38 additions & 0 deletions server/schedulers/balance_leader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package schedulers

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestBalanceLeaderSchedulerConfigClone(t *testing.T) {
re := require.New(t)
keyRanges1, _ := getKeyRanges([]string{"a", "b", "c", "d"})
conf := &balanceLeaderSchedulerConfig{
Ranges: keyRanges1,
Batch: 10,
}
conf2 := conf.Clone()
re.Equal(conf.Batch, conf2.Batch)
re.Equal(conf.Ranges, conf2.Ranges)

keyRanges2, _ := getKeyRanges([]string{"e", "f", "g", "h"})
// update conf2
conf2.Ranges[1] = keyRanges2[1]
re.NotEqual(conf.Ranges, conf2.Ranges)
}
4 changes: 3 additions & 1 deletion server/schedulers/grant_hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ func (conf *grantHotRegionSchedulerConfig) SetStoreLeaderID(id uint64) {
func (conf *grantHotRegionSchedulerConfig) Clone() *grantHotRegionSchedulerConfig {
conf.mu.RLock()
defer conf.mu.RUnlock()
newStoreIDs := make([]uint64, len(conf.StoreIDs))
copy(newStoreIDs, conf.StoreIDs)
return &grantHotRegionSchedulerConfig{
StoreIDs: conf.StoreIDs,
StoreIDs: newStoreIDs,
StoreLeaderID: conf.StoreLeaderID,
}
}
Expand Down
6 changes: 5 additions & 1 deletion server/schedulers/grant_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ func (conf *grantLeaderSchedulerConfig) BuildWithArgs(args []string) error {
func (conf *grantLeaderSchedulerConfig) Clone() *grantLeaderSchedulerConfig {
conf.mu.RLock()
defer conf.mu.RUnlock()
newStoreIDWithRanges := make(map[uint64][]core.KeyRange)
for k, v := range conf.StoreIDWithRanges {
newStoreIDWithRanges[k] = v
}
return &grantLeaderSchedulerConfig{
StoreIDWithRanges: conf.StoreIDWithRanges,
StoreIDWithRanges: newStoreIDWithRanges,
}
}

Expand Down

0 comments on commit 4950757

Please sign in to comment.