Java Code Examples for org.apache.hadoop.hbase.MiniHBaseCluster#waitForActiveAndReadyMaster()

The following examples show how to use org.apache.hadoop.hbase.MiniHBaseCluster#waitForActiveAndReadyMaster() . 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: HBaseIOTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  // Try to bind the hostname to localhost to solve an issue when it is not configured or
  // no DNS resolution available.
  conf.setStrings("hbase.master.hostname", "localhost");
  conf.setStrings("hbase.regionserver.hostname", "localhost");
  htu = new HBaseTestingUtility(conf);

  // We don't use the full htu.startMiniCluster() to avoid starting unneeded HDFS/MR daemons
  htu.startMiniZKCluster();
  MiniHBaseCluster hbm = htu.startMiniHBaseCluster(1, 4);
  hbm.waitForActiveAndReadyMaster();

  admin = htu.getHBaseAdmin();
}
 
Example 2
Source File: TestingPhoenixServer.java    From presto with Apache License 2.0 5 votes vote down vote up
private TestingPhoenixServer()
{
    // keep references to prevent GC from resetting the log levels
    apacheLogger = java.util.logging.Logger.getLogger("org.apache");
    apacheLogger.setLevel(Level.SEVERE);
    zookeeperLogger = java.util.logging.Logger.getLogger(ZooKeeperServer.class.getName());
    zookeeperLogger.setLevel(Level.OFF);
    securityLogger = java.util.logging.Logger.getLogger("SecurityLogger.org.apache");
    securityLogger.setLevel(Level.SEVERE);
    // to squelch the SecurityLogger,
    // instantiate logger with config above before config is overriden again in HBase test franework
    org.apache.commons.logging.LogFactory.getLog("SecurityLogger.org.apache.hadoop.hbase.server");
    this.conf.set("hbase.security.logger", "ERROR");
    this.conf.setInt(MASTER_INFO_PORT, -1);
    this.conf.setInt(REGIONSERVER_INFO_PORT, -1);
    this.conf.setInt(HBASE_CLIENT_RETRIES_NUMBER, 1);
    this.conf.setBoolean("phoenix.schema.isNamespaceMappingEnabled", true);
    this.conf.set("hbase.regionserver.wal.codec", "org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec");
    this.hbaseTestingUtility = new HBaseTestingUtility(conf);

    try {
        MiniZooKeeperCluster zkCluster = this.hbaseTestingUtility.startMiniZKCluster();
        port = zkCluster.getClientPort();

        MiniHBaseCluster hbaseCluster = hbaseTestingUtility.startMiniHBaseCluster(1, 4);
        hbaseCluster.waitForActiveAndReadyMaster();
        LOG.info("Phoenix server ready: %s", getJdbcUrl());
    }
    catch (Exception e) {
        throw new RuntimeException("Can't start phoenix server.", e);
    }
}
 
Example 3
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();
}
 
Example 4
Source File: TestMasterFailover.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test meta in transition when master failover.
 * This test used to manipulate region state up in zk. That is not allowed any more in hbase2
 * so I removed that messing. That makes this test anemic.
 */
@Test
public void testMetaInTransitionWhenMasterFailover() throws Exception {
  // Start the cluster
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
  TEST_UTIL.startMiniCluster();
  try {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    LOG.info("Cluster started");

    HMaster activeMaster = cluster.getMaster();
    ServerName metaServerName = cluster.getServerHoldingMeta();
    HRegionServer hrs = cluster.getRegionServer(metaServerName);

    // Now kill master, meta should remain on rs, where we placed it before.
    LOG.info("Aborting master");
    activeMaster.abort("test-kill");
    cluster.waitForMasterToStop(activeMaster.getServerName(), 30000);
    LOG.info("Master has aborted");

    // meta should remain where it was
    RegionState metaState = MetaTableLocator.getMetaRegionState(hrs.getZooKeeper());
    assertEquals("hbase:meta should be online on RS",
        metaState.getServerName(), metaServerName);
    assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState());

    // Start up a new master
    LOG.info("Starting up a new master");
    activeMaster = cluster.startMaster().getMaster();
    LOG.info("Waiting for master to be ready");
    cluster.waitForActiveAndReadyMaster();
    LOG.info("Master is ready");

    // ensure meta is still deployed on RS
    metaState = MetaTableLocator.getMetaRegionState(activeMaster.getZooKeeper());
    assertEquals("hbase:meta should be online on RS",
        metaState.getServerName(), metaServerName);
    assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState());

    // Done, shutdown the cluster
  } finally {
    TEST_UTIL.shutdownMiniCluster();
  }
}