Search in sources :

Example 6 with ForeignExceptionDispatcher

use of org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher in project hbase by apache.

the class TestProcedure method testErrorPropagation.

@Test(timeout = 60000)
public void testErrorPropagation() throws Exception {
    List<String> members = new ArrayList<>();
    members.add("member");
    Procedure proc = new Procedure(coord, new ForeignExceptionDispatcher(), 100, Integer.MAX_VALUE, "op", null, members);
    final Procedure procspy = spy(proc);
    ForeignException cause = new ForeignException("SRC", "External Exception");
    proc.receive(cause);
    // start the barrier procedure
    Thread t = new Thread() {

        public void run() {
            procspy.call();
        }
    };
    t.start();
    t.join();
    verify(procspy, never()).sendGlobalBarrierStart();
    verify(procspy, never()).sendGlobalBarrierReached();
    verify(procspy).sendGlobalBarrierComplete();
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) Test(org.junit.Test)

Example 7 with ForeignExceptionDispatcher

use of org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher in project hbase by apache.

the class TestZKProcedureControllers method testSimpleZKCohortMemberController.

/**
   * Smaller test to just test the actuation on the cohort member
   * @throws Exception on failure
   */
@Test(timeout = 60000)
public void testSimpleZKCohortMemberController() throws Exception {
    ZooKeeperWatcher watcher = UTIL.getZooKeeperWatcher();
    final String operationName = "instanceTest";
    final Subprocedure sub = Mockito.mock(Subprocedure.class);
    Mockito.when(sub.getName()).thenReturn(operationName);
    final byte[] data = new byte[] { 1, 2, 3 };
    final CountDownLatch prepared = new CountDownLatch(1);
    final CountDownLatch committed = new CountDownLatch(1);
    final ForeignExceptionDispatcher monitor = spy(new ForeignExceptionDispatcher());
    final ZKProcedureMemberRpcs controller = new ZKProcedureMemberRpcs(watcher, "testSimple");
    // mock out cohort member callbacks
    final ProcedureMember member = Mockito.mock(ProcedureMember.class);
    Mockito.doReturn(sub).when(member).createSubprocedure(operationName, data);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            controller.sendMemberAcquired(sub);
            prepared.countDown();
            return null;
        }
    }).when(member).submitSubprocedure(sub);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            controller.sendMemberCompleted(sub, memberData);
            committed.countDown();
            return null;
        }
    }).when(member).receivedReachedGlobalBarrier(operationName);
    // start running the listener
    controller.start(COHORT_NODE_NAME, member);
    // set a prepare node from a 'coordinator'
    String prepare = ZKProcedureUtil.getAcquireBarrierNode(controller.getZkController(), operationName);
    ZKUtil.createSetData(watcher, prepare, ProtobufUtil.prependPBMagic(data));
    // wait for the operation to be prepared
    prepared.await();
    // create the commit node so we update the operation to enter the commit phase
    String commit = ZKProcedureUtil.getReachedBarrierNode(controller.getZkController(), operationName);
    LOG.debug("Found prepared, posting commit node:" + commit);
    ZKUtil.createAndFailSilent(watcher, commit);
    LOG.debug("Commit node:" + commit + ", exists:" + ZKUtil.checkExists(watcher, commit));
    committed.await();
    verify(monitor, never()).receive(Mockito.any(ForeignException.class));
    // XXX: broken due to composition.
    //    verify(member, never()).getManager().controllerConnectionFailure(Mockito.anyString(),
    //      Mockito.any(IOException.class));
    // cleanup after the test
    ZKUtil.deleteNodeRecursively(watcher, controller.getZkController().getBaseZnode());
    assertEquals("Didn't delete prepare node", -1, ZKUtil.checkExists(watcher, prepare));
    assertEquals("Didn't delete commit node", -1, ZKUtil.checkExists(watcher, commit));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) Test(org.junit.Test)

Example 8 with ForeignExceptionDispatcher

use of org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher in project hbase by apache.

the class TestProcedure method testSingleMember.

/**
   * With a single member, verify ordered execution.  The Coordinator side is run in a separate
   * thread so we can only trigger from members and wait for particular state latches.
   */
