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() + '.'));
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations