Java Code Examples for org.apache.hadoop.hbase.regionserver.HRegionServer#isStopped()
The following examples show how to use
org.apache.hadoop.hbase.regionserver.HRegionServer#isStopped() .
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: HBaseTestingUtility.java From hbase with Apache License 2.0 | 6 votes |
/** * Make sure that at least the specified number of region servers * are running. We don't count the ones that are currently stopping or are * stopped. * @param num minimum number of region servers that should be running * @return true if we started some servers * @throws IOException */ public boolean ensureSomeNonStoppedRegionServersAvailable(final int num) throws IOException { boolean startedServer = ensureSomeRegionServersAvailable(num); int nonStoppedServers = 0; for (JVMClusterUtil.RegionServerThread rst : getMiniHBaseCluster().getRegionServerThreads()) { HRegionServer hrs = rst.getRegionServer(); if (hrs.isStopping() || hrs.isStopped()) { LOG.info("A region server is stopped or stopping:"+hrs); } else { nonStoppedServers++; } } for (int i=nonStoppedServers; i<num; ++i) { LOG.info("Started new server=" + getMiniHBaseCluster().startRegionServer()); startedServer = true; } return startedServer; }
Example 2
Source File: MiniHBaseCluster.java From hbase with Apache License 2.0 | 5 votes |
/** * Get the location of the specified region * @param regionName Name of the region in bytes * @return Index into List of {@link MiniHBaseCluster#getRegionServerThreads()} * of HRS carrying hbase:meta. Returns -1 if none found. */ public int getServerWith(byte[] regionName) { int index = 0; for (JVMClusterUtil.RegionServerThread rst: getRegionServerThreads()) { HRegionServer hrs = rst.getRegionServer(); if (!hrs.isStopped()) { Region region = hrs.getOnlineRegion(regionName); if (region != null) { return index; } } index++; } return -1; }
Example 3
Source File: TestHBCKSCP.java From hbase with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { // we are about to do one for it? MiniHBaseCluster cluster = this.util.getHBaseCluster(); // Assert that we have three RegionServers. Test depends on there being multiple. assertEquals(RS_COUNT, cluster.getLiveRegionServerThreads().size()); int count; try (Table table = createTable(TableName.valueOf(this.name.getMethodName()))) { // Load the table with a bit of data so some logs to split and some edits in each region. this.util.loadTable(table, HBaseTestingUtility.COLUMNS[0]); count = util.countRows(table); } assertTrue("expected some rows", count > 0); // Make the test easier by not working on server hosting meta... // Find another RS. Purge it from Master memory w/o running SCP (if // SCP runs, it will clear entries from hbase:meta which frustrates // our attempt at manufacturing 'Unknown Servers' condition). int metaIndex = this.util.getMiniHBaseCluster().getServerWithMeta(); int rsIndex = (metaIndex + 1) % RS_COUNT; ServerName rsServerName = cluster.getRegionServer(rsIndex).getServerName(); HMaster master = cluster.getMaster(); // Get a Region that is on the server. RegionInfo rsRI = master.getAssignmentManager().getRegionsOnServer(rsServerName).get(0); Result r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName()); // Assert region is OPEN. assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER))); ServerName serverName = CatalogFamilyFormat.getServerName(r, 0); assertEquals(rsServerName, serverName); // moveFrom adds to dead servers and adds it to processing list only we will // not be processing this server 'normally'. Remove it from processing by // calling 'finish' and then remove it from dead servers so rsServerName // becomes an 'Unknown Server' even though it is still around. master.getServerManager().moveFromOnlineToDeadServers(rsServerName); master.getServerManager().getDeadServers().finish(rsServerName); master.getServerManager().getDeadServers().removeDeadServer(rsServerName); master.getAssignmentManager().getRegionStates().removeServer(rsServerName); // Kill the server. Nothing should happen since an 'Unknown Server' as far // as the Master is concerned; i.e. no SCP. LOG.info("Killing {}", rsServerName); HRegionServer hrs = cluster.getRegionServer(rsServerName); hrs.abort("KILLED"); while (!hrs.isStopped()) { Threads.sleep(10); } LOG.info("Dead {}", rsServerName); // Now assert still references in hbase:meta to the 'dead' server -- they haven't been // cleaned up by an SCP or by anything else. assertTrue(searchMeta(master, rsServerName)); // Assert region is OPEN on dead server still. r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName()); assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER))); serverName = CatalogFamilyFormat.getServerName(r, 0); assertNotNull(cluster.getRegionServer(serverName)); assertEquals(rsServerName, serverName); // I now have 'Unknown Server' references in hbase:meta; i.e. Server references // with no corresponding SCP. Queue one. MasterProtos.ScheduleServerCrashProcedureResponse response = master.getMasterRpcServices().scheduleServerCrashProcedure(null, MasterProtos.ScheduleServerCrashProcedureRequest.newBuilder(). addServerName(ProtobufUtil.toServerName(rsServerName)).build()); assertEquals(1, response.getPidCount()); long pid = response.getPid(0); assertNotEquals(Procedure.NO_PROC_ID, pid); while (master.getMasterProcedureExecutor().getActiveProcIds().contains(pid)) { Threads.sleep(10); } // After SCP, assert region is OPEN on new server. r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName()); assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER))); serverName = CatalogFamilyFormat.getServerName(r, 0); assertNotNull(cluster.getRegionServer(serverName)); assertNotEquals(rsServerName, serverName); // Make sure no mention of old server post SCP. assertFalse(searchMeta(master, rsServerName)); }