Skip to content

Commit

Permalink
pd-ctl: return full region information for /region api (#1252)
Browse files Browse the repository at this point in the history
  • Loading branch information
liukun4515 authored and disksing committed Sep 25, 2018
1 parent b9caf04 commit a87733a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 2 additions & 3 deletions server/api/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ func (h *regionsHandler) GetAll(w http.ResponseWriter, r *http.Request) {
h.rd.JSON(w, http.StatusInternalServerError, server.ErrNotBootstrapped.Error())
return
}

regions := cluster.GetMetaRegions()
regions := cluster.GetRegions()
regionInfos := make([]*regionInfo, len(regions))
for i, r := range regions {
regionInfos[i] = newRegionInfo(core.NewRegionInfo(r, nil))
regionInfos[i] = newRegionInfo(r)
}
regionsInfo := &regionsInfo{
Count: len(regions),
Expand Down
26 changes: 26 additions & 0 deletions server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ func (s *testRegionSuite) TestRegion(c *C) {
c.Assert(r2, DeepEquals, newRegionInfo(r))
}

func (s *testRegionSuite) TestRegions(c *C) {
rs := []*core.RegionInfo{
newTestRegionInfo(2, 1, []byte("a"), []byte("b")),
newTestRegionInfo(3, 1, []byte("b"), []byte("c")),
newTestRegionInfo(4, 2, []byte("c"), []byte("d")),
}
regions := make([]*regionInfo, 0, len(rs))
for _, r := range rs {
regions = append(regions, newRegionInfo(r))
mustRegionHeartbeat(c, s.svr, r)
}
url := fmt.Sprintf("%s/regions", s.urlPrefix)
regionsInfo := &regionsInfo{}
err := readJSONWithURL(url, regionsInfo)
c.Assert(err, IsNil)
c.Assert(regionsInfo.Count, Equals, len(regions))
sort.Slice(regionsInfo.Regions, func(i, j int) bool {
return regionsInfo.Regions[i].ID < regionsInfo.Regions[j].ID
})
for i, r := range regionsInfo.Regions {
c.Assert(r.ID, Equals, regions[i].ID)
c.Assert(r.ApproximateSize, Equals, regions[i].ApproximateSize)
c.Assert(r.ApproximateKeys, Equals, regions[i].ApproximateKeys)
}
}

func (s *testRegionSuite) TestStoreRegions(c *C) {
r1 := newTestRegionInfo(2, 1, []byte("a"), []byte("b"))
r2 := newTestRegionInfo(3, 1, []byte("b"), []byte("c"))
Expand Down

0 comments on commit a87733a

Please sign in to comment.