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.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.HTableDescriptor;
|
||||
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.Get;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
|
@ -359,7 +362,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
tserver.getClass().getName());
|
||||
}
|
||||
|
||||
// login the server principal (if using secure Hadoop)
|
||||
// login the server principal (if using secure Hadoop)
|
||||
if (User.isSecurityEnabled() && User.isHBaseSecurityEnabled(conf)) {
|
||||
String machineName = Strings.domainNamePointerToHostName(
|
||||
DNS.getDefaultHost(conf.get("hbase.thrift.dns.interface", "default"),
|
||||
|
@ -385,7 +388,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
String bindAddressStr = conf.get(BIND_CONF_KEY, DEFAULT_BIND_ADDR);
|
||||
return InetAddress.getByName(bindAddressStr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The HBaseHandler is a glue object that connects Thrift RPC calls to the
|
||||
* HBase client API primarily defined in the HBaseAdmin and HTable objects.
|
||||
|
@ -495,7 +498,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
this.conf = c;
|
||||
scannerMap = new HashMap<Integer, ResultScanner>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain HBaseAdmin. Creates the instance if it is not already created.
|
||||
*/
|
||||
|
@ -508,7 +511,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
}
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableTable(ByteBuffer tableName) throws IOError {
|
||||
|
@ -583,23 +586,30 @@ public class ThriftServerRunner implements Runnable {
|
|||
@Override
|
||||
public List<TRegionInfo> getTableRegions(ByteBuffer tableName)
|
||||
throws IOError {
|
||||
try{
|
||||
List<HRegionInfo> hris =
|
||||
this.getHBaseAdmin().getTableRegions(getBytes(tableName));
|
||||
List<TRegionInfo> regions = new ArrayList<TRegionInfo>();
|
||||
|
||||
if (hris != null) {
|
||||
for (HRegionInfo regionInfo : hris){
|
||||
TRegionInfo region = new TRegionInfo();
|
||||
region.startKey = ByteBuffer.wrap(regionInfo.getStartKey());
|
||||
region.endKey = ByteBuffer.wrap(regionInfo.getEndKey());
|
||||
region.id = regionInfo.getRegionId();
|
||||
region.name = ByteBuffer.wrap(regionInfo.getRegionName());
|
||||
region.version = regionInfo.getVersion();
|
||||
regions.add(region);
|
||||
}
|
||||
try {
|
||||
HTable table = getTable(tableName);
|
||||
Map<HRegionInfo, ServerName> regionLocations =
|
||||
table.getRegionLocations();
|
||||
List<TRegionInfo> results = new ArrayList<TRegionInfo>();
|
||||
for (Map.Entry<HRegionInfo, ServerName> entry :
|
||||
regionLocations.entrySet()) {
|
||||
HRegionInfo info = entry.getKey();
|
||||
ServerName serverName = entry.getValue();
|
||||
TRegionInfo region = new TRegionInfo();
|
||||
region.serverName = ByteBuffer.wrap(
|
||||
Bytes.toBytes(serverName.getHostname()));
|
||||
region.port = serverName.getPort();
|
||||
region.startKey = ByteBuffer.wrap(info.getStartKey());
|
||||
region.endKey = ByteBuffer.wrap(info.getEndKey());
|
||||
region.id = info.getRegionId();
|
||||
region.name = ByteBuffer.wrap(info.getRegionName());
|
||||
region.version = info.getVersion();
|
||||
results.add(region);
|
||||
}
|
||||
return regions;
|
||||
return results;
|
||||
} catch (TableNotFoundException e) {
|
||||
// Return empty list for non-existing table
|
||||
return Collections.emptyList();
|
||||
} catch (IOException e){
|
||||
LOG.warn(e.getMessage(), e);
|
||||
throw new IOError(e.getMessage());
|
||||
|
@ -928,7 +938,7 @@ public class ThriftServerRunner implements Runnable {
|
|||
|
||||
@Override
|
||||
public void mutateRow(ByteBuffer tableName, ByteBuffer row,
|
||||
List<Mutation> mutations, Map<ByteBuffer, ByteBuffer> attributes)
|
||||
List<Mutation> mutations, Map<ByteBuffer, ByteBuffer> attributes)
|
||||
throws IOError, IllegalArgument {
|
||||
mutateRowTs(tableName, row, mutations, HConstants.LATEST_TIMESTAMP,
|
||||
attributes);
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
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.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
|
@ -60,6 +62,7 @@ import org.junit.experimental.categories.Category;
|
|||
@Category(MediumTests.class)
|
||||
public class TestThriftServer {
|
||||
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
||||
private static final Log LOG = LogFactory.getLog(TestThriftServer.class);
|
||||
protected static final int MAXVERSIONS = 3;
|
||||
|
||||
private static ByteBuffer asByteBuffer(String i) {
|
||||
|
@ -162,13 +165,13 @@ public class TestThriftServer {
|
|||
}
|
||||
|
||||
private static void verifyMetrics(ThriftMetrics metrics, String name, int expectValue)
|
||||
throws Exception {
|
||||
MetricsContext context = MetricsUtil.getContext(
|
||||
ThriftMetrics.CONTEXT_NAME);
|
||||
metrics.doUpdates(context);
|
||||
OutputRecord record = context.getAllRecords().get(
|
||||
ThriftMetrics.CONTEXT_NAME).iterator().next();
|
||||
assertEquals(expectValue, record.getMetric(name).intValue());
|
||||
throws Exception {
|
||||
MetricsContext context = MetricsUtil.getContext(
|
||||
ThriftMetrics.CONTEXT_NAME);
|
||||
metrics.doUpdates(context);
|
||||
OutputRecord record = context.getAllRecords().get(
|
||||
ThriftMetrics.CONTEXT_NAME).iterator().next();
|
||||
assertEquals(expectValue, record.getMetric(name).intValue());
|
||||
}
|
||||
|
||||
public static void createTestTables(Hbase.Iface handler) throws Exception {
|
||||
|
@ -246,7 +249,7 @@ public class TestThriftServer {
|
|||
TRowResult rowResult2 = handler.getRow(tableAname, rowBname, null).get(0);
|
||||
assertEquals(rowBname, rowResult2.row);
|
||||
assertEquals(valueCname, rowResult2.columns.get(columnAname).value);
|
||||
assertEquals(valueDname, rowResult2.columns.get(columnBname).value);
|
||||
assertEquals(valueDname, rowResult2.columns.get(columnBname).value);
|
||||
|
||||
// Apply some deletes
|
||||
handler.deleteAll(tableAname, rowAname, columnBname, null);
|
||||
|
@ -434,26 +437,30 @@ public class TestThriftServer {
|
|||
|
||||
public static void doTestGetTableRegions(Hbase.Iface handler)
|
||||
throws Exception {
|
||||
assertEquals(handler.getTableNames().size(), 0);
|
||||
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, " +
|
||||
"but found " + regionCount, regionCount, 1);
|
||||
LOG.info("Region found:" + regions.get(0));
|
||||
handler.disableTable(tableAname);
|
||||
handler.deleteTable(tableAname);
|
||||
regionCount = handler.getTableRegions(tableAname).size();
|
||||
assertEquals("non-existing table should have 0 region, " +
|
||||
"but found " + regionCount, regionCount, 0);
|
||||
}
|
||||
|
||||
|
||||
public void doTestFilterRegistration() throws Exception {
|
||||
Configuration conf = UTIL.getConfiguration();
|
||||
|
||||
|
||||
conf.set("hbase.thrift.filters", "MyFilter:filterclass");
|
||||
|
||||
ThriftServerRunner.registerFilters(conf);
|
||||
|
||||
|
||||
Map<String, String> registeredFilters = ParseFilter.getAllFilters();
|
||||
|
||||
|
||||
assertEquals("filterclass", registeredFilters.get("MyFilter"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue