-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
server: Add table range api to http status server #20456
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,6 +279,25 @@ func (ts *HTTPHandlerTestSuite) TestRegionsAPIForClusterIndex(c *C) { | |
} | ||
} | ||
|
||
func (ts *HTTPHandlerTestSuite) TestRangesAPI(c *C) { | ||
ts.startServer(c) | ||
defer ts.stopServer(c) | ||
ts.prepareData(c) | ||
resp, err := ts.fetchStatus("/tables/tidb/t/ranges") | ||
c.Assert(err, IsNil) | ||
c.Assert(resp.StatusCode, Equals, http.StatusOK) | ||
defer resp.Body.Close() | ||
decoder := json.NewDecoder(resp.Body) | ||
|
||
var data TableRanges | ||
err = decoder.Decode(&data) | ||
c.Assert(err, IsNil) | ||
c.Assert(data.TableName, Equals, "t") | ||
c.Assert(len(data.Indices), Equals, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the indices name should also be asserted here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert added |
||
_, ok := data.Indices["PRIMARY"] | ||
c.Assert(ok, IsTrue) | ||
} | ||
|
||
func (ts *HTTPHandlerTestSuite) regionContainsTable(c *C, regionID uint64, tableID int64) bool { | ||
resp, err := ts.fetchStatus(fmt.Sprintf("/regions/%d", regionID)) | ||
c.Assert(err, IsNil) | ||
|
@@ -320,6 +339,30 @@ func (ts *HTTPHandlerTestSuite) TestListTableRegions(c *C) { | |
c.Assert(err, IsNil) | ||
} | ||
|
||
func (ts *HTTPHandlerTestSuite) TestListTableRanges(c *C) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can merge this test into TestRangesAPI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's copied from TestListTableRegions which turns out to be a test for not existing table and a partitioned table which indeed is different test. |
||
ts.startServer(c) | ||
defer ts.stopServer(c) | ||
ts.prepareData(c) | ||
// Test list table regions with error | ||
resp, err := ts.fetchStatus("/tables/fdsfds/aaa/ranges") | ||
c.Assert(err, IsNil) | ||
defer resp.Body.Close() | ||
c.Assert(resp.StatusCode, Equals, http.StatusBadRequest) | ||
|
||
resp, err = ts.fetchStatus("/tables/tidb/pt/ranges") | ||
c.Assert(err, IsNil) | ||
defer resp.Body.Close() | ||
|
||
var data []*TableRanges | ||
dec := json.NewDecoder(resp.Body) | ||
err = dec.Decode(&data) | ||
c.Assert(err, IsNil) | ||
c.Assert(len(data), Equals, 3) | ||
for i, partition := range data { | ||
c.Assert(partition.TableName, Equals, fmt.Sprintf("p%d", i)) | ||
} | ||
} | ||
|
||
func (ts *HTTPHandlerTestSuite) TestGetRegionByIDWithError(c *C) { | ||
ts.startServer(c) | ||
defer ts.stopServer(c) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same API will return different data structure responses for the partitioned tables. Can we use
[]*TableRanges{createTableRanges(meta.ID, meta.Name.String(), meta.Indices)}
to make the API users use it friendly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is the way that table regions api does, I wouldn't mind make this api consistent as long as we don't care these two similar APIs handle partition tables in different way.