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

*: show more region info in api #589

Merged
merged 8 commits into from
Mar 29, 2017
Merged

*: show more region info in api #589

merged 8 commits into from
Mar 29, 2017

Conversation

nolouch
Copy link
Contributor

@nolouch nolouch commented Mar 28, 2017

@siddontang
Copy link
Contributor

Please fix the conflict first.

return
}
region, leader, err := client.GetRegion(context.Background(), key)
prefix := fmt.Sprintf(regionKeyPrefix, key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any needs of using url.PathEscape()?

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 function PathEscape is new add in go 1.8. It is enough to deal with the key firstly with the protobuf format.

regionPrefix = "pd/api/v1/region/%s"
regionsPrefix = "pd/api/v1/regions"
regionIDPrefix = "pd/api/v1/region/id/%s"
regionKeyPrefix = "pd/api/v1/region/key/%s"
Copy link
Contributor

Choose a reason for hiding this comment

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

prefix should not contain %s here, you can format whole key explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

or use string add directly

// GetRegionInfoByKey gets regionInfo by region key from cluster.
func (c *RaftCluster) GetRegionInfoByKey(regionKey []byte) *RegionInfo {
region := c.cachedCluster.searchRegion(regionKey)
if region == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can return region here directly, no need checking nil here

// GetRegionInfoByID gets regionInfo by regionID from cluster.
func (c *RaftCluster) GetRegionInfoByID(regionID uint64) *RegionInfo {
region := c.cachedCluster.getRegion(regionID)
if region == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@siddontang
Copy link
Contributor

what does the pd-ctl output now?

@nolouch
Copy link
Contributor Author

nolouch commented Mar 29, 2017

like

{
  "id": 2,
  "end_key": "bURCOjMAAAD/APsAAAAAAAD/AGhUYWJsZTr/NwD+AAAAAAD6",
  "region_epoch": {
    "conf_ver": 9,
    "version": 2
  },
  "peers": [
    {
      "id": 44,
      "store_id": 7
    },
    {
      "id": 65,
      "store_id": 1
    },
    {
      "id": 17259,
      "store_id": 6
    }
  ],
  "Leader": null,
  "DownPeers": [],
  "PendingPeers": []
}

@siddontang
Copy link
Contributor

I think we should support protobuf string output format for start and end key later.

LGTM

@disksing
Copy link
Contributor

LGTM

@siddontang siddontang merged commit 15904a7 into master Mar 29, 2017
@siddontang siddontang deleted the shuning/add-peer-status branch March 29, 2017 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd-ctl: show more region info
3 participants