Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.MiniHBaseCluster$HMasterRunner


  public void testCorrectnessWhenMasterFailOver() throws Exception {
    final byte[] TABLENAME = Bytes.toBytes("testCorrectnessWhenMasterFailOver");
    final byte[] FAMILY = Bytes.toBytes("family");
    final byte[][] SPLITKEYS = { Bytes.toBytes("b"), Bytes.toBytes("i") };

    MiniHBaseCluster cluster = TESTUTIL.getHBaseCluster();

    HTableDescriptor desc = new HTableDescriptor(TABLENAME);
    desc.addFamily(new HColumnDescriptor(FAMILY));
    HBaseAdmin hbaseAdmin = TESTUTIL.getHBaseAdmin();
    hbaseAdmin.createTable(desc, SPLITKEYS);

    assertTrue(hbaseAdmin.isTableAvailable(TABLENAME));

    HTable table = new HTable(TESTUTIL.getConfiguration(), TABLENAME);
    List<Put> puts = new ArrayList<Put>();
    Put put1 = new Put(Bytes.toBytes("a"));
    put1.add(FAMILY, Bytes.toBytes("q1"), Bytes.toBytes("value"));
    Put put2 = new Put(Bytes.toBytes("h"));
    put2.add(FAMILY, Bytes.toBytes("q1"), Bytes.toBytes("value"));
    Put put3 = new Put(Bytes.toBytes("o"));
    put3.add(FAMILY, Bytes.toBytes("q1"), Bytes.toBytes("value"));
    puts.add(put1);
    puts.add(put2);
    puts.add(put3);
    table.put(puts);
    ResultScanner resultScanner = table.getScanner(new Scan());
    int count = 0;
    while (resultScanner.next() != null) {
      count++;
    }
    resultScanner.close();
    table.close();
    assertEquals(3, count);

    /* Starting test */
    cluster.getConfiguration().setBoolean("TestingMaster.sleep", true);
    cluster.getConfiguration().setInt("TestingMaster.sleep.duration", 10000);

    /* NO.1 .META. region correctness */
    // First abort master
    abortMaster(cluster);
    TestingMaster master = startMasterAndWaitUntilLogSplit(cluster);

    // Second kill meta server
    int metaServerNum = cluster.getServerWithMeta();
    int rootServerNum = cluster.getServerWith(HRegionInfo.ROOT_REGIONINFO
        .getRegionName());
    HRegionServer metaRS = cluster.getRegionServer(metaServerNum);
    LOG.debug("Killing metaRS and carryingRoot = "
        + (metaServerNum == rootServerNum));
    metaRS.kill();
    metaRS.join();

    /*
     * Sleep double time of TestingMaster.sleep.duration, so we can ensure that
     * master has already assigned ROOTandMETA or is blocking on assigning
     * ROOTandMETA
     */
    Thread.sleep(10000 * 2);

    waitUntilMasterIsInitialized(master);

    // Third check whether data is correct in meta region
    assertTrue(hbaseAdmin.isTableAvailable(TABLENAME));

    /*
     * NO.2 -ROOT- region correctness . If the .META. server killed in the NO.1
     * is also carrying -ROOT- region, it is not needed
     */
    if (rootServerNum != metaServerNum) {
      // First abort master
      abortMaster(cluster);
      master = startMasterAndWaitUntilLogSplit(cluster);

      // Second kill meta server
      HRegionServer rootRS = cluster.getRegionServer(rootServerNum);
      LOG.debug("Killing rootRS");
      rootRS.kill();
      rootRS.join();

      /*
       * Sleep double time of TestingMaster.sleep.duration, so we can ensure
       * that master has already assigned ROOTandMETA or is blocking on
       * assigning ROOTandMETA
       */
      Thread.sleep(10000 * 2);
      waitUntilMasterIsInitialized(master);

      // Third check whether data is correct in meta region
      assertTrue(hbaseAdmin.isTableAvailable(TABLENAME));
    }

    /* NO.3 data region correctness */
    ServerManager serverManager = cluster.getMaster().getServerManager();
    while (serverManager.areDeadServersInProgress()) {
      Thread.sleep(100);
    }
    // Create a ZKW to use in the test
    ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TESTUTIL);
