HBASE-5613 ThriftServer getTableRegions does not return serverName and port (Scott Chen)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1304602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
929113dfab
commit
26b2950bc7
|
@ -27,6 +27,7 @@ import java.net.UnknownHostException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -50,6 +51,8 @@ import org.apache.hadoop.hbase.HConstants;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
import org.apache.hadoop.hbase.HRegionInfo;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
import org.apache.hadoop.hbase.KeyValue;
|
||||||
|
import org.apache.hadoop.hbase.ServerName;
|
||||||
|
import org.apache.hadoop.hbase.TableNotFoundException;
|
||||||
import org.apache.hadoop.hbase.client.Delete;
|
import org.apache.hadoop.hbase.client.Delete;
|
||||||
import org.apache.hadoop.hbase.client.Get;
|
import org.apache.hadoop.hbase.client.Get;
|
||||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||||
|
@ -584,22 +587,29 @@ public class ThriftServerRunner implements Runnable {
|
||||||
public List<TRegionInfo> getTableRegions(ByteBuffer tableName)
|
public List<TRegionInfo> getTableRegions(ByteBuffer tableName)
|
||||||
throws IOError {
|
throws IOError {
|
||||||
try {
|
try {
|
||||||
List<HRegionInfo> hris =
|
HTable table = getTable(tableName);
|
||||||
this.getHBaseAdmin().getTableRegions(getBytes(tableName));
|
Map<HRegionInfo, ServerName> regionLocations =
|
||||||
List<TRegionInfo> regions = new ArrayList<TRegionInfo>();
|
table.getRegionLocations();
|
||||||
|
List<TRegionInfo> results = new ArrayList<TRegionInfo>();
|
||||||
if (hris != null) {
|
for (Map.Entry<HRegionInfo, ServerName> entry :
|
||||||
for (HRegionInfo regionInfo : hris){
|
regionLocations.entrySet()) {
|
||||||
|
HRegionInfo info = entry.getKey();
|
||||||
|
ServerName serverName = entry.getValue();
|
||||||
TRegionInfo region = new TRegionInfo();
|
TRegionInfo region = new TRegionInfo();
|
||||||
region.startKey = ByteBuffer.wrap(regionInfo.getStartKey());
|
region.serverName = ByteBuffer.wrap(
|
||||||
region.endKey = ByteBuffer.wrap(regionInfo.getEndKey());
|
Bytes.toBytes(serverName.getHostname()));
|
||||||
region.id = regionInfo.getRegionId();
|
region.port = serverName.getPort();
|
||||||
region.name = ByteBuffer.wrap(regionInfo.getRegionName());
|
region.startKey = ByteBuffer.wrap(info.getStartKey());
|
||||||
region.version = regionInfo.getVersion();
|
region.endKey = ByteBuffer.wrap(info.getEndKey());
|
||||||
regions.add(region);
|
region.id = info.getRegionId();
|
||||||
|
region.name = ByteBuffer.wrap(info.getRegionName());
|
||||||
|
region.version = info.getVersion();
|
||||||
|
results.add(region);
|
||||||
}
|
}
|
||||||
}
|
return results;
|
||||||
return regions;
|
} catch (TableNotFoundException e) {
|
||||||
|
// Return empty list for non-existing table
|
||||||
|
return Collections.emptyList();
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
LOG.warn(e.getMessage(), e);
|
LOG.warn(e.getMessage(), e);
|
||||||
throw new IOError(e.getMessage());
|
throw new IOError(e.getMessage());
|
||||||
|
|
|
@ -29,6 +29,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HConstants;
|
import org.apache.hadoop.hbase.HConstants;
|
||||||
|
@ -60,6 +62,7 @@ import org.junit.experimental.categories.Category;
|
||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestThriftServer {
|
public class TestThriftServer {
|
||||||
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
||||||
|
private static final Log LOG = LogFactory.getLog(TestThriftServer.class);
|
||||||
protected static final int MAXVERSIONS = 3;
|
protected static final int MAXVERSIONS = 3;
|
||||||
|
|
||||||
private static ByteBuffer asByteBuffer(String i) {
|
private static ByteBuffer asByteBuffer(String i) {
|
||||||
|
@ -434,10 +437,14 @@ public class TestThriftServer {
|
||||||
|
|
||||||
public static void doTestGetTableRegions(Hbase.Iface handler)
|
public static void doTestGetTableRegions(Hbase.Iface handler)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assertEquals(handler.getTableNames().size(), 0);
|
||||||
handler.createTable(tableAname, getColumnDescriptors());
|
handler.createTable(tableAname, getColumnDescriptors());
|
||||||
int regionCount = handler.getTableRegions(tableAname).size();
|
assertEquals(handler.getTableNames().size(), 1);
|
||||||
|
List<TRegionInfo> regions = handler.getTableRegions(tableAname);
|
||||||
|
int regionCount = regions.size();
|
||||||
assertEquals("empty table should have only 1 region, " +
|
assertEquals("empty table should have only 1 region, " +
|
||||||
"but found " + regionCount, regionCount, 1);
|
"but found " + regionCount, regionCount, 1);
|
||||||
|
LOG.info("Region found:" + regions.get(0));
|
||||||
handler.disableTable(tableAname);
|
handler.disableTable(tableAname);
|
||||||
handler.deleteTable(tableAname);
|
handler.deleteTable(tableAname);
|
||||||
regionCount = handler.getTableRegions(tableAname).size();
|
regionCount = handler.getTableRegions(tableAname).size();
|
||||||
|
|
Loading…
Reference in New Issue