Search in sources :

Example 1 with FencingTokenException

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

the class FencedAkkaRpcActor method handleRpcMessage.

@Override
protected void handleRpcMessage(Object message) {
    if (message instanceof FencedMessage) {
        final F expectedFencingToken = rpcEndpoint.getFencingToken();
        if (expectedFencingToken == null) {
            if (log.isDebugEnabled()) {
                log.debug("Fencing token not set: Ignoring message {} because the fencing token is null.", message);
            }
            sendErrorIfSender(new FencingTokenException(String.format("Fencing token not set: Ignoring message %s sent to %s because the fencing token is null.", message, rpcEndpoint.getAddress())));
        } else {
            @SuppressWarnings("unchecked") FencedMessage<F, ?> fencedMessage = ((FencedMessage<F, ?>) message);
            F fencingToken = fencedMessage.getFencingToken();
            if (Objects.equals(expectedFencingToken, fencingToken)) {
                super.handleRpcMessage(fencedMessage.getPayload());
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Fencing token mismatch: Ignoring message {} because the fencing token {} did " + "not match the expected fencing token {}.", message, fencingToken, expectedFencingToken);
                }
                sendErrorIfSender(new FencingTokenException("Fencing token mismatch: Ignoring message " + message + " because the fencing token " + fencingToken + " did not match the expected fencing token " + expectedFencingToken + '.'));
            }
        }
    } else if (message instanceof UnfencedMessage) {
        super.handleRpcMessage(((UnfencedMessage<?>) message).getPayload());
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Unknown message type: Ignoring message {} because it is neither of type {} nor {}.", message, FencedMessage.class.getSimpleName(), UnfencedMessage.class.getSimpleName());
        }
        sendErrorIfSender(new AkkaUnknownMessageException("Unknown message type: Ignoring message " + message + " of type " + message.getClass().getSimpleName() + " because it is neither of type " + FencedMessage.class.getSimpleName() + " nor " + UnfencedMessage.class.getSimpleName() + '.'));
    }
}
Also used : AkkaUnknownMessageException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaUnknownMessageException) LocalFencedMessage(org.apache.flink.runtime.rpc.messages.LocalFencedMessage) FencedMessage(org.apache.flink.runtime.rpc.messages.FencedMessage) FencingTokenException(org.apache.flink.runtime.rpc.exceptions.FencingTokenException) UnfencedMessage(org.apache.flink.runtime.rpc.messages.UnfencedMessage)

Example 2 with FencingTokenException

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

the class AsyncCallsTest method testCallAsyncWithFencing.

/**
 * Tests that async callables are not executed if the fencing token changes.
 */
@Test
public void testCallAsyncWithFencing() throws Exception {
    final UUID newFencingToken = UUID.randomUUID();
    CompletableFuture<Boolean> resultFuture = testRunAsync(endpoint -> endpoint.callAsync(() -> true, timeout), newFencingToken);
    try {
        resultFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
        fail("The async call operation should fail due to the changed fencing token.");
    } catch (ExecutionException e) {
        assertTrue(ExceptionUtils.stripExecutionException(e) instanceof FencingTokenException);
    }
}
Also used : FencingTokenException(org.apache.flink.runtime.rpc.exceptions.FencingTokenException) UUID(java.util.UUID) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with FencingTokenException

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

the class FencedRpcEndpointTest method testRemoteAndSelfGateways.

/**
 * Tests that the self gateway always uses the current fencing token whereas the remote gateway
 * has a fixed fencing token.
 */
@Test
public void testRemoteAndSelfGateways() throws Exception {
    final UUID initialFencingToken = UUID.randomUUID();
    final UUID newFencingToken = UUID.randomUUID();
    final String value = "foobar";
    final FencedTestingEndpoint fencedTestingEndpoint = new FencedTestingEndpoint(rpcService, value, initialFencingToken);
    try {
        fencedTestingEndpoint.start();
        FencedTestingGateway selfGateway = fencedTestingEndpoint.getSelfGateway(FencedTestingGateway.class);
        FencedTestingGateway remoteGateway = rpcService.connect(fencedTestingEndpoint.getAddress(), initialFencingToken, FencedTestingGateway.class).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
        assertEquals(initialFencingToken, selfGateway.getFencingToken());
        assertEquals(initialFencingToken, remoteGateway.getFencingToken());
        assertEquals(value, selfGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS));
        assertEquals(value, remoteGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS));
        CompletableFuture<Acknowledge> newFencingTokenFuture = fencedTestingEndpoint.setFencingTokenInMainThread(newFencingToken, timeout);
        // wait for the new fencing token to be set
        newFencingTokenFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
        assertEquals(newFencingToken, selfGateway.getFencingToken());
        assertNotEquals(newFencingToken, remoteGateway.getFencingToken());
        assertEquals(value, selfGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS));
        try {
            remoteGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
            fail("This should have failed because we don't have the right fencing token.");
        } catch (ExecutionException e) {
            assertTrue(ExceptionUtils.stripExecutionException(e) instanceof FencingTokenException);
        }
    } finally {
        RpcUtils.terminateRpcEndpoint(fencedTestingEndpoint, timeout);
    }
}
Also used : Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FencingTokenException(org.apache.flink.runtime.rpc.exceptions.FencingTokenException) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with FencingTokenException

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

the class FencedRpcEndpointTest method testFencing.

/**
 * Tests that messages with the wrong fencing token are filtered out.
 */
@Test
public void testFencing() throws Exception {
    final UUID fencingToken = UUID.randomUUID();
    final UUID wrongFencingToken = UUID.randomUUID();
    final String value = "barfoo";
    FencedTestingEndpoint fencedTestingEndpoint = new FencedTestingEndpoint(rpcService, value, fencingToken);
    try {
        fencedTestingEndpoint.start();
        final FencedTestingGateway properFencedGateway = rpcService.connect(fencedTestingEndpoint.getAddress(), fencingToken, FencedTestingGateway.class).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
        final FencedTestingGateway wronglyFencedGateway = rpcService.connect(fencedTestingEndpoint.getAddress(), wrongFencingToken, FencedTestingGateway.class).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
        assertEquals(value, properFencedGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS));
        try {
            wronglyFencedGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
            fail("This should fail since we have the wrong fencing token.");
        } catch (ExecutionException e) {
            assertTrue(ExceptionUtils.stripExecutionException(e) instanceof FencingTokenException);
        }
        final UUID newFencingToken = UUID.randomUUID();
        CompletableFuture<Acknowledge> newFencingTokenFuture = fencedTestingEndpoint.setFencingTokenInMainThread(newFencingToken, timeout);
        // wait for the new fencing token to be set
        newFencingTokenFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
        // this should no longer work because of the new fencing token
        try {
            properFencedGateway.foobar(timeout).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
            fail("This should fail since we have the wrong fencing token by now.");
        } catch (ExecutionException e) {
            assertTrue(ExceptionUtils.stripExecutionException(e) instanceof FencingTokenException);
        }
    } finally {
        RpcUtils.terminateRpcEndpoint(fencedTestingEndpoint, timeout);
    }
}
Also used : Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FencingTokenException(org.apache.flink.runtime.rpc.exceptions.FencingTokenException) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

FencingTokenException (org.apache.flink.runtime.rpc.exceptions.FencingTokenException)4 UUID (java.util.UUID)3 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.Test)3 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AkkaUnknownMessageException (org.apache.flink.runtime.rpc.akka.exceptions.AkkaUnknownMessageException)1 FencedMessage (org.apache.flink.runtime.rpc.messages.FencedMessage)1 LocalFencedMessage (org.apache.flink.runtime.rpc.messages.LocalFencedMessage)1 UnfencedMessage (org.apache.flink.runtime.rpc.messages.UnfencedMessage)1