use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestRegionMover1 method testDecomServerExclusionWithAck.
@Test
public void testDecomServerExclusionWithAck() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HRegionServer excludeServer = cluster.getRegionServer(1);
List<HRegion> regions = excludeServer.getRegions();
int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
TEST_UTIL.getAdmin().decommissionRegionServers(Collections.singletonList(excludeServer.getServerName()), false);
waitForServerDecom(excludeServer);
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getHostname();
int port = regionServer.getServerName().getPort();
String hostname = rsName + ":" + Integer.toString(port);
RegionMoverBuilder rmBuilder = new RegionMoverBuilder(hostname, TEST_UTIL.getConfiguration()).ack(true);
int targetServerRegions = cluster.getRegionServer(2).getRegions().size();
int sourceServerRegions = regionServer.getRegions().size();
try (RegionMover regionMover = rmBuilder.build()) {
Assert.assertTrue(regionMover.unload());
LOG.info("Unloading {}", hostname);
assertEquals(0, regionServer.getNumberOfOnlineRegions());
assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions());
LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions());
List<HRegion> regionList = cluster.getRegionServer(1).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.SingleProcessHBaseCluster in project hbase by apache.
the class TestRegionMover1 method testDesignatedFile.
@Test
public void testDesignatedFile() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
File designatedFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "designated_file");
HRegionServer designatedServer = cluster.getRegionServer(0);
try (FileWriter fos = new FileWriter(designatedFile)) {
String designatedHostname = designatedServer.getServerName().getHostname();
int designatedServerPort = designatedServer.getServerName().getPort();
String excludeServerName = designatedHostname + ":" + designatedServerPort;
fos.write(excludeServerName);
}
int regionsInDesignatedServer = designatedServer.getNumberOfOnlineRegions();
HRegionServer regionServer = cluster.getRegionServer(1);
String rsName = regionServer.getServerName().getHostname();
int port = regionServer.getServerName().getPort();
String rs = rsName + ":" + port;
int regionsInRegionServer = regionServer.getNumberOfOnlineRegions();
RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration()).designatedFile(designatedFile.getCanonicalPath());
try (RegionMover rm = rmBuilder.build()) {
LOG.debug("Unloading {} regions", rs);
rm.unload();
assertEquals(0, regionServer.getNumberOfOnlineRegions());
assertEquals(regionsInDesignatedServer + regionsInRegionServer, designatedServer.getNumberOfOnlineRegions());
LOG.debug("Before:{} After:{}", regionsInDesignatedServer, designatedServer.getNumberOfOnlineRegions());
}
}
use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestRegionMover1 method testExclude.
/**
* To test that we successfully exclude a server from the unloading process We test for the number
* of regions on Excluded server and also test that regions are unloaded successfully
*/
@Test
public void testExclude() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file");
FileWriter fos = new FileWriter(excludeFile);
HRegionServer excludeServer = cluster.getRegionServer(1);
String excludeHostname = excludeServer.getServerName().getHostname();
int excludeServerPort = excludeServer.getServerName().getPort();
int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions();
String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort);
fos.write(excludeServerName);
fos.close();
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getHostname();
int port = regionServer.getServerName().getPort();
String rs = rsName + ":" + Integer.toString(port);
RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration()).ack(true).excludeFile(excludeFile.getCanonicalPath());
try (RegionMover rm = rmBuilder.build()) {
rm.unload();
LOG.info("Unloading " + rs);
assertEquals(0, regionServer.getNumberOfOnlineRegions());
assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions());
LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions());
}
}
use of org.apache.hadoop.hbase.SingleProcessHBaseCluster 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.SingleProcessHBaseCluster 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);
}
}
Aggregations