Java Code Examples for org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread#isAlive()

The following examples show how to use org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread#isAlive() . 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: TestClientClusterStatus.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName());
  UTIL = new HBaseTestingUtility(conf);
  StartMiniClusterOption option = StartMiniClusterOption.builder()
      .numMasters(MASTERS).numRegionServers(SLAVES).numDataNodes(SLAVES).build();
  UTIL.startMiniCluster(option);
  CLUSTER = UTIL.getHBaseCluster();
  CLUSTER.waitForActiveAndReadyMaster();
  ADMIN = UTIL.getAdmin();
  // Kill one region server
  List<RegionServerThread> rsts = CLUSTER.getLiveRegionServerThreads();
  RegionServerThread rst = rsts.get(rsts.size() - 1);
  DEAD = rst.getRegionServer();
  DEAD.stop("Test dead servers status");
  while (rst.isAlive()) {
    Thread.sleep(500);
  }
}
 
Example 2
Source File: TestClientClusterMetrics.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName());
  UTIL = new HBaseTestingUtility(conf);
  StartMiniClusterOption option = StartMiniClusterOption.builder()
      .numMasters(MASTERS).numRegionServers(SLAVES).numDataNodes(SLAVES).build();
  UTIL.startMiniCluster(option);
  CLUSTER = UTIL.getHBaseCluster();
  CLUSTER.waitForActiveAndReadyMaster();
  ADMIN = UTIL.getAdmin();
  // Kill one region server
  List<RegionServerThread> rsts = CLUSTER.getLiveRegionServerThreads();
  RegionServerThread rst = rsts.get(rsts.size() - 1);
  DEAD = rst.getRegionServer();
  DEAD.stop("Test dead servers metrics");
  while (rst.isAlive()) {
    Thread.sleep(500);
  }
}
 
Example 3
Source File: AbstractTestDLS.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Find a RS that has regions of a table.
 * @param hasMetaRegion when true, the returned RS has hbase:meta region as well
 */
private HRegionServer findRSToKill(boolean hasMetaRegion) throws Exception {
  List<RegionServerThread> rsts = cluster.getLiveRegionServerThreads();
  List<RegionInfo> regions = null;
  HRegionServer hrs = null;

  for (RegionServerThread rst : rsts) {
    hrs = rst.getRegionServer();
    while (rst.isAlive() && !hrs.isOnline()) {
      Thread.sleep(100);
    }
    if (!rst.isAlive()) {
      continue;
    }
    boolean isCarryingMeta = false;
    boolean foundTableRegion = false;
    regions = ProtobufUtil.getOnlineRegions(hrs.getRSRpcServices());
    for (RegionInfo region : regions) {
      if (region.isMetaRegion()) {
        isCarryingMeta = true;
      }
      if (region.getTable() == tableName) {
        foundTableRegion = true;
      }
      if (foundTableRegion && (isCarryingMeta || !hasMetaRegion)) {
        break;
      }
    }
    if (isCarryingMeta && hasMetaRegion) {
      // clients ask for a RS with META
      if (!foundTableRegion) {
        HRegionServer destRS = hrs;
        // the RS doesn't have regions of the specified table so we need move one to this RS
        List<RegionInfo> tableRegions = TEST_UTIL.getAdmin().getRegions(tableName);
        RegionInfo hri = tableRegions.get(0);
        TEST_UTIL.getAdmin().move(hri.getEncodedNameAsBytes(), destRS.getServerName());
        // wait for region move completes
        RegionStates regionStates =
            TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
        TEST_UTIL.waitFor(45000, 200, new Waiter.Predicate<Exception>() {
          @Override
          public boolean evaluate() throws Exception {
            ServerName sn = regionStates.getRegionServerOfRegion(hri);
            return (sn != null && sn.equals(destRS.getServerName()));
          }
        });
      }
      return hrs;
    } else if (hasMetaRegion || isCarryingMeta) {
      continue;
    }
    if (foundTableRegion) {
      break;
    }
  }

  return hrs;
}