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 role_name and is_learner to the returned peer info #3643

Merged
merged 14 commits into from
Jun 4, 2021

Conversation

HunDunDM
Copy link
Member

@HunDunDM HunDunDM commented Apr 26, 2021

Signed-off-by: HunDunDM hundundm@gmail.com

What problem does this PR solve?

close #3372 tidb#24293

What is changed and how it works?

  • api: add role_name and is_learner to the returned peer info

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Before

region 83693
{
  "id": 83693,
  "peers": [
    {
      "id": 83694,
      "store_id": 1
    },
    {
      "id": 83695,
      "store_id": 51
    },
    {
      "id": 83696,
      "store_id": 76
    },
    {
      "id": 104792,
      "store_id": 101,
      "role": 1
    }
  ],
  "leader": {
    "id": 83694,
    "store_id": 1
  },
  ...
}
SELECT * FROM INFORMATION_SCHEMA.TIKV_REGION_PEERS WHERE REGION_ID=83693;
+-----------+---------+----------+------------+-----------+--------+--------------+
| REGION_ID | PEER_ID | STORE_ID | IS_LEARNER | IS_LEADER | STATUS | DOWN_SECONDS |
+-----------+---------+----------+------------+-----------+--------+--------------+
|     83693 |   83694 |        1 |          0 |         1 | NORMAL |         NULL |
|     83693 |   83695 |       51 |          0 |         0 | NORMAL |         NULL |
|     83693 |   83696 |       76 |          0 |         0 | NORMAL |         NULL |
|     83693 |  104792 |      101 |          0 |         0 | NORMAL |         NULL |
+-----------+---------+----------+------------+-----------+--------+--------------+

After

region 83693                                                                                                                                   
{
  "id": 83693,
  "peers": [
    {
      "id": 83694,
      "store_id": 1,
      "role_name": "Voter"
    },
    {
      "id": 83695,
      "store_id": 51,
      "role_name": "Voter"
    },
    {
      "id": 83696,
      "store_id": 76,
      "role_name": "Voter"
    },
    {
      "id": 104792,
      "store_id": 101,
      "role": 1,
      "role_name": "Learner",
      "is_learner": true
    }
  ],
  "leader": {
    "id": 83696,
    "store_id": 76,
    "role_name": "Voter"
  },
  ...
}
SELECT * FROM INFORMATION_SCHEMA.TIKV_REGION_PEERS WHERE REGION_ID=83693;
+-----------+---------+----------+------------+-----------+--------+--------------+
| REGION_ID | PEER_ID | STORE_ID | IS_LEARNER | IS_LEADER | STATUS | DOWN_SECONDS |
+-----------+---------+----------+------------+-----------+--------+--------------+
|     83693 |   83694 |        1 |          0 |         0 | NORMAL |         NULL |
|     83693 |   83695 |       51 |          0 |         0 | NORMAL |         NULL |
|     83693 |   83696 |       76 |          0 |         1 | NORMAL |         NULL |
|     83693 |  104792 |      101 |          1 |         0 | NORMAL |         NULL |
+-----------+---------+----------+------------+-----------+--------+--------------+

Side effects

  • Possible performance regression
    • When /regions returns a large number of regions

Before

goos: darwin
goarch: amd64
pkg: github.com/tikv/pd/server/api
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkConvertToAPIRegions-4               571           1918032 ns/op
BenchmarkConvertToAPIRegions-4               584           1892309 ns/op
BenchmarkConvertToAPIRegions-4               570           1918750 ns/op
BenchmarkConvertToAPIRegions-4               592           2220998 ns/op
BenchmarkConvertToAPIRegions-4               598           1936396 ns/op

After

goos: darwin
goarch: amd64
pkg: github.com/tikv/pd/server/api
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkConvertToAPIRegions-4               368           3293800 ns/op
BenchmarkConvertToAPIRegions-4               375           3128312 ns/op
BenchmarkConvertToAPIRegions-4               368           3121975 ns/op
BenchmarkConvertToAPIRegions-4               374           3114500 ns/op
BenchmarkConvertToAPIRegions-4               373           3083650 ns/op

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix the bug that the is_learner field of the Region Peer in TiDB is incorrect.

@ti-chi-bot ti-chi-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 26, 2021
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
Signed-off-by: HunDunDM <hundundm@gmail.com>
@sonarcloud
Copy link

sonarcloud bot commented Apr 26, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
4.9% 4.9% Duplication

@codecov
Copy link

codecov bot commented Apr 26, 2021

Codecov Report

Merging #3643 (8562081) into master (c6ce285) will decrease coverage by 0.29%.
The diff coverage is 96.66%.

❗ Current head 8562081 differs from pull request most recent head 76bc290. Consider uploading reports for the commit 76bc290 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3643      +/-   ##
==========================================
- Coverage   74.97%   74.67%   -0.30%     
==========================================
  Files         244      245       +1     
  Lines       24403    24162     -241     
==========================================
- Hits        18296    18044     -252     
- Misses       4489     4504      +15     
+ Partials     1618     1614       -4     
Flag Coverage Δ
unittests 74.67% <96.66%> (-0.30%) ⬇️

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

Impacted Files Coverage Δ
server/api/region.go 65.84% <96.15%> (+1.66%) ⬆️
tests/pdctl/helper.go 100.00% <100.00%> (ø)
pkg/tempurl/tempurl.go 45.00% <0.00%> (-15.00%) ⬇️
server/tso/allocator_manager.go 74.05% <0.00%> (-9.09%) ⬇️
server/statistics/hot_cache.go 92.85% <0.00%> (-3.89%) ⬇️
server/schedule/region_splitter.go 65.71% <0.00%> (-3.81%) ⬇️
server/schedulers/random_merge.go 60.00% <0.00%> (-3.34%) ⬇️
server/core/region_tree.go 91.34% <0.00%> (-3.23%) ⬇️
server/tso/tso.go 68.71% <0.00%> (-3.20%) ⬇️
server/statistics/hot_peer_cache.go 93.18% <0.00%> (-2.67%) ⬇️
... and 48 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 57932d6...76bc290. Read the comment docs.

@HunDunDM HunDunDM marked this pull request as ready for review April 27, 2021 08:34
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 27, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 10, 2021
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JmPotato
  • disksing

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 writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 18, 2021
@HunDunDM
Copy link
Member Author

HunDunDM commented Jun 4, 2021

/merge

@ti-chi-bot
Copy link
Member

@HunDunDM: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: ffa896c

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 4, 2021
@HunDunDM HunDunDM added component/api HTTP API. needs-cherry-pick-release-5.0 The PR needs to cherry pick to release-5.0 branch. type/bugfix This PR fixes a bug. labels Jun 4, 2021
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #3743.

@HunDunDM HunDunDM deleted the fix-enum-name branch June 4, 2021 03:31
ti-chi-bot added a commit that referenced this pull request Jun 28, 2021
…3743)

* api: add role_name and is_learner to the returned peer info

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add comment

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add unit test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix lint

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* rename struct

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add comment

Signed-off-by: HunDunDM <hundundm@gmail.com>

* adjust test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* delete unnecessary pointer

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix enum name

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

Co-authored-by: HunDunDM <hundundm@gmail.com>
bufferflies pushed a commit to bufferflies/pd that referenced this pull request Jul 9, 2021
* api: add role_name and is_learner to the returned peer info

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add comment

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add unit test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix lint

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* rename struct

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add comment

Signed-off-by: HunDunDM <hundundm@gmail.com>

* adjust test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* delete unnecessary pointer

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix enum name

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
bufferflies pushed a commit to bufferflies/pd that referenced this pull request Jul 9, 2021
* api: add role_name and is_learner to the returned peer info

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add comment

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add unit test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix lint

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* rename struct

Signed-off-by: HunDunDM <hundundm@gmail.com>

* add comment

Signed-off-by: HunDunDM <hundundm@gmail.com>

* adjust test

Signed-off-by: HunDunDM <hundundm@gmail.com>

* delete unnecessary pointer

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix enum name

Signed-off-by: HunDunDM <hundundm@gmail.com>

* fix test

Signed-off-by: HunDunDM <hundundm@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/api HTTP API. needs-cherry-pick-release-5.0 The PR needs to cherry pick to release-5.0 branch. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Peer role should be string instead of number
4 participants