use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.
the class SourceCoordinatorContext method callInCoordinatorThread.
/**
* A helper method that delegates the callable to the coordinator thread if the current thread
* is not the coordinator thread, otherwise call the callable right away.
*
* @param callable the callable to delegate.
*/
private <V> V callInCoordinatorThread(Callable<V> callable, String errorMessage) {
// Ensure the split assignment is done by the coordinator executor.
if (!coordinatorThreadFactory.isCurrentThreadCoordinatorThread()) {
try {
final Callable<V> guardedCallable = () -> {
try {
return callable.call();
} catch (Throwable t) {
LOG.error("Uncaught Exception in Source Coordinator Executor", t);
ExceptionUtils.rethrowException(t);
return null;
}
};
return coordinatorExecutor.submit(guardedCallable).get();
} catch (InterruptedException | ExecutionException e) {
throw new FlinkRuntimeException(errorMessage, e);
}
}
try {
return callable.call();
} catch (Throwable t) {
LOG.error("Uncaught Exception in Source Coordinator Executor", t);
throw new FlinkRuntimeException(errorMessage, t);
}
}
use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.
the class ChangelogKeyedStateBackend method createInternalState.
@Nonnull
@Override
@SuppressWarnings("unchecked")
public <N, SV, SEV, S extends State, IS extends S> IS createInternalState(@Nonnull TypeSerializer<N> namespaceSerializer, @Nonnull StateDescriptor<S, SV> stateDesc, @Nonnull StateSnapshotTransformer.StateSnapshotTransformFactory<SEV> snapshotTransformFactory) throws Exception {
StateFactory stateFactory = STATE_FACTORIES.get(stateDesc.getType());
if (stateFactory == null) {
String message = String.format("State %s is not supported by %s", stateDesc.getClass(), this.getClass());
throw new FlinkRuntimeException(message);
}
RegisteredKeyValueStateBackendMetaInfo<N, SV> meta = new RegisteredKeyValueStateBackendMetaInfo<>(stateDesc.getType(), stateDesc.getName(), namespaceSerializer, stateDesc.getSerializer(), (StateSnapshotTransformer.StateSnapshotTransformFactory<SV>) snapshotTransformFactory);
InternalKvState<K, N, SV> state = keyedStateBackend.createInternalState(namespaceSerializer, stateDesc, snapshotTransformFactory);
KvStateChangeLoggerImpl<K, SV, N> kvStateChangeLogger = new KvStateChangeLoggerImpl<>(state.getKeySerializer(), state.getNamespaceSerializer(), state.getValueSerializer(), keyedStateBackend.getKeyContext(), stateChangelogWriter, meta, stateDesc.getTtlConfig(), stateDesc.getDefaultValue(), ++lastCreatedStateId);
closer.register(kvStateChangeLogger);
IS is = stateFactory.create(state, kvStateChangeLogger, keyedStateBackend);
changelogStates.put(stateDesc.getName(), (ChangelogState) is);
return is;
}
use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.
the class ZooKeeperLeaderElectionTest method testUnExpectedErrorForwarding.
/**
* Test that background errors in the {@link LeaderElectionDriver} are correctly forwarded to
* the {@link FatalErrorHandler}.
*/
@Test
public void testUnExpectedErrorForwarding() throws Exception {
LeaderElectionDriver leaderElectionDriver = null;
final TestingLeaderElectionEventHandler electionEventHandler = new TestingLeaderElectionEventHandler(LEADER_ADDRESS);
final TestingFatalErrorHandler fatalErrorHandler = new TestingFatalErrorHandler();
final FlinkRuntimeException testException = new FlinkRuntimeException("testUnExpectedErrorForwarding");
final CuratorFrameworkFactory.Builder curatorFrameworkBuilder = CuratorFrameworkFactory.builder().connectString(testingServer.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 0)).aclProvider(new ACLProvider() {
// trigger background exception
@Override
public List<ACL> getDefaultAcl() {
throw testException;
}
@Override
public List<ACL> getAclForPath(String s) {
throw testException;
}
}).namespace("flink");
try (CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper = ZooKeeperUtils.startCuratorFramework(curatorFrameworkBuilder, fatalErrorHandler)) {
CuratorFramework clientWithErrorHandler = curatorFrameworkWrapper.asCuratorFramework();
assertFalse(fatalErrorHandler.getErrorFuture().isDone());
leaderElectionDriver = createAndInitLeaderElectionDriver(clientWithErrorHandler, electionEventHandler);
assertThat(fatalErrorHandler.getErrorFuture().join(), FlinkMatchers.containsCause(testException));
} finally {
electionEventHandler.close();
if (leaderElectionDriver != null) {
leaderElectionDriver.close();
}
}
}
use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.
the class RocksDBCachingPriorityQueueSet method serializeElement.
@Nonnull
private byte[] serializeElement(@Nonnull E element) {
try {
outputView.clear();
outputView.write(groupPrefixBytes);
byteOrderProducingSerializer.serialize(element, outputView);
return outputView.getCopyOfBuffer();
} catch (IOException e) {
throw new FlinkRuntimeException("Error while serializing the element.", e);
}
}
use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.
the class RocksDBCachingPriorityQueueSet method checkRefillCacheFromStore.
private void checkRefillCacheFromStore() {
if (!allElementsInCache && orderedCache.isEmpty()) {
try (final RocksBytesIterator iterator = orderedBytesIterator()) {
orderedCache.bulkLoadFromOrderedIterator(iterator);
allElementsInCache = !iterator.hasNext();
} catch (Exception e) {
throw new FlinkRuntimeException("Exception while refilling store from iterator.", e);
}
}
}
Aggregations