Search in sources :

Example 11 with RetriesExhaustedException

use of org.apache.hadoop.hbase.client.RetriesExhaustedException in project hbase by apache.

the class TransitRegionStateProcedure method confirmOpened.

private Flow confirmOpened(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException {
    if (regionNode.isInState(State.OPEN)) {
        retryCounter = null;
        if (lastState == RegionStateTransitionState.REGION_STATE_TRANSITION_CONFIRM_OPENED) {
            // we are the last state, finish
            regionNode.unsetProcedure(this);
            ServerCrashProcedure.updateProgress(env, getParentProcId());
            return Flow.NO_MORE_STATE;
        }
        // It is possible that we arrive here but confirm opened is not the last state, for example,
        // when merging or splitting a region, we unassign the region from a RS and the RS is crashed,
        // then there will be recovered edits for this region, we'd better make the region online
        // again and then unassign it, otherwise we have to fail the merge/split procedure as we may
        // loss data.
        setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_CLOSE);
        return Flow.HAS_MORE_STATE;
    }
    int retries = env.getAssignmentManager().getRegionStates().addToFailedOpen(regionNode).incrementAndGetRetries();
    int maxAttempts = env.getAssignmentManager().getAssignMaxAttempts();
    LOG.info("Retry={} of max={}; {}; {}", retries, maxAttempts, this, regionNode.toShortString());
    if (retries >= maxAttempts) {
        env.getAssignmentManager().regionFailedOpen(regionNode, true);
        setFailure(getClass().getSimpleName(), new RetriesExhaustedException("Max attempts " + env.getAssignmentManager().getAssignMaxAttempts() + " exceeded"));
        regionNode.unsetProcedure(this);
        return Flow.NO_MORE_STATE;
    }
    env.getAssignmentManager().regionFailedOpen(regionNode, false);
    // we failed to assign the region, force a new plan
    forceNewPlan = true;
    regionNode.setRegionLocation(null);
    setNextState(RegionStateTransitionState.REGION_STATE_TRANSITION_GET_ASSIGN_CANDIDATE);
    if (retries > env.getAssignmentManager().getAssignRetryImmediatelyMaxAttempts()) {
        // Throw exception to backoff and retry when failed open too many times
        throw new HBaseIOException("Failed confirm OPEN of " + regionNode + " (remote log may yield more detail on why).");
    } else {
        // Here we do not throw exception because we want to the region to be online ASAP
        return Flow.HAS_MORE_STATE;
    }
}
Also used : RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException)

Example 12 with RetriesExhaustedException

use of org.apache.hadoop.hbase.client.RetriesExhaustedException in project hbase by apache.

the class ReplicationSink method batch.

/**
 * Do the changes and handle the pool
 * @param tableName table to insert into
 * @param allRows list of actions
 * @param batchRowSizeThreshold rowSize threshold for batch mutation
 */
private void batch(TableName tableName, Collection<List<Row>> allRows, int batchRowSizeThreshold) throws IOException {
    if (allRows.isEmpty()) {
        return;
    }
    AsyncTable<?> table = getConnection().getTable(tableName);
    List<Future<?>> futures = new ArrayList<>();
    for (List<Row> rows : allRows) {
        List<List<Row>> batchRows;
        if (rows.size() > batchRowSizeThreshold) {
            batchRows = Lists.partition(rows, batchRowSizeThreshold);
        } else {
            batchRows = Collections.singletonList(rows);
        }
        futures.addAll(batchRows.stream().map(table::batchAll).collect(Collectors.toList()));
    }
    for (Future<?> future : futures) {
        try {
            FutureUtils.get(future);
        } catch (RetriesExhaustedException e) {
            if (e.getCause() instanceof TableNotFoundException) {
                throw new TableNotFoundException("'" + tableName + "'");
            }
            throw e;
        }
    }
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) Row(org.apache.hadoop.hbase.client.Row)

Example 13 with RetriesExhaustedException

use of org.apache.hadoop.hbase.client.RetriesExhaustedException in project hbase by apache.

the class TestAsyncCoprocessorEndpoint method testRegionServerCoprocessorServiceError.

