use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestRegionSizeCalculator method mockRegionLocator.
/**
* Makes some table with given region names.
* */
private RegionLocator mockRegionLocator(String... regionNames) throws IOException {
RegionLocator mockedTable = Mockito.mock(RegionLocator.class);
when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable"));
List<HRegionLocation> regionLocations = new ArrayList<>(regionNames.length);
when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations);
for (String regionName : regionNames) {
HRegionInfo info = Mockito.mock(HRegionInfo.class);
when(info.getRegionName()).thenReturn(regionName.getBytes());
regionLocations.add(new HRegionLocation(info, sn));
}
return mockedTable;
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestRegionSplitter method verifyBounds.
private void verifyBounds(List<byte[]> expectedBounds, TableName tableName) throws Exception {
// Get region boundaries from the cluster and verify their endpoints
final int numRegions = expectedBounds.size() - 1;
try (Table table = UTIL.getConnection().getTable(tableName);
RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) {
final List<HRegionLocation> regionInfoMap = locator.getAllRegionLocations();
assertEquals(numRegions, regionInfoMap.size());
for (HRegionLocation entry : regionInfoMap) {
final HRegionInfo regionInfo = entry.getRegionInfo();
byte[] regionStart = regionInfo.getStartKey();
byte[] regionEnd = regionInfo.getEndKey();
// This region's start key should be one of the region boundaries
int startBoundaryIndex = indexOfBytes(expectedBounds, regionStart);
assertNotSame(-1, startBoundaryIndex);
// This region's end key should be the region boundary that comes
// after the starting boundary.
byte[] expectedRegionEnd = expectedBounds.get(startBoundaryIndex + 1);
assertEquals(0, Bytes.compareTo(regionEnd, expectedRegionEnd));
}
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestServerCustomProtocol method testRowRange.
@Test
public void testRowRange() throws Throwable {
try (Table table = util.getConnection().getTable(TEST_TABLE);
RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
for (HRegionLocation e : locator.getAllRegionLocations()) {
LOG.info("Region " + e.getRegionInfo().getRegionNameAsString() + ", servername=" + e.getServerName());
}
// Here are what regions looked like on a run:
//
// test,,1355943549657.c65d4822d8bdecc033a96451f3a0f55d.
// test,bbb,1355943549661.110393b070dd1ed93441e0bc9b3ffb7e.
// test,ccc,1355943549665.c3d6d125141359cbbd2a43eaff3cdf74.
Map<byte[], String> results = ping(table, null, ROW_A);
// Should contain first region only.
assertEquals(1, results.size());
verifyRegionResults(locator, results, ROW_A);
// Test start row + empty end
results = ping(table, ROW_BC, null);
assertEquals(2, results.size());
// should contain last 2 regions
HRegionLocation loc = locator.getRegionLocation(ROW_A, true);
assertNull("Should be missing region for row aaa (prior to start row)", results.get(loc.getRegionInfo().getRegionName()));
verifyRegionResults(locator, results, ROW_B);
verifyRegionResults(locator, results, ROW_C);
// test empty start + end
results = ping(table, null, ROW_BC);
// should contain the first 2 regions
assertEquals(2, results.size());
verifyRegionResults(locator, results, ROW_A);
verifyRegionResults(locator, results, ROW_B);
loc = locator.getRegionLocation(ROW_C, true);
assertNull("Should be missing region for row ccc (past stop row)", results.get(loc.getRegionInfo().getRegionName()));
// test explicit start + end
results = ping(table, ROW_AB, ROW_BC);
// should contain first 2 regions
assertEquals(2, results.size());
verifyRegionResults(locator, results, ROW_A);
verifyRegionResults(locator, results, ROW_B);
loc = locator.getRegionLocation(ROW_C, true);
assertNull("Should be missing region for row ccc (past stop row)", results.get(loc.getRegionInfo().getRegionName()));
// test single region
results = ping(table, ROW_B, ROW_BC);
// should only contain region bbb
assertEquals(1, results.size());
verifyRegionResults(locator, results, ROW_B);
loc = locator.getRegionLocation(ROW_A, true);
assertNull("Should be missing region for row aaa (prior to start)", results.get(loc.getRegionInfo().getRegionName()));
loc = locator.getRegionLocation(ROW_C, true);
assertNull("Should be missing region for row ccc (past stop row)", results.get(loc.getRegionInfo().getRegionName()));
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class TestServerCustomProtocol method testNullReturn.
@Test
public void testNullReturn() throws Throwable {
try (Table table = util.getConnection().getTable(TEST_TABLE);
RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
Map<byte[], String> results = hello(table, "nobody", ROW_A, ROW_C);
verifyRegionResults(locator, results, null, ROW_A);
verifyRegionResults(locator, results, null, ROW_B);
verifyRegionResults(locator, results, null, ROW_C);
}
}
use of org.apache.hadoop.hbase.client.RegionLocator in project hbase by apache.
the class MasterDDLOperationHelper method reOpenAllRegions.
/**
* Reopen all regions from a table after a schema change operation.
**/
public static boolean reOpenAllRegions(final MasterProcedureEnv env, final TableName tableName, final List<HRegionInfo> regionInfoList) throws IOException {
boolean done = false;
LOG.info("Bucketing regions by region server...");
List<HRegionLocation> regionLocations = null;
Connection connection = env.getMasterServices().getConnection();
try (RegionLocator locator = connection.getRegionLocator(tableName)) {
regionLocations = locator.getAllRegionLocations();
}
// Convert List<HRegionLocation> to Map<HRegionInfo, ServerName>.
NavigableMap<HRegionInfo, ServerName> hri2Sn = new TreeMap<>();
for (HRegionLocation location : regionLocations) {
hri2Sn.put(location.getRegionInfo(), location.getServerName());
}
TreeMap<ServerName, List<HRegionInfo>> serverToRegions = Maps.newTreeMap();
List<HRegionInfo> reRegions = new ArrayList<>();
for (HRegionInfo hri : regionInfoList) {
ServerName sn = hri2Sn.get(hri);
// See HBASE-4578 for more information.
if (null == sn) {
LOG.info("Skip " + hri);
continue;
}
if (!serverToRegions.containsKey(sn)) {
LinkedList<HRegionInfo> hriList = Lists.newLinkedList();
serverToRegions.put(sn, hriList);
}
reRegions.add(hri);
serverToRegions.get(sn).add(hri);
}
LOG.info("Reopening " + reRegions.size() + " regions on " + serverToRegions.size() + " region servers.");
AssignmentManager am = env.getMasterServices().getAssignmentManager();
am.setRegionsToReopen(reRegions);
BulkReOpen bulkReopen = new BulkReOpen(env.getMasterServices(), serverToRegions, am);
while (true) {
try {
if (bulkReopen.bulkReOpen()) {
done = true;
break;
} else {
LOG.warn("Timeout before reopening all regions");
}
} catch (InterruptedException e) {
LOG.warn("Reopen was interrupted");
// Preserve the interrupt.
Thread.currentThread().interrupt();
break;
}
}
return done;
}
Aggregations