Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api:add api for history_hot_region info;cluster add storage for hot region;config add config for hot-region storage #3989

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8f45266
config:add config for hot region history
qidi1 Aug 15, 2021
5daff0f
api:add history-hot-region interface
qidi1 Aug 15, 2021
0f744af
statistics:add comminicate struct
qidi1 Aug 15, 2021
d95e987
cluster:add hot region storage
qidi1 Aug 15, 2021
c77c560
server:add method to get hot region info
qidi1 Aug 15, 2021
f03c4e5
conf: add config in config toml
qidi1 Aug 15, 2021
bdf7ca5
fix style error in code
qidi1 Aug 15, 2021
b0b6e0f
Merge branch 'master' into qidi1
disksing Aug 16, 2021
a2c43fa
commit for cherry-pick
qidi1 Aug 20, 2021
8fab37c
config:add hot_regions_write_interval&hot_regions_remian_days in to c…
qidi1 Aug 23, 2021
81ed653
cluster:add hot_region_storage
qidi1 Aug 23, 2021
d74aaee
api:add interface for hot_region info reqeust
qidi1 Aug 23, 2021
9ff1c2c
change config part
qidi1 Aug 23, 2021
4e4c009
change api part
qidi1 Aug 23, 2021
cc7dfa6
change cluster part
qidi1 Aug 23, 2021
fc0b866
change isleader to bool
qidi1 Aug 24, 2021
52bc0f1
change isleader to bool
qidi1 Aug 24, 2021
ec10b04
change request way to get
qidi1 Aug 24, 2021
27d0000
remove cluster code that no need
qidi1 Aug 25, 2021
c9f8b24
api:remove range fliter
qidi1 Aug 25, 2021
1ec631f
add wg
qidi1 Aug 28, 2021
77d73bf
move getjson to util
qidi1 Aug 28, 2021
77c4775
add isLearn to api
qidi1 Aug 28, 2021
78178e5
Merge branch 'master' into qidi1
qidi1 Aug 28, 2021
2705035
move hot_region_storage to core
qidi1 Aug 31, 2021
5709064
move hot_region_storage to core
qidi1 Aug 31, 2021
ffe81b8
change return 200 to core.HistoryHotRegions
qidi1 Aug 31, 2021
c37f7ca
Merge https://github.com/IcePigZDB/pd into qidi1
qidi1 Sep 1, 2021
a4d0d6a
merge to remote
qidi1 Sep 1, 2021
5c3aca3
cluster:merge from remote
qidi1 Sep 1, 2021
168d2e9
api:merge from remote
qidi1 Sep 1, 2021
ea4ff9f
config:merge from remote
qidi1 Sep 1, 2021
b7dab7b
cluster:change 1000 to time.Millisecond
qidi1 Sep 2, 2021
a242499
config:remove old code
qidi1 Sep 2, 2021
80fa477
cluster:change 12 to defalut,go out function
qidi1 Sep 2, 2021
3fb807c
config:change discprtion
qidi1 Sep 2, 2021
e28de35
clsuter:format check
qidi1 Sep 2, 2021
7e65973
api:format check
qidi1 Sep 2, 2021
324d925
cluster:add mock for peer id
qidi1 Sep 2, 2021
f22e7b3
config:change default
qidi1 Sep 2, 2021
c7520c9
apiadd error request test
qidi1 Sep 10, 2021
d923486
command:add hot-history-regions command
qidi1 Sep 11, 2021
9c8ce2e
api:if no arguments in is_leaders or is_learners,return all
qidi1 Sep 11, 2021
b4be83e
cluster:fix bug every region see as read,AsPeer include AsLeader,remo…
qidi1 Sep 12, 2021
f9b6797
command:add test for hot history regions
qidi1 Sep 12, 2021
cfab956
cluster:add test for hot region storage
qidi1 Sep 12, 2021
bc0f0c2
api:change return nil to err,change reponse of 500 code
qidi1 Sep 14, 2021
7b9233e
cluster:add test in tests/server/core
qidi1 Sep 14, 2021
f3d6135
cluster:remove some unuse code
qidi1 Sep 14, 2021
e931026
api:remove unuse code
qidi1 Sep 14, 2021
a47777c
api:remove append in leaderSet and learnerSet
qidi1 Sep 15, 2021
31d5264
ctl:append if is_leader and is_learner not sepcfic
qidi1 Sep 15, 2021
50ebc1b
ctl:change test name to TestHistoryHotRegions
qidi1 Sep 16, 2021
566d0eb
core:change core.HotRegionType from string to enum
qidi1 Sep 18, 2021
f803c06
Merge branch 'master' into qidi1
qidi1 Sep 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions cmd/pd-server/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag

package docs

import (
"bytes"
"encoding/json"
"strings"

"github.com/alecthomas/template"
"github.com/swaggo/swag"
)

var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {}
}`

type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = swaggerInfo{
qidi1 marked this conversation as resolved.
Show resolved Hide resolved
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
}

type s struct{}

func (s *s) ReadDoc() string {
sInfo := SwaggerInfo
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)

t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
},
}).Parse(doc)
if err != nil {
return doc
}

var tpl bytes.Buffer
if err := t.Execute(&tpl, sInfo); err != nil {
return doc
}

return tpl.String()
}

func init() {
swag.Register(swag.Name, &s{})
}
7 changes: 7 additions & 0 deletions cmd/pd-server/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"swagger": "2.0",
"info": {
"contact": {}
},
"paths": {}
}
4 changes: 4 additions & 0 deletions cmd/pd-server/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
info:
contact: {}
paths: {}
swagger: "2.0"
3 changes: 1 addition & 2 deletions server/api/hot_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,5 @@ func writeToDB(kv *kv.LeveldbKV, hotRegions []*core.HistoryHotRegion) error {
}
batch.Put([]byte(key), value)
}
kv.Write(batch, nil)
return nil
return kv.Write(batch, nil)
}
1 change: 1 addition & 0 deletions server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
hotStatusHandler := newHotStatusHandler(handler, rd)
apiRouter.HandleFunc("/hotspot/regions/write", hotStatusHandler.GetHotWriteRegions).Methods("GET")
apiRouter.HandleFunc("/hotspot/regions/read", hotStatusHandler.GetHotReadRegions).Methods("GET")
apiRouter.HandleFunc("/hotspot/regions/history", hotStatusHandler.GetHistoryHotRegions).Methods("GET")
apiRouter.HandleFunc("/hotspot/stores", hotStatusHandler.GetHotStores).Methods("GET")
apiRouter.HandleFunc("/hotspot/regions/history", hotStatusHandler.GetHistoryHotRegions).Methods("GET")

Expand Down
30 changes: 25 additions & 5 deletions server/core/hot_region_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,30 @@ const (
defaultDeleteTime = 4
)

// HotRegionType stands for hot type.
type HotRegionType uint32

// Flags for flow.
const (
WriteType HotRegionType = iota
ReadType
)

// HotRegionTypes stands for hot type.
var HotRegionTypes = []string{
"read",
"write",
WriteType.String(),
ReadType.String(),
}

// String return HotRegionType in string format.
func (h HotRegionType) String() string {
switch h {
case WriteType:
return "write"
case ReadType:
return "read"
}
return "unimplemented"
}

// NewHotRegionsStorage create storage to store hot regions info.
Expand Down Expand Up @@ -223,14 +243,14 @@ func (h *HotRegionStorage) pullHotRegionInfo() error {
if err != nil {
return err
}
if err := h.packHistoryHotRegions(historyHotReadRegions, HotRegionTypes[0]); err != nil {
if err := h.packHistoryHotRegions(historyHotReadRegions, ReadType.String()); err != nil {
return err
}
historyHotWriteRegions, err := h.hotRegionStorageHandler.PackHistoryHotWriteRegions()
if err != nil {
return err
}
err = h.packHistoryHotRegions(historyHotWriteRegions, HotRegionTypes[1])
err = h.packHistoryHotRegions(historyHotWriteRegions, WriteType.String())
return err
}

Expand All @@ -248,7 +268,7 @@ func (h *HotRegionStorage) packHistoryHotRegions(historyHotRegions []HistoryHotR
}
historyHotRegions[i].StartKey = region.StartKey
historyHotRegions[i].EndKey = region.EndKey
key := HotRegionStorePath(HotRegionTypes[0], historyHotRegions[i].UpdateTime, historyHotRegions[i].RegionID)
key := HotRegionStorePath(hotRegionType, historyHotRegions[i].UpdateTime, historyHotRegions[i].RegionID)
h.batchHotInfo[key] = &historyHotRegions[i]
}
return nil
Expand Down
22 changes: 15 additions & 7 deletions server/core/hot_region_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,33 @@ func (t *testHotRegionStorage) TestHotRegionWrite(c *C) {
UpdateTime: now.UnixNano() / int64(time.Millisecond),
RegionID: 1,
StoreID: 1,
HotRegionType: HotRegionTypes[0],
HotRegionType: ReadType.String(),
},
{
UpdateTime: now.Add(10*time.Second).UnixNano() / int64(time.Millisecond),
RegionID: 2,
StoreID: 1,
HotRegionType: HotRegionTypes[0],
HotRegionType: ReadType.String(),
},
{
UpdateTime: now.Add(20*time.Second).UnixNano() / int64(time.Millisecond),
RegionID: 3,
StoreID: 1,
HotRegionType: HotRegionTypes[0],
HotRegionType: ReadType.String(),
},
}
packHotRegionInfo.historyHotReads = hotRegionStorages
packHotRegionInfo.historyHotWrites = []HistoryHotRegion{
{
UpdateTime: now.Add(30*time.Second).UnixNano() / int64(time.Millisecond),
RegionID: 4,
StoreID: 1,
HotRegionType: WriteType.String(),
},
}
store.pullHotRegionInfo()
store.flush()
iter := store.NewIterator(HotRegionTypes,
iter := store.NewIterator([]string{ReadType.String()},
now.UnixNano()/int64(time.Millisecond),
now.Add(40*time.Second).UnixNano()/int64(time.Millisecond))
index := 0
Expand All @@ -143,19 +151,19 @@ func (t *testHotRegionStorage) TestHotRegionDelete(c *C) {
UpdateTime: deleteDate.UnixNano() / int64(time.Millisecond),
RegionID: 1,
StoreID: 1,
HotRegionType: HotRegionTypes[0],
HotRegionType: ReadType.String(),
},
{
UpdateTime: deleteDate.Add(10*time.Second).UnixNano() / int64(time.Millisecond),
RegionID: 2,
StoreID: 1,
HotRegionType: HotRegionTypes[0],
HotRegionType: ReadType.String(),
},
{
UpdateTime: time.Now().UnixNano() / int64(time.Millisecond),
RegionID: 3,
StoreID: 1,
HotRegionType: HotRegionTypes[0],
HotRegionType: ReadType.String(),
},
}
packHotRegionInfo.historyHotReads = hotRegionStorages
Expand Down
37 changes: 17 additions & 20 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,54 +912,51 @@ func (h *Handler) IsLeader() bool {

// PackHistoryHotReadRegions get read hot region info in HistoryHotRegion form.
func (h *Handler) PackHistoryHotReadRegions() (historyHotRegions []core.HistoryHotRegion, err error) {
hotReadLeaderRegions := h.GetHotReadRegions().AsLeader
historyLeaderHotRegions, err := h.packHotRegions(hotReadLeaderRegions, true, core.HotRegionTypes[0])
if err != nil {
hotReadRegions := h.GetHotReadRegions()
if hotReadRegions == nil {
return
}
hotReadPeerRegions := h.GetHotReadRegions().AsPeer
historyPeerHotRegions, err := h.packHotRegions(hotReadPeerRegions, false, core.HotRegionTypes[0])
hotReadPeerRegions := hotReadRegions.AsPeer
historyPeerHotRegions, err := h.packHotRegions(hotReadPeerRegions, core.ReadType.String())
if err != nil {
return
}
historyHotRegions = append(historyHotRegions, historyLeaderHotRegions...)
historyHotRegions = append(historyHotRegions, historyPeerHotRegions...)
return
}

// PackHistoryHotWriteRegions get write hot region info in HistoryHotRegion from
func (h *Handler) PackHistoryHotWriteRegions() (historyHotRegions []core.HistoryHotRegion, err error) {
hotWriteLeaderRegions := h.GetHotWriteRegions().AsLeader
historyLeaderHotRegions, err := h.packHotRegions(hotWriteLeaderRegions, true, core.HotRegionTypes[1])
if err != nil {
hotWriteRegions := h.GetHotWriteRegions()
if hotWriteRegions == nil {
return
}
hotWritePeerRegions := h.GetHotWriteRegions().AsPeer
historyPeerHotRegions, err := h.packHotRegions(hotWritePeerRegions, false, core.HotRegionTypes[1])
hotWritePeerRegions := hotWriteRegions.AsPeer
historyPeerHotRegions, err := h.packHotRegions(hotWritePeerRegions, core.WriteType.String())
if err != nil {
return
}
historyHotRegions = append(historyHotRegions, historyLeaderHotRegions...)
historyHotRegions = append(historyHotRegions, historyPeerHotRegions...)
return
}

func (h *Handler) packHotRegions(hotPeersStat statistics.StoreHotPeersStat, isLeader bool, hotRegionType string) (historyHotRegions []core.HistoryHotRegion, err error) {
func (h *Handler) packHotRegions(hotPeersStat statistics.StoreHotPeersStat, hotRegionType string) (historyHotRegions []core.HistoryHotRegion, err error) {
c, err := h.GetRaftCluster()
if err != nil {
return nil, err
}
for _, hotPeersStat := range hotPeersStat {
stats := hotPeersStat.Stats
for _, hotPeerStat := range stats {
region := c.GetRegion(hotPeerStat.RegionID).GetMeta()
region, err := encryption.EncryptRegion(region, h.s.encryptionKeyManager)
region := c.GetRegion(hotPeerStat.RegionID)
meta := region.GetMeta()
meta, err := encryption.EncryptRegion(meta, h.s.encryptionKeyManager)
if err != nil {
return nil, err
}
var peerID uint64
var isLearner bool
for _, peer := range region.Peers {
for _, peer := range meta.Peers {
if peer.StoreId == hotPeerStat.StoreID {
peerID = peer.Id
isLearner = peer.Role == metapb.PeerRole_Learner
Expand All @@ -971,15 +968,15 @@ func (h *Handler) packHotRegions(hotPeersStat statistics.StoreHotPeersStat, isLe
RegionID: hotPeerStat.RegionID,
StoreID: hotPeerStat.StoreID,
PeerID: peerID,
IsLeader: isLeader,
IsLeader: meta.Id == region.GetLeader().Id,
IsLearner: isLearner,
HotDegree: int64(hotPeerStat.HotDegree),
FlowBytes: hotPeerStat.ByteRate,
KeyRate: hotPeerStat.KeyRate,
QueryRate: hotPeerStat.QueryRate,
StartKey: region.StartKey,
EndKey: region.EndKey,
EncryptionMeta: region.EncryptionMeta,
StartKey: meta.StartKey,
EndKey: meta.EndKey,
EncryptionMeta: meta.EncryptionMeta,
HotRegionType: hotRegionType,
}
historyHotRegions = append(historyHotRegions, stat)
Expand Down
Loading