@Test
public void testRegionServerCoprocessorServiceError() throws Exception {
    final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    DummyRegionServerEndpointProtos.DummyRequest request = DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance();
    try {
        admin.<DummyRegionServerEndpointProtos.DummyService.Stub, DummyRegionServerEndpointProtos.DummyResponse>coprocessorService(DummyRegionServerEndpointProtos.DummyService::newStub, (s, c, done) -> s.dummyThrow(c, request, done), serverName).get();
        fail("Should have thrown an exception");
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof RetriesExhaustedException);
        assertTrue(e.getCause().getMessage().contains(WHAT_TO_THROW.getClass().getName().trim()));
    }
}
Also used : TestProtos(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestProtos) TestRpcServiceProtos(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos) DummyService(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyService) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) CoprocessorEnvironment(org.apache.hadoop.hbase.CoprocessorEnvironment) RpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController) TestAsyncAdminBase(org.apache.hadoop.hbase.client.TestAsyncAdminBase) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) HConstants(org.apache.hadoop.hbase.HConstants) Assert.fail(org.junit.Assert.fail) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Parameterized(org.junit.runners.Parameterized) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) Service(org.apache.hbase.thirdparty.com.google.protobuf.Service) Assert.assertTrue(org.junit.Assert.assertTrue) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) FileNotFoundException(java.io.FileNotFoundException) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) DummyRequest(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyRequest) RpcCallback(org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) DummyRegionServerEndpointProtos(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos) DummyResponse(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyResponse) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) DummyService(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyService) DummyRequest(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyRequest) ServerName(org.apache.hadoop.hbase.ServerName) DummyRegionServerEndpointProtos(org.apache.hadoop.hbase.shaded.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) Test(org.junit.Test)

Example 14 with RetriesExhaustedException

use of org.apache.hadoop.hbase.client.RetriesExhaustedException in project hbase by apache.

the class TestRefreshHFilesEndpoint method callRefreshRegionHFilesEndPoint.

private void callRefreshRegionHFilesEndPoint() throws IOException {
    try {
        RefreshHFilesClient refreshHFilesClient = new RefreshHFilesClient(CONF);
        refreshHFilesClient.refreshHFiles(TABLE_NAME);
    } catch (RetriesExhaustedException rex) {
        if (rex.getCause() instanceof IOException) {
            throw new IOException();
        }
    } catch (Throwable ex) {
        LOG.error(ex.toString(), ex);
        fail("Couldn't call the RefreshRegionHFilesEndpoint");
    }
}
Also used : RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) IOException(java.io.IOException) RefreshHFilesClient(org.apache.hadoop.hbase.client.example.RefreshHFilesClient)

Example 15 with RetriesExhaustedException

use of org.apache.hadoop.hbase.client.RetriesExhaustedException in project hbase by apache.

the class ResourceBase method processException.

protected Response processException(Throwable exp) {
    Throwable curr = exp;
    if (accessDeniedClazz != null) {
        // some access denied exceptions are buried
        while (curr != null) {
            if (accessDeniedClazz.isAssignableFrom(curr.getClass())) {
                throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
            }
            curr = curr.getCause();
        }
    }
    // TableNotFound may also be buried one level deep
    if (exp instanceof TableNotFoundException || exp.getCause() instanceof TableNotFoundException) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
    }
    if (exp instanceof NoSuchColumnFamilyException) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
    }
    if (exp instanceof RuntimeException) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT).entity("Bad request" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
    }
    if (exp instanceof RetriesExhaustedException) {
        RetriesExhaustedException retryException = (RetriesExhaustedException) exp;
        processException(retryException.getCause());
    }
    throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)

Aggregations

RetriesExhaustedException (org.apache.hadoop.hbase.client.RetriesExhaustedException)18 Test (org.junit.Test)10 IOException (java.io.IOException)9 SocketTimeoutException (java.net.SocketTimeoutException)5 Get (org.apache.hadoop.hbase.client.Get)4 CallTimeoutException (org.apache.hadoop.hbase.ipc.CallTimeoutException)4 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3 Connection (org.apache.hadoop.hbase.client.Connection)3 Put (org.apache.hadoop.hbase.client.Put)3 Table (org.apache.hadoop.hbase.client.Table)3 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)3 FileNotFoundException (java.io.FileNotFoundException)2 ConnectException (java.net.ConnectException)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)2 TableName (org.apache.hadoop.hbase.TableName)2 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)2 EOFException (java.io.EOFException)1 InterruptedIOException (java.io.InterruptedIOException)1 Socket (java.net.Socket)1