server: fix http schema table_id api with partition ID (#37845)
close pingcap/tidb#37844
This commit is contained in:
@ -1201,7 +1201,13 @@ func (h schemaHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
writeData(w, data.Meta())
|
||||
return
|
||||
}
|
||||
writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID))
|
||||
// The tid maybe a partition ID of the partition-table.
|
||||
tbl, _, _ := schema.FindTableByPartitionID(int64(tid))
|
||||
if tbl == nil {
|
||||
writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID))
|
||||
return
|
||||
}
|
||||
writeData(w, tbl.Meta())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -948,6 +948,15 @@ func TestGetSchema(t *testing.T) {
|
||||
require.Equal(t, "t1", dbtbl.TableInfo.Name.L)
|
||||
require.Equal(t, "test", dbtbl.DBInfo.Name.L)
|
||||
require.Equal(t, ti, dbtbl.TableInfo)
|
||||
|
||||
resp, err = ts.fetchStatus(fmt.Sprintf("/schema?table_id=%v", ti.GetPartitionInfo().Definitions[0].ID))
|
||||
require.NoError(t, err)
|
||||
decoder = json.NewDecoder(resp.Body)
|
||||
err = decoder.Decode(&ti)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
require.Equal(t, "t1", ti.Name.L)
|
||||
require.Equal(t, ti, ti)
|
||||
}
|
||||
|
||||
func TestAllHistory(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user