Search in sources :

Example 1 with RpcException

use of org.apache.flink.runtime.rpc.exceptions.RpcException in project flink by apache.

the class CheckpointCoordinatorTest method testTasksFinishDuringTriggering.

@Test
public void testTasksFinishDuringTriggering() throws Exception {
    JobVertexID jobVertexID1 = new JobVertexID();
    JobVertexID jobVertexID2 = new JobVertexID();
    ExecutionGraph graph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().setTransitToRunning(false).addJobVertex(jobVertexID1, 1, 256).addJobVertex(jobVertexID2, 1, 256).build();
    ExecutionJobVertex jobVertex1 = graph.getJobVertex(jobVertexID1);
    ExecutionVertex taskVertex = jobVertex1.getTaskVertices()[0];
    ExecutionJobVertex jobVertex2 = graph.getJobVertex(jobVertexID2);
    ExecutionVertex taskVertex2 = jobVertex2.getTaskVertices()[0];
    AtomicBoolean checkpointAborted = new AtomicBoolean(false);
    LogicalSlot slot1 = new TestingLogicalSlotBuilder().setTaskManagerGateway(new SimpleAckingTaskManagerGateway() {

        @Override
        public CompletableFuture<Acknowledge> triggerCheckpoint(ExecutionAttemptID executionAttemptID, JobID jobId, long checkpointId, long timestamp, CheckpointOptions checkpointOptions) {
            taskVertex.getCurrentExecutionAttempt().markFinished();
            return FutureUtils.completedExceptionally(new RpcException(""));
        }
    }).createTestingLogicalSlot();
    LogicalSlot slot2 = new TestingLogicalSlotBuilder().setTaskManagerGateway(new SimpleAckingTaskManagerGateway() {

        @Override
        public void notifyCheckpointAborted(ExecutionAttemptID executionAttemptID, JobID jobId, long checkpointId, long latestCompletedCheckpointId, long timestamp) {
            checkpointAborted.set(true);
        }
    }).createTestingLogicalSlot();
    ExecutionGraphTestUtils.setVertexResource(taskVertex, slot1);
    taskVertex.getCurrentExecutionAttempt().transitionState(ExecutionState.RUNNING);
    ExecutionGraphTestUtils.setVertexResource(taskVertex2, slot2);
    taskVertex2.getCurrentExecutionAttempt().transitionState(ExecutionState.RUNNING);
    CheckpointCoordinator checkpointCoordinator = new CheckpointCoordinatorBuilder().setExecutionGraph(graph).setTimer(manuallyTriggeredScheduledExecutor).setAllowCheckpointsAfterTasksFinished(true).build();
    // nothing should be happening
    assertEquals(0, checkpointCoordinator.getNumberOfPendingCheckpoints());
    assertEquals(0, checkpointCoordinator.getNumberOfRetainedSuccessfulCheckpoints());
    // trigger the first checkpoint. this will not fail because we allow checkpointing even with
    // finished tasks
    final CompletableFuture<CompletedCheckpoint> checkpointFuture = checkpointCoordinator.triggerCheckpoint(false);
    manuallyTriggeredScheduledExecutor.triggerAll();
    assertTrue(checkpointFuture.isCompletedExceptionally());
    assertTrue(checkpointAborted.get());
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) CheckpointCoordinatorBuilder(org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleAckingTaskManagerGateway(org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) RpcException(org.apache.flink.runtime.rpc.exceptions.RpcException) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 2 with RpcException

use of org.apache.flink.runtime.rpc.exceptions.RpcException in project flink by apache.

the class AkkaInvocationHandler method invokeRpc.

// ------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------
/**
 * Invokes a RPC method by sending the RPC invocation details to the rpc endpoint.
 *
 * @param method to call
 * @param args of the method call
 * @return result of the RPC; the result future is completed with a {@link TimeoutException} if
 *     the requests times out; if the recipient is not reachable, then the result future is
 *     completed with a {@link RecipientUnreachableException}.
 * @throws Exception if the RPC invocation fails
 */
private Object invokeRpc(Method method, Object[] args) throws Exception {
    String methodName = method.getName();
    Class<?>[] parameterTypes = method.getParameterTypes();
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    Time futureTimeout = extractRpcTimeout(parameterAnnotations, args, timeout);
    final RpcInvocation rpcInvocation = createRpcInvocationMessage(method.getDeclaringClass().getSimpleName(), methodName, parameterTypes, args);
    Class<?> returnType = method.getReturnType();
    final Object result;
    if (Objects.equals(returnType, Void.TYPE)) {
        tell(rpcInvocation);
        result = null;
    } else {
        // Capture the call stack. It is significantly faster to do that via an exception than
        // via Thread.getStackTrace(), because exceptions lazily initialize the stack trace,
        // initially only
        // capture a lightweight native pointer, and convert that into the stack trace lazily
        // when needed.
        final Throwable callStackCapture = captureAskCallStack ? new Throwable() : null;
        // execute an asynchronous call
        final CompletableFuture<?> resultFuture = ask(rpcInvocation, futureTimeout).thenApply(resultValue -> deserializeValueIfNeeded(resultValue, method, flinkClassLoader));
        final CompletableFuture<Object> completableFuture = new CompletableFuture<>();
        resultFuture.whenComplete((resultValue, failure) -> {
            if (failure != null) {
                completableFuture.completeExceptionally(resolveTimeoutException(ExceptionUtils.stripCompletionException(failure), callStackCapture, address, rpcInvocation));
            } else {
                completableFuture.complete(resultValue);
            }
        });
        if (Objects.equals(returnType, CompletableFuture.class)) {
            result = completableFuture;
        } else {
            try {
                result = completableFuture.get(futureTimeout.getSize(), futureTimeout.getUnit());
            } catch (ExecutionException ee) {
                throw new RpcException("Failure while obtaining synchronous RPC result.", ExceptionUtils.stripExecutionException(ee));
            }
        }
    }
    return result;
}
Also used : LocalRpcInvocation(org.apache.flink.runtime.rpc.messages.LocalRpcInvocation) RemoteRpcInvocation(org.apache.flink.runtime.rpc.messages.RemoteRpcInvocation) RpcInvocation(org.apache.flink.runtime.rpc.messages.RpcInvocation) Time(org.apache.flink.api.common.time.Time) CompletableFuture(java.util.concurrent.CompletableFuture) RpcException(org.apache.flink.runtime.rpc.exceptions.RpcException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

RpcException (org.apache.flink.runtime.rpc.exceptions.RpcException)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JobID (org.apache.flink.api.common.JobID)1 Time (org.apache.flink.api.common.time.Time)1 CheckpointCoordinatorBuilder (org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder)1 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)1 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)1 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)1 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)1 SimpleAckingTaskManagerGateway (org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)1 TestingLogicalSlotBuilder (org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder)1 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)1 LocalRpcInvocation (org.apache.flink.runtime.rpc.messages.LocalRpcInvocation)1 RemoteRpcInvocation (org.apache.flink.runtime.rpc.messages.RemoteRpcInvocation)1 RpcInvocation (org.apache.flink.runtime.rpc.messages.RpcInvocation)1 Test (org.junit.Test)1