use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionMover1 method testRegionServerPort.
@Test
public void testRegionServerPort() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getHostname();
final int PORT = 16021;
Configuration conf = TEST_UTIL.getConfiguration();
String originalPort = conf.get(HConstants.REGIONSERVER_PORT);
conf.set(HConstants.REGIONSERVER_PORT, Integer.toString(PORT));
RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, conf);
assertEquals(PORT, rmBuilder.port);
if (originalPort != null) {
conf.set(HConstants.REGIONSERVER_PORT, originalPort);
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionMover3 method testRegionUnloadWithRack.
@Test
public void testRegionUnloadWithRack() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
Admin admin = TEST_UTIL.getAdmin();
Table table = TEST_UTIL.getConnection().getTable(tableName);
List<Put> puts = IntStream.range(10, 50000).mapToObj(i -> new Put(Bytes.toBytes(i)).addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i))).collect(Collectors.toList());
table.put(puts);
admin.flush(tableName);
admin.compact(tableName);
Thread.sleep(3000);
HRegionServer hRegionServer0 = cluster.getRegionServer(0);
HRegionServer hRegionServer1 = cluster.getRegionServer(1);
HRegionServer hRegionServer2 = cluster.getRegionServer(2);
int numRegions0 = hRegionServer0.getNumberOfOnlineRegions();
int numRegions1 = hRegionServer1.getNumberOfOnlineRegions();
int numRegions2 = hRegionServer2.getNumberOfOnlineRegions();
Assert.assertTrue(numRegions0 >= 3);
Assert.assertTrue(numRegions1 >= 3);
Assert.assertTrue(numRegions2 >= 3);
int totalRegions = numRegions0 + numRegions1 + numRegions2;
// source RS: rs0
String sourceRSName = rs0.getAddress().toString();
// move all regions from rs1 to rs0
for (HRegion region : hRegionServer1.getRegions()) {
TEST_UTIL.getAdmin().move(region.getRegionInfo().getEncodedNameAsBytes(), rs0);
}
TEST_UTIL.waitFor(5000, () -> {
int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions();
int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions();
return newNumRegions1 == 0 && newNumRegions0 == (numRegions0 + numRegions1);
});
// regionMover obj on rs0. While unloading regions from rs0
// with default rackManager, which resolves "/default-rack" for each server, no region
// is moved while using unloadFromRack() as all rs belong to same rack.
RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(sourceRSName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
try (RegionMover regionMover = rmBuilder.build()) {
regionMover.unloadFromRack();
int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions();
int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions();
int newNumRegions2 = hRegionServer2.getNumberOfOnlineRegions();
Assert.assertEquals(0, newNumRegions1);
Assert.assertEquals(totalRegions, newNumRegions0 + newNumRegions2);
}
// use custom rackManager, which resolves "rack-1" for rs0 and rs1,
// while "rack-2" for rs2. Hence, unloadFromRack() from rs0 should move all
// regions that belong to rs0 to rs2 only, and nothing should be moved to rs1
// as rs0 and rs1 belong to same rack.
rmBuilder.rackManager(new MockRackManager());
try (RegionMover regionMover = rmBuilder.build()) {
regionMover.unloadFromRack();
int newNumRegions0 = hRegionServer0.getNumberOfOnlineRegions();
int newNumRegions1 = hRegionServer1.getNumberOfOnlineRegions();
int newNumRegions2 = hRegionServer2.getNumberOfOnlineRegions();
Assert.assertEquals(0, newNumRegions0);
Assert.assertEquals(0, newNumRegions1);
Assert.assertEquals(totalRegions, newNumRegions2);
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionMover1 method testLoadMetaRegion.
/**
* UT for HBASE-21746
*/
@Test
public void testLoadMetaRegion() throws Exception {
HRegionServer rsWithMeta = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(rs -> rs.getRegions(TableName.META_TABLE_NAME).size() > 0).findFirst().get();
int onlineRegions = rsWithMeta.getNumberOfOnlineRegions();
String rsName = rsWithMeta.getServerName().getAddress().toString();
try (RegionMover rm = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).build()) {
LOG.info("Unloading " + rsWithMeta.getServerName());
rm.unload();
assertEquals(0, rsWithMeta.getNumberOfOnlineRegions());
LOG.info("Loading " + rsWithMeta.getServerName());
rm.load();
assertEquals(onlineRegions, rsWithMeta.getNumberOfOnlineRegions());
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionMover1 method testDecomServerExclusion.
@Test
public void testDecomServerExclusion() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HRegionServer excludeServer = cluster.getRegionServer(0);
List<HRegion> regions = excludeServer.getRegions();
int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
TEST_UTIL.getAdmin().decommissionRegionServers(Collections.singletonList(excludeServer.getServerName()), false);
waitForServerDecom(excludeServer);
HRegionServer sourceRegionServer = cluster.getRegionServer(1);
String rsName = sourceRegionServer.getServerName().getHostname();
int port = sourceRegionServer.getServerName().getPort();
String hostname = rsName + ":" + Integer.toString(port);
RegionMoverBuilder rmBuilder = new RegionMoverBuilder(hostname, TEST_UTIL.getConfiguration()).ack(false);
int targetServerRegions = cluster.getRegionServer(2).getRegions().size();
int sourceServerRegions = sourceRegionServer.getRegions().size();
try (RegionMover regionMover = rmBuilder.build()) {
Assert.assertTrue(regionMover.unload());
LOG.info("Unloading {}", hostname);
assertEquals(0, sourceRegionServer.getNumberOfOnlineRegions());
assertEquals(regionsExcludeServer, cluster.getRegionServer(0).getNumberOfOnlineRegions());
LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions());
List<HRegion> regionList = cluster.getRegionServer(0).getRegions();
int index = 0;
for (HRegion hRegion : regionList) {
Assert.assertEquals(hRegion, regions.get(index++));
}
Assert.assertEquals(targetServerRegions + sourceServerRegions, cluster.getRegionServer(2).getNumberOfOnlineRegions());
Assert.assertTrue(regionMover.load());
}
TEST_UTIL.getAdmin().recommissionRegionServer(excludeServer.getServerName(), Collections.emptyList());
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestAdmin2 method testGetRegionInfo.
/**
* TestCase for HBASE-21355
*/
@Test
public void testGetRegionInfo() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
Table table = TEST_UTIL.createTable(tableName, Bytes.toBytes("f"));
for (int i = 0; i < 100; i++) {
table.put(new Put(Bytes.toBytes(i)).addColumn(Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes(i)));
}
ADMIN.flush(tableName);
HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(table.getName());
List<HRegion> regions = rs.getRegions(tableName);
Assert.assertEquals(1, regions.size());
HRegion region = regions.get(0);
byte[] regionName = region.getRegionInfo().getRegionName();
HStore store = region.getStore(Bytes.toBytes("f"));
long expectedStoreFilesSize = store.getStorefilesSize();
Assert.assertNotNull(store);
Assert.assertEquals(expectedStoreFilesSize, store.getSize());
for (int i = 0; i < 10; i++) {
RegionInfo ri = ProtobufUtil.toRegionInfo(TEST_UTIL.getAsyncConnection().getRegionServerAdmin(rs.getServerName()).getRegionInfo(RequestConverter.buildGetRegionInfoRequest(regionName)).get().getRegionInfo());
Assert.assertEquals(region.getRegionInfo(), ri);
// Make sure that the store size is still the actual file system's store size.
Assert.assertEquals(expectedStoreFilesSize, store.getSize());
}
// Test querying using the encoded name only. When encoded name passed,
// and the target server is the Master, we return the full region name.
// Convenience.
ServerName sn = null;
try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
sn = admin.getMaster();
}
RegionInfo ri = region.getRegionInfo();
testGetWithRegionName(sn, ri, ri.getEncodedNameAsBytes());
testGetWithRegionName(sn, ri, ri.getRegionName());
// Try querying meta encoded name.
ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
testGetWithRegionName(sn, ri, ri.getEncodedNameAsBytes());
testGetWithRegionName(sn, ri, ri.getRegionName());
}
Aggregations