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

Conversation

qidi1
Copy link
Contributor

@qidi1 qidi1 commented Aug 15, 2021

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

  • Unit test

Code changes

  • Has configuration change
    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
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
    Add post api /hotspot/regions/history
  • Has persistent data change
    store hot region info

Side effects

  • Possible performance regression
    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

Store hot-region information regularly,Provide  api interface for requesting historical hot-region information

@ti-chi-bot
Copy link
Member

[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 /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes 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
Copy link

codecov bot commented Aug 16, 2021

Codecov Report

Merging #3989 (f803c06) into master (1db2398) will increase coverage by 0.11%.
The diff coverage is 65.97%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 74.77% <65.97%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tools/pd-ctl/pdctl/command/hot_command.go 59.34% <56.94%> (-3.40%) ⬇️
server/core/hot_region_storage.go 74.68% <77.77%> (+0.34%) ⬆️
server/api/router.go 97.25% <100.00%> (+0.01%) ⬆️
server/handler.go 48.15% <100.00%> (+9.36%) ⬆️
server/tso/local_allocator.go 71.62% <0.00%> (-6.76%) ⬇️
server/election/lease.go 85.71% <0.00%> (-6.35%) ⬇️
server/region_syncer/client.go 77.46% <0.00%> (-4.23%) ⬇️
pkg/dashboard/adapter/manager.go 79.78% <0.00%> (-3.20%) ⬇️
client/base_client.go 81.52% <0.00%> (-2.72%) ⬇️
server/member/member.go 65.24% <0.00%> (-1.61%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1db2398...f803c06. Read the comment docs.

conf/config.toml Outdated Show resolved Hide resolved
conf/simconfig.toml Outdated Show resolved Hide resolved
server/cluster/hot_region_storage.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage_test.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage_test.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage_test.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage_test.go Outdated Show resolved Hide resolved
server/cluster/hot_region_storage_test.go Outdated Show resolved Hide resolved
@ti-chi-bot
Copy link
Member

@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.

@qidi1 qidi1 force-pushed the qidi1 branch 3 times, most recently from ea2a150 to 4731301 Compare August 16, 2021 07:22
@nolouch nolouch self-requested a review August 17, 2021 02:57
conf/config.toml Outdated Show resolved Hide resolved
@disksing
Copy link
Contributor

There are enough reviewers so I'm unassigning myself :)

@disksing disksing removed their request for review August 17, 2021 07:13
@@ -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"
Copy link
Contributor

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.

@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use "Get" more suitable?

storeSet := make(map[uint64]bool)
peerSet := make(map[uint64]bool)
for _, id := range request.RegionIDs {
regionSet[id] = true
Copy link
Contributor

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
Copy link
Contributor

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.

@@ -0,0 +1,320 @@
package cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license.

@nolouch
Copy link
Contributor

nolouch commented Aug 17, 2021

BTW, I think your PR can split into three PRs:

  • storage
  • config
  • API

more small PRs review more quickly. And the quality is more guaranteed.

@nolouch
Copy link
Contributor

nolouch commented Aug 19, 2021

BTW, you can also supports pd-ctl command to check hot history region.

Copy link
Contributor

@Yisaer Yisaer left a 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

for {
select {
case <-ticker.C:
if h.member.IsLeader() {
Copy link
Contributor

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.

if err != nil {
return nil, err
}
hotRegionInfoCtx, hotRegionInfoCancle := context.WithCancel(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hotRegionInfoCtx, hotRegionInfoCancle := context.WithCancel(ctx)
hotRegionInfoCtx, hotRegionInfoCancel := context.WithCancel(ctx)

Comment on lines 90 to 108
// 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())
Copy link
Contributor

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).

Copy link
Contributor Author

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.

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))
Copy link
Contributor

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.

Comment on lines 118 to 135
ticker := time.NewTicker(h.pullInterval)
go func() {
defer ticker.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

select {
case <-ticker.C:
if h.member.IsLeader() {
if err := h.pullHotRegionInfo(); err != nil {
Copy link
Contributor

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.

type HotRegionStorage struct {
*kv.LeveldbKV
encryptionKeyManager *encryptionkm.KeyManager
mu sync.RWMutex
Copy link
Contributor

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
}

if err := h.LeveldbKV.Write(batch, nil); err != nil {
return errs.ErrLevelDBWrite.Wrap(err).GenWithStackByCause()
}
h.batchHotInfo = make(map[string]*statistics.HistoryHotRegion)
Copy link
Contributor

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>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2021
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
@qidi1 qidi1 mentioned this pull request Sep 14, 2021
14 tasks
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2021
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 14, 2021
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
Signed-off-by: qidi1 <1083369179@qq.com>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2021
@qidi1 qidi1 force-pushed the qidi1 branch 2 times, most recently from f73e4a4 to 64e8802 Compare September 18, 2021 01:48
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 18, 2021
Signed-off-by: qidi1 <1083369179@qq.com>
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 18, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 18, 2021
@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 27, 2021
@qidi1 qidi1 closed this Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants