Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility#getAllOnlineRegions()

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#getAllOnlineRegions() . 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: AbstractTestDLS.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Table installTable(int nrs, int existingRegions) throws Exception {
  // Create a table with regions
  byte[] family = Bytes.toBytes("family");
  LOG.info("Creating table with " + nrs + " regions");
  Table table = TEST_UTIL.createMultiRegionTable(tableName, family, nrs);
  int numRegions = -1;
  try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
    numRegions = r.getStartKeys().length;
  }
  assertEquals(nrs, numRegions);
  LOG.info("Waiting for no more RIT\n");
  blockUntilNoRIT();
  // disable-enable cycle to get rid of table's dead regions left behind
  // by createMultiRegions
  assertTrue(TEST_UTIL.getAdmin().isTableEnabled(tableName));
  LOG.debug("Disabling table\n");
  TEST_UTIL.getAdmin().disableTable(tableName);
  LOG.debug("Waiting for no more RIT\n");
  blockUntilNoRIT();
  NavigableSet<String> regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  LOG.debug("Verifying only catalog region is assigned\n");
  if (regions.size() != 1) {
    for (String oregion : regions)
      LOG.debug("Region still online: " + oregion);
  }
  assertEquals(1 + existingRegions, regions.size());
  LOG.debug("Enabling table\n");
  TEST_UTIL.getAdmin().enableTable(tableName);
  LOG.debug("Waiting for no more RIT\n");
  blockUntilNoRIT();
  LOG.debug("Verifying there are " + numRegions + " assigned on cluster\n");
  regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals(numRegions + 1 + existingRegions, regions.size());
  return table;
}
 
Example 2
Source File: TestMasterRestartAfterDisablingTable.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
    throws Exception {
  final int NUM_MASTERS = 2;
  final int NUM_REGIONS_TO_CREATE = 4;

  // Start the cluster
  log("Starting cluster");
  Configuration conf = HBaseConfiguration.create();
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
  StartMiniClusterOption option = StartMiniClusterOption.builder()
      .numMasters(NUM_MASTERS).build();
  TEST_UTIL.startMiniCluster(option);
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  log("Waiting for active/ready master");
  cluster.waitForActiveAndReadyMaster();

  // Create a table with regions
  final TableName tableName = TableName.valueOf(name.getMethodName());
  byte[] family = Bytes.toBytes("family");
  log("Creating table with " + NUM_REGIONS_TO_CREATE + " regions");
  Table ht = TEST_UTIL.createMultiRegionTable(tableName, family, NUM_REGIONS_TO_CREATE);
  int numRegions = -1;
  try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
    numRegions = r.getStartKeys().length;
  }
  numRegions += 1; // catalogs
  log("Waiting for no more RIT\n");
  TEST_UTIL.waitUntilNoRegionsInTransition(60000);
  log("Disabling table\n");
  TEST_UTIL.getAdmin().disableTable(tableName);

  NavigableSet<String> regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals("The number of regions for the table tableRestart should be 0 and only" +
    "the catalog table should be present.", 1, regions.size());

  List<MasterThread> masterThreads = cluster.getMasterThreads();
  MasterThread activeMaster = null;
  if (masterThreads.get(0).getMaster().isActiveMaster()) {
    activeMaster = masterThreads.get(0);
  } else {
    activeMaster = masterThreads.get(1);
  }
  activeMaster.getMaster().stop(
      "stopping the active master so that the backup can become active");
  cluster.hbaseCluster.waitOnMaster(activeMaster);
  cluster.waitForActiveAndReadyMaster();

  assertTrue("The table should not be in enabled state",
      cluster.getMaster().getTableStateManager().isTableState(
      TableName.valueOf(name.getMethodName()), TableState.State.DISABLED,
      TableState.State.DISABLING));
  log("Enabling table\n");
  // Need a new Admin, the previous one is on the old master
  Admin admin = TEST_UTIL.getAdmin();
  admin.enableTable(tableName);
  admin.close();
  log("Waiting for no more RIT\n");
  TEST_UTIL.waitUntilNoRegionsInTransition(60000);
  log("Verifying there are " + numRegions + " assigned on cluster\n");
  regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals("The assigned regions were not onlined after master" +
    " switch except for the catalog table.", 5, regions.size());
  assertTrue("The table should be in enabled state", cluster.getMaster().getTableStateManager()
    .isTableState(TableName.valueOf(name.getMethodName()), TableState.State.ENABLED));
  ht.close();
  TEST_UTIL.shutdownMiniCluster();
}