Java Code Examples for org.apache.hadoop.hbase.regionserver.HRegionServer#getNumberOfOnlineRegions()
The following examples show how to use
org.apache.hadoop.hbase.regionserver.HRegionServer#getNumberOfOnlineRegions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testWithAck() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getAddress().toString(); int numRegions = regionServer.getNumberOfOnlineRegions(); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8); try (RegionMover rm = rmBuilder.build()) { LOG.info("Unloading " + regionServer.getServerName()); rm.unload(); assertEquals(0, regionServer.getNumberOfOnlineRegions()); LOG.info("Successfully Unloaded\nNow Loading"); rm.load(); assertEquals(numRegions, regionServer.getNumberOfOnlineRegions()); // Repeat the same load. It should be very fast because all regions are already moved. rm.load(); } }
Example 2
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 6 votes |
/** * 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()); } }
Example 3
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 5 votes |
/** * Test to unload a regionserver first and then load it using no Ack mode. */ @Test public void testWithoutAck() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getAddress().toString(); int numRegions = regionServer.getNumberOfOnlineRegions(); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(false); try (RegionMover rm = rmBuilder.build()) { LOG.info("Unloading " + regionServer.getServerName()); rm.unload(); TEST_UTIL.waitFor(30000, 1000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return regionServer.getNumberOfOnlineRegions() == 0; } }); LOG.info("Successfully Unloaded\nNow Loading"); rm.load(); // In UT we only have 10 regions so it is not likely to fail, so here we check for all // regions, in the real production this may not be true. TEST_UTIL.waitFor(30000, 1000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return regionServer.getNumberOfOnlineRegions() == numRegions; } }); } }
Example 4
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 5 votes |
/** * 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 { MiniHBaseCluster 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()); } }
Example 5
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDecomServerExclusionWithAck() throws Exception { MiniHBaseCluster 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()); }
Example 6
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDecomServerExclusion() throws Exception { MiniHBaseCluster 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()); }