View Full Code Here


    HBaseAdmin ha = new HBaseAdmin(conn);
    assertTrue(ha.tableExists(tableName));
    assertTrue(t.get(new Get(ROW)).isEmpty());

    // stop the master
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    cluster.stopMaster(0, false);
    cluster.waitOnMaster(0);

    // start up a new master
    cluster.startMaster();
    assertTrue(cluster.waitForActiveAndReadyMaster());

    // test that the same unmanaged connection works with a new
    // HBaseAdmin and can connect to the new master;
    HBaseAdmin newAdmin = new HBaseAdmin(conn);
    assertTrue(newAdmin.tableExists(tableName));
View Full Code Here

    try {
      final byte[] TABLENAME = Bytes
          .toBytes("testDataCorrectnessReplayingRecoveredEdits");
      final byte[] FAMILY = Bytes.toBytes("family");
      MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
      HMaster master = cluster.getMaster();

      // Create table
      HTableDescriptor desc = new HTableDescriptor(TABLENAME);
      desc.addFamily(new HColumnDescriptor(FAMILY));
      HBaseAdmin hbaseAdmin = TEST_UTIL.getHBaseAdmin();
      hbaseAdmin.createTable(desc);

      assertTrue(hbaseAdmin.isTableAvailable(TABLENAME));

      // Put data: r1->v1
      HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLENAME);
      putDataAndVerify(table, "r1", FAMILY, "v1", 1);

      // Move region to target server
      HRegionInfo regionInfo = table.getRegionLocation("r1").getRegionInfo();
      int originServerNum = cluster.getServerWith(regionInfo.getRegionName());
      HRegionServer originServer = cluster.getRegionServer(originServerNum);
      int targetServerNum = (originServerNum + 1) % NUM_RS;
      HRegionServer targetServer = cluster.getRegionServer(targetServerNum);
      assertFalse(originServer.equals(targetServer));

      do {
        Thread.sleep(10);
      } while (!originServer.getServerName().equals(
              cluster.getMaster().getAssignmentManager().getRegionServerOfRegion(regionInfo)));

      hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(),
          Bytes.toBytes(targetServer.getServerName().getServerName()));

      do {
        Thread.sleep(10);
      } while (cluster.getServerWith(regionInfo.getRegionName()) == originServerNum ||
          !targetServer.getServerName().equals(
              cluster.getMaster().getAssignmentManager().getRegionServerOfRegion(regionInfo)));

      // Put data: r2->v2
      putDataAndVerify(table, "r2", FAMILY, "v2", 2);

      // Move region to origin server
      hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(),
          Bytes.toBytes(originServer.getServerName().getServerName()));
      do {
        Thread.sleep(1);
      } while (cluster.getServerWith(regionInfo.getRegionName()) == targetServerNum);

      // Put data: r3->v3
      putDataAndVerify(table, "r3", FAMILY, "v3", 3);

      // Kill target server
      targetServer.kill();
      cluster.getRegionServerThreads().get(targetServerNum).join();
      // Wait until finish processing of shutdown
      while (master.getServerManager().areDeadServersInProgress()) {
        Thread.sleep(5);
      }
      // Kill origin server
      originServer.kill();
      cluster.getRegionServerThreads().get(originServerNum).join();

      // Put data: r4->v4
      putDataAndVerify(table, "r4", FAMILY, "v4", 4);

    } finally {
View Full Code Here

    TEST_UTIL.shutdownMiniCluster();
  }

  @Test
  public void testMasterOpsWhileSplitting() throws Exception {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster m = cluster.getMaster();
    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();

    TEST_UTIL.createTable(TABLENAME, FAMILYNAME);
    TEST_UTIL.loadTable(new HTable(TABLENAME), FAMILYNAME);
View Full Code Here

   * @see <a href="https://issues.apache.org/jira/browse/HBASE-2428">HBASE-2428</a>
   */
  @Test (timeout=300000) public void testRegionCloseWhenNoMetaHBase2428()
  throws Exception {
    LOG.info("Running testRegionCloseWhenNoMetaHBase2428");
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    final HMaster master = cluster.getMaster();
    int metaIndex = cluster.getServerWithMeta();
    // Figure the index of the server that is not server the .META.
    int otherServerIndex = -1;
    for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
      if (i == metaIndex) continue;
      otherServerIndex = i;
      break;
    }
    final HRegionServer otherServer = cluster.getRegionServer(otherServerIndex);
    final HRegionServer metaHRS = cluster.getRegionServer(metaIndex);

    // Get a region out on the otherServer.
    final HRegionInfo hri =
      otherServer.getOnlineRegions().iterator().next().getRegionInfo();
    // Add our RegionServerOperationsListener
    HBase2428Listener listener = new HBase2428Listener(cluster,
      metaHRS.getHServerInfo().getServerAddress(), hri, otherServerIndex);
    master.getRegionServerOperationQueue().
      registerRegionServerOperationListener(listener);
    try {
      // Now close the server carrying meta.
      cluster.abortRegionServer(metaIndex);

      // First wait on receipt of meta server shutdown message.
      while(!listener.metaShutdownReceived) Threads.sleep(100);
      while(!listener.isDone()) Threads.sleep(10);
      // We should not have retried the close more times than it took for the
View Full Code Here

   * that meta gets redeployed.
   */
  @Test (timeout=300000) public void testAddingServerBeforeOldIsDead2413()
  throws IOException {
    LOG.info("Running testAddingServerBeforeOldIsDead2413");
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    int count = count();
    int metaIndex = cluster.getServerWithMeta();
    MiniHBaseClusterRegionServer metaHRS =
      (MiniHBaseClusterRegionServer)cluster.getRegionServer(metaIndex);
    int port = metaHRS.getServerInfo().getServerAddress().getPort();
    Configuration c = TEST_UTIL.getConfiguration();
    String oldPort = c.get(HConstants.REGIONSERVER_PORT, "0");
    try {
      LOG.info("KILLED=" + metaHRS);
      metaHRS.kill();
      c.set(HConstants.REGIONSERVER_PORT, Integer.toString(port));
      // Try and start new regionserver.  It might clash with the old
      // regionserver port so keep trying to get past the BindException.
      HRegionServer hrs = null;
      while (true) {
        try {
          hrs = cluster.startRegionServer().getRegionServer();
          break;
        } catch (IOException e) {
          if (e.getCause() != null && e.getCause() instanceof InvocationTargetException) {
            InvocationTargetException ee = (InvocationTargetException)e.getCause();
            if (ee.getCause() != null && ee.getCause() instanceof BindException) {
View Full Code Here

   * @see <a href="https://issues.apache.org/jira/browse/HBASE-2482">HBASE-2482</a>
   */
  @Test (timeout=300000) public void testKillRSWithOpeningRegion2482()
  throws Exception {
    LOG.info("Running testKillRSWithOpeningRegion2482");
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    if (cluster.getLiveRegionServerThreads().size() < 2) {
      // Need at least two servers.
      cluster.startRegionServer();
    }
    // Count how many regions are online.  They need to be all back online for
    // this test to succeed.
    int countOfMetaRegions = countOfMetaRegions();
    // Add a listener on the server.
    HMaster m = cluster.getMaster();
    // Start new regionserver.
    MiniHBaseClusterRegionServer hrs =
      (MiniHBaseClusterRegionServer)cluster.startRegionServer().getRegionServer();
    LOG.info("Started new regionserver: " + hrs.toString());
    // Wait until has some regions before proceeding.  Balancer will give it some.
    int minimumRegions =
      countOfMetaRegions/(cluster.getRegionServerThreads().size() * 2);
    while (hrs.getOnlineRegions().size() < minimumRegions) Threads.sleep(100);
    // Set the listener only after some regions have been opened on new server.
    HBase2482Listener listener = new HBase2482Listener(hrs);
    m.getRegionServerOperationQueue().
      registerRegionServerOperationListener(listener);
    try {
      // Go close all non-catalog regions on this new server
      closeAllNonCatalogRegions(cluster, hrs);
      // After all closes, add blocking message before the region opens start to
      // come in.
      cluster.addMessageToSendRegionServer(hrs,
        new HMsg(HMsg.Type.TESTING_MSG_BLOCK_RS));
      // Wait till one of the above close messages has an effect before we start
      // wait on all regions back online.
      while (!listener.closed) Threads.sleep(100);
      LOG.info("Past close");
View Full Code Here

    htu.getConfiguration().setLong("dfs.block.size", DEFAULT_BLOCK_SIZE);
    htu.getConfiguration().setInt("dfs.replication", 2);


    // set up a cluster with 3 nodes
    MiniHBaseCluster cluster = null;
    String dataNodeHosts[] = new String[] { "host1", "host2", "host3" };
    int regionServersCount = 3;

    try {
      cluster = htu.startMiniCluster(1, regionServersCount, dataNodeHosts);
View Full Code Here

    try {
      setupTable(table);
      assertEquals(ROWKEYS.length, countRows());

      // Mess it up by creating an overlap
      MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
      HMaster master = cluster.getMaster();
      HRegionInfo hriOverlap1 = createRegion(conf, tbl.getTableDescriptor(),
        Bytes.toBytes("A"), Bytes.toBytes("AB"));
      master.assignRegion(hriOverlap1);
      master.getAssignmentManager().waitForAssignment(hriOverlap1);
      HRegionInfo hriOverlap2 = createRegion(conf, tbl.getTableDescriptor(),
        Bytes.toBytes("AB"), Bytes.toBytes("B"));
      master.assignRegion(hriOverlap2);
      master.getAssignmentManager().waitForAssignment(hriOverlap2);

      HBaseFsck hbck = doFsck(conf, false);
      assertErrors(hbck, new ERROR_CODE[] {ERROR_CODE.DUPE_STARTKEYS,
        ERROR_CODE.DUPE_STARTKEYS, ERROR_CODE.OVERLAP_IN_REGION_CHAIN});
      assertEquals(3, hbck.getOverlapGroups(table).size());
      assertEquals(ROWKEYS.length, countRows());

      // mess around the overlapped regions, to trigger NotServingRegionException
      Multimap<byte[], HbckInfo> overlapGroups = hbck.getOverlapGroups(table);
      ServerName serverName = null;
      byte[] regionName = null;
      for (HbckInfo hbi: overlapGroups.values()) {
        if ("A".equals(Bytes.toString(hbi.getStartKey()))
            && "B".equals(Bytes.toString(hbi.getEndKey()))) {
          regionName = hbi.getRegionName();

          // get an RS not serving the region to force bad assignment info in to META.
          int k = cluster.getServerWith(regionName);
          for (int i = 0; i < 3; i++) {
            if (i != k) {
              HRegionServer rs = cluster.getRegionServer(i);
              serverName = rs.getServerName();
              break;
            }
          }

          HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
          HBaseFsckRepair.closeRegionSilentlyAndWait(admin,
            cluster.getRegionServer(k).getServerName(), hbi.getHdfsHRI());
          admin.unassign(regionName, true);
          break;
        }
      }
View Full Code Here

  @Test
  public void testRegionShouldNotBeDeployed() throws Exception {
    String table = "tableRegionShouldNotBeDeployed";
    try {
      LOG.info("Starting testRegionShouldNotBeDeployed.");
      MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
      assertTrue(cluster.waitForActiveAndReadyMaster());

      // Create a ZKW to use in the test
      ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);

      FileSystem filesystem = FileSystem.get(conf);
      Path rootdir = filesystem.makeQualified(new Path(conf
          .get(HConstants.HBASE_DIR)));

      byte[][] SPLIT_KEYS = new byte[][] { new byte[0], Bytes.toBytes("aaa"),
          Bytes.toBytes("bbb"), Bytes.toBytes("ccc"), Bytes.toBytes("ddd") };
      HTableDescriptor htdDisabled = new HTableDescriptor(Bytes.toBytes(table));
      htdDisabled.addFamily(new HColumnDescriptor(FAM));

      // Write the .tableinfo
      FSTableDescriptors
          .createTableDescriptor(filesystem, rootdir, htdDisabled);
      List<HRegionInfo> disabledRegions = TEST_UTIL.createMultiRegionsInMeta(
          TEST_UTIL.getConfiguration(), htdDisabled, SPLIT_KEYS);

      // Let's just assign everything to first RS
      HRegionServer hrs = cluster.getRegionServer(0);
      ServerName serverName = hrs.getServerName();

      // create region files.
      TEST_UTIL.getHBaseAdmin().disableTable(table);
      TEST_UTIL.getHBaseAdmin().enableTable(table);
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.MiniHBaseCluster$HMasterRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.