Search in sources :

Example 11 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestMasterReplication method rollWALAndWait.

private void rollWALAndWait(final HBaseTestingUtility utility, final TableName table, final byte[] row) throws IOException {
    final Admin admin = utility.getAdmin();
    final MiniHBaseCluster cluster = utility.getMiniHBaseCluster();
    // find the region that corresponds to the given row.
    HRegion region = null;
    for (HRegion candidate : cluster.getRegions(table)) {
        if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
            region = candidate;
            break;
        }
    }
    assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);
    final CountDownLatch latch = new CountDownLatch(1);
    // listen for successful log rolls
    final WALActionsListener listener = new WALActionsListener.Base() {

        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
            latch.countDown();
        }
    };
    region.getWAL().registerWALActionsListener(listener);
    // request a roll
    admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDesc().getTableName(), region.getRegionInfo().getRegionName()));
    // wait
    try {
        latch.await();
    } catch (InterruptedException exception) {
        LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " + "replication tests fail, it's probably because we should still be waiting.");
        Thread.currentThread().interrupt();
    }
    region.getWAL().unregisterWALActionsListener(listener);
}
Also used : Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestScannersFromClientSide method testScanOnReopenedRegion.

/**
   * Test from client side for scan while the region is reopened
   * on the same region server.
   *
   * @throws Exception
   */
@Test
public void testScanOnReopenedRegion() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 2);
    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
    Put put;
    Scan scan;
    Result result;
    ResultScanner scanner;
    boolean toLog = false;
    List<Cell> kvListExp;
    // table: row, family, c0:0, c1:1
    put = new Put(ROW);
    for (int i = 0; i < QUALIFIERS.length; i++) {
        KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
        put.add(kv);
    }
    ht.put(put);
    scan = new Scan().withStartRow(ROW);
    scanner = ht.getScanner(scan);
    HRegionLocation loc;
    try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        loc = locator.getRegionLocation(ROW);
    }
    HRegionInfo hri = loc.getRegionInfo();
    MiniHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
    byte[] regionName = hri.getRegionName();
    int i = cluster.getServerWith(regionName);
    HRegionServer rs = cluster.getRegionServer(i);
    ProtobufUtil.closeRegion(null, rs.getRSRpcServices(), rs.getServerName(), regionName);
    long startTime = EnvironmentEdgeManager.currentTime();
    long timeOut = 300000;
    while (true) {
        if (rs.getOnlineRegion(regionName) == null) {
            break;
        }
        assertTrue("Timed out in closing the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
        Thread.sleep(500);
    }
    // Now open the region again.
    HMaster master = cluster.getMaster();
    RegionStates states = master.getAssignmentManager().getRegionStates();
    states.regionOffline(hri);
    states.updateRegionState(hri, State.OPENING);
    ProtobufUtil.openRegion(null, rs.getRSRpcServices(), rs.getServerName(), hri);
    startTime = EnvironmentEdgeManager.currentTime();
    while (true) {
        if (rs.getOnlineRegion(regionName) != null) {
            break;
        }
        assertTrue("Timed out in open the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
        Thread.sleep(500);
    }
    // c0:0, c1:1
    kvListExp = new ArrayList<>();
    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[0], 0, VALUE));
    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[1], 1, VALUE));
    result = scanner.next();
    verifyResult(result, kvListExp, toLog, "Testing scan on re-opened region");
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) RegionStates(org.apache.hadoop.hbase.master.RegionStates) HMaster(org.apache.hadoop.hbase.master.HMaster) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 13 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestMasterCoprocessorExceptionWithRemove method testExceptionFromCoprocessorWhenCreatingTable.

@Test(timeout = 30000)
public void testExceptionFromCoprocessorWhenCreatingTable() throws IOException {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    BuggyMasterObserver cp = (BuggyMasterObserver) host.findCoprocessor(BuggyMasterObserver.class.getName());
    assertFalse("No table created yet", cp.wasCreateTableCalled());
    // Set a watch on the zookeeper /hbase/master node. If the master dies,
    // the node will be deleted.
    // Master should *NOT* die:
    // we are testing that the default setting of hbase.coprocessor.abortonerror
    // =false
    // is respected.
    ZooKeeperWatcher zkw = new ZooKeeperWatcher(UTIL.getConfiguration(), "unittest", new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
            throw new RuntimeException("Fatal ZK error: " + why, e);
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    });
    MasterTracker masterTracker = new MasterTracker(zkw, "/hbase/master", new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
            throw new RuntimeException("Fatal ZooKeeper tracker error, why=", e);
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    });
    masterTracker.start();
    zkw.registerListener(masterTracker);
    // Test (part of the) output that should have be printed by master when it aborts:
    // (namely the part that shows the set of loaded coprocessors).
    // In this test, there is only a single coprocessor (BuggyMasterObserver).
    String coprocessorName = BuggyMasterObserver.class.getName();
    assertTrue(HMaster.getLoadedCoprocessors().contains(coprocessorName));
    HTableDescriptor htd1 = new HTableDescriptor(TableName.valueOf(TEST_TABLE1));
    htd1.addFamily(new HColumnDescriptor(TEST_FAMILY1));
    boolean threwDNRE = false;
    try {
        Admin admin = UTIL.getAdmin();
        admin.createTable(htd1);
    } catch (IOException e) {
        if (e.getClass().getName().equals("org.apache.hadoop.hbase.DoNotRetryIOException")) {
            threwDNRE = true;
        }
    } finally {
        assertTrue(threwDNRE);
    }
    // wait for a few seconds to make sure that the Master hasn't aborted.
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        fail("InterruptedException while sleeping.");
    }
    assertFalse("Master survived coprocessor NPE, as expected.", masterTracker.masterZKNodeWasDeleted);
    String loadedCoprocessors = HMaster.getLoadedCoprocessors();
    assertTrue(loadedCoprocessors.contains(coprocessorName));
    // Verify that BuggyMasterObserver has been removed due to its misbehavior
    // by creating another table: should not have a problem this time.
    HTableDescriptor htd2 = new HTableDescriptor(TableName.valueOf(TEST_TABLE2));
    htd2.addFamily(new HColumnDescriptor(TEST_FAMILY2));
    Admin admin = UTIL.getAdmin();
    try {
        admin.createTable(htd2);
    } catch (IOException e) {
        fail("Failed to create table after buggy coprocessor removal: " + e);
    }
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) Abortable(org.apache.hadoop.hbase.Abortable) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 14 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestMasterObserver method testListProceduresOperation.

