Search in sources :

Example 21 with FlinkRuntimeException

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);
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with FlinkRuntimeException

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;
}
Also used : LatencyTrackingStateFactory(org.apache.flink.runtime.state.metrics.LatencyTrackingStateFactory) TtlStateFactory(org.apache.flink.runtime.state.ttl.TtlStateFactory) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) StateSnapshotTransformer(org.apache.flink.runtime.state.StateSnapshotTransformer) RegisteredKeyValueStateBackendMetaInfo(org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo) Nonnull(javax.annotation.Nonnull)

Example 23 with FlinkRuntimeException

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();
        }
    }
}
Also used : TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) ACLProvider(org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider) CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) ACL(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 24 with FlinkRuntimeException

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);
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Example 25 with FlinkRuntimeException

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);
        }
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) RocksDBException(org.rocksdb.RocksDBException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)78 IOException (java.io.IOException)28 Test (org.junit.Test)13 JobID (org.apache.flink.api.common.JobID)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutionException (java.util.concurrent.ExecutionException)7 Nonnull (javax.annotation.Nonnull)7 Configuration (org.apache.flink.configuration.Configuration)6 Collectors (java.util.stream.Collectors)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobResultStore (org.apache.flink.runtime.highavailability.JobResultStore)4 RocksDBException (org.rocksdb.RocksDBException)4 List (java.util.List)3 Map (java.util.Map)3 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)3 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3