Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.MiniHBaseCluster


    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


  }

  @Test
  public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception {
    final byte[] tableName = Bytes.toBytes("testCreateTableCalledTwiceAndFirstOneInProgress");
    final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    final HMaster m = cluster.getMaster();
    final HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILYNAME));
    final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getName(), null,
        null) };
    CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
        m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
        m.getCatalogTracker(), m.getAssignmentManager());
    throwException = true;
    handler.process();
    throwException = false;
    CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
        m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
        m.getCatalogTracker(), m.getAssignmentManager());
    handler1.process();
    for (int i = 0; i < 100; i++) {
      if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
        Thread.sleep(200);
View Full Code Here

  }

  @Test (timeout=300000)
  public void testCreateTableWithSplitRegion() throws Exception {
    final byte[] tableName = Bytes.toBytes("testCreateTableWithSplitRegion");
    final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    final HMaster m = cluster.getMaster();
    final HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILYNAME));
    byte[] splitPoint = Bytes.toBytes("split-point");
    long ts = System.currentTimeMillis();
    HRegionInfo d1 = new HRegionInfo(tableName, null, splitPoint, false, ts);
    HRegionInfo d2 = new HRegionInfo(tableName, splitPoint, null, false, ts + 1);
    HRegionInfo parent = new HRegionInfo(tableName, null, null, true, ts + 2);
    parent.setOffline(true);

    Path tempdir = m.getMasterFileSystem().getTempDir();
    FileSystem fs = m.getMasterFileSystem().getFileSystem();
    Path tempTableDir = FSUtils.getTablePath(tempdir, tableName);
    fs.delete(tempTableDir, true); // Clean up temp table dir if exists

    final HRegionInfo[] hRegionInfos = new HRegionInfo[] {d1, d2, parent};
    CreateTableHandler handler = new CreateTableHandler(m, m.getMasterFileSystem(),
      m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
      m.getCatalogTracker(), m.getAssignmentManager());
    handler.process();
    for (int i = 0; i < 200; i++) {
      if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
        Thread.sleep(300);
View Full Code Here

  }

  @Test (timeout=60000)
  public void testMasterRestartAfterEnablingNodeIsCreated() throws Exception {
    byte[] tableName = Bytes.toBytes("testMasterRestartAfterEnablingNodeIsCreated");
    final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    final HMaster m = cluster.getMaster();
    final HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILYNAME));
    final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getName(), null,
        null) };
    CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(),
        m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
        m.getCatalogTracker(), m.getAssignmentManager());
    throwException = true;
    handler.process();
    abortAndStartNewMaster(cluster);
    assertTrue(cluster.getLiveMasterThreads().size() == 1);
  }
