HBASE-24944 Remove MetaTableAccessor.getTableRegionsAndLocations in hbase-rest module (#2302)

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
Duo Zhang 2020-08-25 16:18:42 +08:00 committed by GitHub
parent 1220a8775c
commit 6b0707f541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 15 deletions

View File

@ -19,6 +19,8 @@
package org.apache.hadoop.hbase.rest;
import java.io.IOException;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.CacheControl;
@ -26,19 +28,16 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.rest.model.TableInfoModel;
import org.apache.hadoop.hbase.rest.model.TableRegionModel;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -78,15 +77,15 @@ public class RegionsResource extends ResourceBase {
TableName tableName = TableName.valueOf(tableResource.getName());
TableInfoModel model = new TableInfoModel(tableName.getNameAsString());
Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor
.getTableRegionsAndLocations(connection, tableName);
connection.close();
for (Pair<RegionInfo,ServerName> e: regions) {
RegionInfo hri = e.getFirst();
ServerName addr = e.getSecond();
model.add(
new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(),
List<HRegionLocation> locs;
try (Connection connection = ConnectionFactory.createConnection(servlet.getConfiguration());
RegionLocator locator = connection.getRegionLocator(tableName)) {
locs = locator.getAllRegionLocations();
}
for (HRegionLocation loc : locs) {
RegionInfo hri = loc.getRegion();
ServerName addr = loc.getServerName();
model.add(new TableRegionModel(tableName.getNameAsString(), hri.getRegionId(),
hri.getStartKey(), hri.getEndKey(), addr.getAddress().toString()));
}
ResponseBuilder response = Response.ok(model);