@Test(timeout = 180000)
public void testListProceduresOperation() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
    cp.resetStates();
    master.listProcedures();
    assertTrue("Coprocessor should be called on list procedures request", cp.wasListProceduresCalled());
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HMaster(org.apache.hadoop.hbase.master.HMaster) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Test(org.junit.Test)

Example 15 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestMasterObserver method testNamespaceOperations.

@Test(timeout = 180000)
public void testNamespaceOperations() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    String testNamespace = "observed_ns";
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
    cp.enableBypass(false);
    cp.resetStates();
    // create a table
    Admin admin = UTIL.getAdmin();
    admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
    assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled());
    assertNotNull(admin.getNamespaceDescriptor(testNamespace));
    assertTrue("Test namespace descriptor should have been called", cp.wasGetNamespaceDescriptorCalled());
    // turn off bypass, run the tests again
    cp.enableBypass(true);
    cp.resetStates();
    boolean expected = false;
    try {
        admin.modifyNamespace(NamespaceDescriptor.create(testNamespace).build());
    } catch (BypassCoprocessorException ce) {
        expected = true;
    }
    assertTrue(expected);
    assertTrue("Test namespace should not have been modified", cp.preModifyNamespaceCalledOnly());
    assertNotNull(admin.getNamespaceDescriptor(testNamespace));
    assertTrue("Test namespace descriptor should have been called", cp.wasGetNamespaceDescriptorCalled());
    expected = false;
    try {
        admin.deleteNamespace(testNamespace);
    } catch (BypassCoprocessorException ce) {
        expected = true;
    }
    assertTrue(expected);
    assertTrue("Test namespace should not have been deleted", cp.preDeleteNamespaceCalledOnly());
    assertNotNull(admin.getNamespaceDescriptor(testNamespace));
    assertTrue("Test namespace descriptor should have been called", cp.wasGetNamespaceDescriptorCalled());
    cp.enableBypass(false);
    cp.resetStates();
    // delete table
    admin.modifyNamespace(NamespaceDescriptor.create(testNamespace).build());
    assertTrue("Test namespace should have been modified", cp.wasModifyNamespaceCalled());
    admin.deleteNamespace(testNamespace);
    assertTrue("Test namespace should have been deleted", cp.wasDeleteNamespaceCalled());
    cp.enableBypass(true);
    cp.resetStates();
    expected = false;
    try {
        admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
    } catch (BypassCoprocessorException ce) {
        expected = true;
    }
    assertTrue(expected);
    assertTrue("Test namespace should not be created", cp.preCreateNamespaceCalledOnly());
    // turn on bypass, run the test
    cp.enableBypass(true);
    cp.resetStates();
    admin.listNamespaceDescriptors();
    assertTrue("post listNamespace should not have been called", cp.preListNamespaceDescriptorsCalledOnly());
    // turn off bypass, run the tests again
    cp.enableBypass(false);
    cp.resetStates();
    admin.listNamespaceDescriptors();
    assertTrue("post listNamespace should have been called", cp.wasListNamespaceDescriptorsCalled());
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HMaster(org.apache.hadoop.hbase.master.HMaster) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Aggregations

MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)86 Test (org.junit.Test)58 TableName (org.apache.hadoop.hbase.TableName)32 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)25 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)21 Table (org.apache.hadoop.hbase.client.Table)21 HMaster (org.apache.hadoop.hbase.master.HMaster)21 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)20 ServerName (org.apache.hadoop.hbase.ServerName)19 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)19 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)18 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)14 Admin (org.apache.hadoop.hbase.client.Admin)12 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 IOException (java.io.IOException)11 Region (org.apache.hadoop.hbase.regionserver.Region)11 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)10 Put (org.apache.hadoop.hbase.client.Put)8 TreeMap (java.util.TreeMap)7 Waiter (org.apache.hadoop.hbase.Waiter)7