View Full Code Here

    }
  }
 
  @Test
  public void testTransitionToFailedOpenEvenIfCleanupFails() throws Exception {
    MiniHBaseCluster cluster = HTU.getHBaseCluster();
    HRegionServer server =
        cluster.getLiveRegionServerThreads().get(0).getRegionServer();
    // Create it OFFLINE, which is what it expects
    ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());
    ZKAssign.transitionNodeOpening(server.getZooKeeper(), TEST_HRI, server.getServerName());
    // Create the handler
    OpenRegionHandler handler = new OpenRegionHandler(server, server, TEST_HRI, TEST_HTD) {
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

   * expired zookeeper session. Without the HBASE-6046 fix master always tries
   * to assign all the user regions by calling retainAssignment.
   */
  @Test
  public void testRegionAssignmentAfterMasterRecoveryDueToZKExpiry() throws Exception {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    cluster.startRegionServer();
    HMaster m = cluster.getMaster();
    ZooKeeperWatcher zkw = m.getZooKeeperWatcher();
    int expectedNumOfListeners = zkw.getNumberOfListeners();
    // now the cluster is up. So assign some regions.
    HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
    byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"),
View Full Code Here

   * zookeeper session and an RS goes down.
   */
  @Test(timeout = 60000)
  public void testLogSplittingAfterMasterRecoveryDueToZKExpiry() throws IOException,
      KeeperException, InterruptedException {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    cluster.startRegionServer();
    HMaster m = cluster.getMaster();
    // now the cluster is up. So assign some regions.
    HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
    byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("1"), Bytes.toBytes("2"),
        Bytes.toBytes("3"), Bytes.toBytes("4"), Bytes.toBytes("5") };

    String tableName = "testLogSplittingAfterMasterRecoveryDueToZKExpiry";
    HTableDescriptor htd = new HTableDescriptor(tableName);
    HColumnDescriptor hcd = new HColumnDescriptor("col");
    htd.addFamily(hcd);
    admin.createTable(htd, SPLIT_KEYS);
    ZooKeeperWatcher zooKeeperWatcher = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
    ZKAssign.blockUntilNoRIT(zooKeeperWatcher);
    HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);

    Put p = null;
    int numberOfPuts = 0;
    for (numberOfPuts = 0; numberOfPuts < 6; numberOfPuts++) {
      p = new Put(Bytes.toBytes(numberOfPuts));
      p.add(Bytes.toBytes("col"), Bytes.toBytes("ql"), Bytes.toBytes("value" + numberOfPuts));
      table.put(p);
    }
    m.getZooKeeperWatcher().close();
    m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException());
    assertFalse(m.isStopped());
    cluster.getRegionServer(0).abort("Aborting");
    // Without patch for HBASE-6046 this test case will always timeout
    // with patch the test case should pass.
    Scan scan = new Scan();
    int numberOfRows = 0;
    ResultScanner scanner = table.getScanner(scan);
View Full Code Here

  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 = startMasterAndWaitTillMetaRegionAssignment(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 = startMasterAndWaitTillMetaRegionAssignment(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

    assertEquals(3, count);
  }

  @Test (timeout=180000)
  public void testMasterFailoverWhenDisablingTableRegionsInRITOnDeadRS() throws Exception {
    MiniHBaseCluster cluster = TESTUTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    // disable load balancing on this master
    master.balanceSwitch(false);

    final String table = "testMasterFailoverWhenDisablingTableRegionsInRITOnDeadRS";
    byte [] FAMILY = Bytes.toBytes("family");
    byte[][] SPLIT_KEYS =
        new byte[][] {Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"),
            Bytes.toBytes("d") };
    HTableDescriptor htd = new HTableDescriptor(table);
    HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
    htd.addFamily(hcd);
    TESTUTIL.getHBaseAdmin().createTable(htd, SPLIT_KEYS);
    AssignmentManager am = cluster.getMaster().getAssignmentManager();
    List<HRegionInfo> regionsOfTable = null;
    while ((regionsOfTable = am.getRegionsOfTable(table.getBytes())).size()
        != (SPLIT_KEYS.length + 1)) {
      Thread.sleep(10);
    }
    HRegionInfo closingRegion = regionsOfTable.get(0);
    ServerName serverName = am.getRegionServerOfRegion(closingRegion);
    HRegionServer deadRS = null;
    for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
      deadRS = cluster.getRegionServer(i);
      if (deadRS.getServerName().equals(serverName)) {
        break;
      }
    }

    // Disable the table in ZK
    ZKTable zkTable = am.getZKTable();
    zkTable.setDisablingTable(table);
    ZKAssign.createNodeClosing(master.getZooKeeper(), closingRegion, serverName);

    // Stop the master
    abortMaster(cluster);
    master = startMasterAndWaitTillMetaRegionAssignment(cluster);
    deadRS.kill();
    deadRS.join();
    waitUntilMasterIsInitialized(master);
    am = cluster.getMaster().getAssignmentManager();
    zkTable = am.getZKTable();
    // wait for no more RIT
    ZKAssign.blockUntilNoRIT(master.getZooKeeper());
    while (!master.getAssignmentManager().getZKTable().isDisabledTable(table)) {
      Thread.sleep(10);
View Full Code Here

TOP

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

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.