@Test(timeout = 60000)
public void testSingleMember() throws Exception {
    // The member
    List<String> members = new ArrayList<>();
    members.add("member");
    LatchedProcedure proc = new LatchedProcedure(coord, new ForeignExceptionDispatcher(), 100, Integer.MAX_VALUE, "op", null, members);
    final LatchedProcedure procspy = spy(proc);
    // coordinator: start the barrier procedure
    new Thread() {

        public void run() {
            procspy.call();
        }
    }.start();
    // coordinator: wait for the barrier to be acquired, then send start barrier
    proc.startedAcquireBarrier.await();
    // we only know that {@link Procedure#sendStartBarrier()} was called, and others are blocked.
    verify(procspy).sendGlobalBarrierStart();
    verify(procspy, never()).sendGlobalBarrierReached();
    verify(procspy, never()).sendGlobalBarrierComplete();
    verify(procspy, never()).barrierAcquiredByMember(anyString());
    // member: trigger global barrier acquisition
    proc.barrierAcquiredByMember(members.get(0));
    // coordinator: wait for global barrier to be acquired.
    proc.acquiredBarrierLatch.await();
    // old news
    verify(procspy).sendGlobalBarrierStart();
    // since two threads, we cannot guarantee that {@link Procedure#sendSatsifiedBarrier()} was
    // or was not called here.
    // member: trigger global barrier release
    proc.barrierReleasedByMember(members.get(0), new byte[0]);
    // coordinator: wait for procedure to be completed
    proc.completedProcedure.await();
    verify(procspy).sendGlobalBarrierReached();
    verify(procspy).sendGlobalBarrierComplete();
    verify(procspy, never()).receive(any(ForeignException.class));
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) Test(org.junit.Test)

Example 9 with ForeignExceptionDispatcher

use of org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher in project hbase by apache.

the class TestProcedure method testBarrieredErrorPropagation.

@Test(timeout = 60000)
public void testBarrieredErrorPropagation() throws Exception {
    List<String> members = new ArrayList<>();
    members.add("member");
    LatchedProcedure proc = new LatchedProcedure(coord, new ForeignExceptionDispatcher(), 100, Integer.MAX_VALUE, "op", null, members);
    final LatchedProcedure procspy = spy(proc);
    // start the barrier procedure
    Thread t = new Thread() {

        public void run() {
            procspy.call();
        }
    };
    t.start();
    // now test that we can put an error in before the commit phase runs
    procspy.startedAcquireBarrier.await();
    ForeignException cause = new ForeignException("SRC", "External Exception");
    procspy.receive(cause);
    procspy.barrierAcquiredByMember(members.get(0));
    t.join();
    // verify state of all the object
    verify(procspy).sendGlobalBarrierStart();
    verify(procspy).sendGlobalBarrierComplete();
    verify(procspy, never()).sendGlobalBarrierReached();
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) Test(org.junit.Test)

Example 10 with ForeignExceptionDispatcher

use of org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher in project hbase by apache.

the class LogRollMasterProcedureManager method execProcedure.

@Override
public void execProcedure(ProcedureDescription desc) throws IOException {
    if (!isBackupEnabled()) {
        LOG.warn("Backup is not enabled. Check your " + BackupRestoreConstants.BACKUP_ENABLE_KEY + " setting");
        return;
    }
    this.done = false;
    // start the process on the RS
    ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getInstance());
    List<ServerName> serverNames = master.getServerManager().getOnlineServersList();
    List<String> servers = new ArrayList<String>();
    for (ServerName sn : serverNames) {
        servers.add(sn.toString());
    }
    List<NameStringPair> conf = desc.getConfigurationList();
    byte[] data = new byte[0];
    if (conf.size() > 0) {
        // Get backup root path
        data = conf.get(0).getValue().getBytes();
    }
    Procedure proc = coordinator.startProcedure(monitor, desc.getInstance(), data, servers);
    if (proc == null) {
        String msg = "Failed to submit distributed procedure for '" + desc.getInstance() + "'";
        LOG.error(msg);
        throw new IOException(msg);
    }
    try {
        // wait for the procedure to complete. A timer thread is kicked off that should cancel this
        // if it takes too long.
        proc.waitForCompleted();
        LOG.info("Done waiting - exec procedure for " + desc.getInstance());
        LOG.info("Distributed roll log procedure is successful!");
        this.done = true;
    } catch (InterruptedException e) {
        ForeignException ee = new ForeignException("Interrupted while waiting for roll log procdure to finish", e);
        monitor.receive(ee);
        Thread.currentThread().interrupt();
    } catch (ForeignException e) {
        ForeignException ee = new ForeignException("Exception while waiting for roll log procdure to finish", e);
        monitor.receive(ee);
    }
    monitor.rethrowException();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair) ServerName(org.apache.hadoop.hbase.ServerName) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) Procedure(org.apache.hadoop.hbase.procedure.Procedure)

Aggregations

ForeignExceptionDispatcher (org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher)21 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)7 Configuration (org.apache.hadoop.conf.Configuration)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 Path (org.apache.hadoop.fs.Path)3 ServerName (org.apache.hadoop.hbase.ServerName)3 RestoreSnapshotHelper (org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper)3 Pair (org.apache.hadoop.hbase.util.Pair)3 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2