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 new api to get the distribution of regions #9090

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bufferflies
Copy link
Contributor

What problem does this PR solve?

Issue Number: Close #9089

What is changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test

Code changes

Side effects

Related changes

Release note

None.

Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 21, 2025
@bufferflies bufferflies force-pushed the distribution-api branch 2 times, most recently from 84099f2 to 66d6daa Compare February 25, 2025 08:57
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 25, 2025
Signed-off-by: 童剑 <[email protected]>
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 75.91241% with 33 lines in your changes missing coverage. Please review.

Project coverage is 76.30%. Comparing base (2bbeb9c) to head (dee04ba).
Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9090      +/-   ##
==========================================
+ Coverage   76.25%   76.30%   +0.04%     
==========================================
  Files         468      468              
  Lines       71695    71850     +155     
==========================================
+ Hits        54673    54823     +150     
+ Misses      13610    13595      -15     
- Partials     3412     3432      +20     
Flag Coverage Δ
unittests 76.30% <75.91%> (+0.04%) ⬆️

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bufferflies bufferflies marked this pull request as ready for review February 26, 2025 07:40
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 26, 2025
Signed-off-by: 童剑 <[email protected]>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Feb 27, 2025
Copy link
Contributor

ti-chi-bot bot commented Feb 27, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lhy1024

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

ti-chi-bot bot commented Feb 27, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-02-27 07:28:14.407076522 +0000 UTC m=+513642.360234788: ☑️ agreed by lhy1024.

@ti-chi-bot ti-chi-bot bot added the approved label Feb 27, 2025
@@ -38,6 +38,7 @@ const (
store = "/pd/api/v1/store"
Stores = "/pd/api/v1/stores"
StatsRegion = "/pd/api/v1/stats/region"
DistributionRegion = "/pd/api/v1/distributions/region"
Copy link
Member

Choose a reason for hiding this comment

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

How about "/pd/api/v1/regions/distribution"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keep the style with the "/pd/api/v1/stats/region"

@@ -2169,8 +2169,12 @@ func (c *RaftCluster) PutMetaCluster(meta *metapb.Cluster) error {
}

// GetRegionStatsByRange returns region statistics from cluster.
func (c *RaftCluster) GetRegionStatsByRange(startKey, endKey []byte) *statistics.RegionStats {
return statistics.GetRegionStats(c.ScanRegions(startKey, endKey, -1))
// if useHotFlow is true, the hot region statistics will be returned.
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the new sql grama "show table t1 partition(p0,p1)" will use it.

if useHotFlow {
return statistics.GetRegionStats(c.ScanRegions(startKey, endKey, -1), c, opts...)
}
return statistics.GetRegionStats(c.ScanRegions(startKey, endKey, -1), nil, opts...)
Copy link
Member

Choose a reason for hiding this comment

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

need pagination

// @Produce json
// @Success 200 {object} statistics.RegionStats
// @Router /distributions/region [get]
func (h *statsHandler) GetRegionDistributions(w http.ResponseWriter, r *http.Request) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this API is almost the same as GetRegionStatusByKeyRange, why not extend the existing API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine, but this api is already complex. It needs to consider three scenes such as:

  1. the informations of the regions.
  2. only needs the region count for spilt regions SQL or Tiflash.
  3. the informations of the regions includes the hot statistics

StoreLeaderKeys: make(map[uint64]int64),
StorePeerSize: make(map[uint64]int64),
StorePeerKeys: make(map[uint64]int64),
StoreLeaderCount: make(map[uint64]int),
Copy link
Member

Choose a reason for hiding this comment

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

Is there any OOM risk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The length of the map is mostly small(less than 200). The API is primarily used by DBAs with a low frequent usage rate.

Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api: add new api to expose the distribution of the regions in different instance
3 participants