-
Notifications
You must be signed in to change notification settings - Fork 722
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
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Codecov Report
@@ Coverage Diff @@
## master #3989 +/- ##
==========================================
+ Coverage 74.65% 74.77% +0.11%
==========================================
Files 258 258
Lines 26337 26413 +76
==========================================
+ Hits 19662 19749 +87
+ Misses 4929 4902 -27
- Partials 1746 1762 +16
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@IcePigZDB: Request changes is only allowed for the reviewers in list. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
ea2a150
to
4731301
Compare
There are enough reviewers so I'm unassigning myself :) |
conf/simconfig.toml
Outdated
@@ -29,3 +29,6 @@ leader-schedule-limit = 32 | |||
region-schedule-limit = 128 | |||
replica-schedule-limit = 32 | |||
merge-schedule-limit = 32 | |||
## TODO:Find a better place to put this config | |||
hot-regions-reserved-days= "30" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In simconfig
, use 0 to close it is ok, it is the simulator environment.
server/api/router.go
Outdated
@@ -140,6 +140,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router { | |||
apiRouter.HandleFunc("/hotspot/regions/write", hotStatusHandler.GetHotWriteRegions).Methods("GET") | |||
apiRouter.HandleFunc("/hotspot/regions/read", hotStatusHandler.GetHotReadRegions).Methods("GET") | |||
apiRouter.HandleFunc("/hotspot/stores", hotStatusHandler.GetHotStores).Methods("GET") | |||
apiRouter.HandleFunc("/hotspot/regions/history", hotStatusHandler.GetHistoryHotRegions).Methods("POST") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use "Get" more suitable?
server/handler.go
Outdated
storeSet := make(map[uint64]bool) | ||
peerSet := make(map[uint64]bool) | ||
for _, id := range request.RegionIDs { | ||
regionSet[id] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need request region IDs and peerIDs? I think only StoresIds
and KeyRange
are reasonable.
@@ -0,0 +1,50 @@ | |||
package statistics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add license like other files.
server/cluster/hot_region_storage.go
Outdated
@@ -0,0 +1,320 @@ | |||
package cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license.
BTW, I think your PR can split into three PRs:
more small PRs review more quickly. And the quality is more guaranteed. |
BTW, you can also supports pd-ctl command to check hot history region. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommended submitting single pr for storage part first
server/cluster/hot_region_storage.go
Outdated
for { | ||
select { | ||
case <-ticker.C: | ||
if h.member.IsLeader() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommended that HotRegionStorage
should be controlled by whether the member is elected as leader during leader campaign to guarantee only the leader could flush data instead of checking leader identity in its own logic.
server/cluster/hot_region_storage.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
hotRegionInfoCtx, hotRegionInfoCancle := context.WithCancel(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hotRegionInfoCtx, hotRegionInfoCancle := context.WithCancel(ctx) | |
hotRegionInfoCtx, hotRegionInfoCancel := context.WithCancel(ctx) |
server/cluster/hot_region_storage.go
Outdated
// make delete happened in defaultDeleteTime clock. | ||
now := time.Now() | ||
next := now.Add(time.Hour * 24) | ||
next = time.Date(next.Year(), next.Month(), next.Day(), defaultDeleteTime, 0, 0, 0, next.Location()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here is kind of weird. I think this could be simplified as running background job 24 hours once here, and simply delete the data which timestamp prefix ranges belong to [0, now - 7 days ago).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I want the delete function run at a time point, such as one clock every day.
server/cluster/hot_region_storage.go
Outdated
now := time.Now() | ||
next := now.Add(time.Hour * 24) | ||
next = time.Date(next.Year(), next.Month(), next.Day(), defaultDeleteTime, 0, 0, 0, next.Location()) | ||
t := time.NewTicker(next.Sub(now)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer ticker.stop as soon as possible after creating ticker.
server/cluster/hot_region_storage.go
Outdated
ticker := time.NewTicker(h.pullInterval) | ||
go func() { | ||
defer ticker.Stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
server/cluster/hot_region_storage.go
Outdated
select { | ||
case <-ticker.C: | ||
if h.member.IsLeader() { | ||
if err := h.pullHotRegionInfo(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If error happened, we should continue this loop.
server/cluster/hot_region_storage.go
Outdated
type HotRegionStorage struct { | ||
*kv.LeveldbKV | ||
encryptionKeyManager *encryptionkm.KeyManager | ||
mu sync.RWMutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use mutex like following in order to make it clear that which variables are under mutex controlled.
mu struct {
sync.Mutex
....
controlled variable here
}
server/cluster/hot_region_storage.go
Outdated
if err := h.LeveldbKV.Write(batch, nil); err != nil { | ||
return errs.ErrLevelDBWrite.Wrap(err).GenWithStackByCause() | ||
} | ||
h.batchHotInfo = make(map[string]*statistics.HistoryHotRegion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this line used for?
…ve AsLeader Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
f73e4a4
to
64e8802
Compare
Signed-off-by: qidi1 <1083369179@qq.com>
@qidi1: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Signed-off-by: qidi1 1083369179@qq.com
What problem does this PR solve?
#4019
#4020
#4021
Proposal: pingcap/tidb#27487
Associated PR:tikv/tidb#27224
Associated Issue: pingcap/tidb#25281
pingcap/tidb#27373
pingcap/tidb#27374
What is changed and how it works?
Store hot-region information regularly,Provide api interface for requesting historical hot-region information
Check List
Tests
Code changes
add hot-regions-reserved-days and hot-regions-write-interval in scheduler,hot-regions-reserved-days means how many days of information are kept,hot-regions-write-interval means the time interval for pulling information
Add post api /hotspot/regions/history
store hot region info
Side effects
store hot region data may have some performance to pd,under 1000 regions,10 min write intervals context,to read all data in a month needs 18s, 1.7s is needed for every month Leveldb compaction
Related changes
Associated PR: pingcap/tidb#27224
Release note