Search in sources :

Example 61 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class RocksDBCachingPriorityQueueSet method deserializeElement.

@Nonnull
private E deserializeElement(@Nonnull byte[] bytes) {
    try {
        final int numPrefixBytes = groupPrefixBytes.length;
        inputView.setBuffer(bytes, numPrefixBytes, bytes.length - numPrefixBytes);
        return byteOrderProducingSerializer.deserialize(inputView);
    } catch (IOException e) {
        throw new FlinkRuntimeException("Error while deserializing the element.", e);
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Example 62 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class RocksStateKeysAndNamespaceIterator method hasNext.

@Override
public boolean hasNext() {
    try {
        while (nextKeyAndNamespace == null && iterator.isValid()) {
            final byte[] keyBytes = iterator.key();
            final K currentKey = deserializeKey(keyBytes, byteArrayDataInputView);
            final N currentNamespace = CompositeKeySerializationUtils.readNamespace(namespaceSerializer, byteArrayDataInputView, ambiguousKeyPossible);
            final Tuple2<K, N> currentKeyAndNamespace = Tuple2.of(currentKey, currentNamespace);
            if (!Objects.equals(previousKeyAndNamespace, currentKeyAndNamespace)) {
                previousKeyAndNamespace = currentKeyAndNamespace;
                nextKeyAndNamespace = currentKeyAndNamespace;
            }
            iterator.next();
        }
    } catch (Exception e) {
        throw new FlinkRuntimeException("Failed to access state [" + state + "]", e);
    }
    return nextKeyAndNamespace != null;
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) NoSuchElementException(java.util.NoSuchElementException)

Example 63 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class CopyOnWriteSkipListStateMapBasicOpTest method testPutWithAllocationFailure.

/**
 * Make sure exception will be thrown with allocation failure rather than swallowed.
 */
@Test
public void testPutWithAllocationFailure() {
    Allocator exceptionalAllocator = new Allocator() {

        @Override
        public long allocate(int size) {
            throw new RuntimeException("Exception on purpose");
        }

        @Override
        public void free(long address) {
        }

        @Override
        @Nullable
        public Chunk getChunkById(int chunkId) {
            return null;
        }

        @Override
        public void close() {
        }
    };
    try (CopyOnWriteSkipListStateMap<Integer, Long, String> stateMap = createEmptyStateMap(0, 0.0f, exceptionalAllocator)) {
        stateMap.put(1, 1L, "test-value");
        fail("Should have thrown exception when space allocation fails");
    } catch (FlinkRuntimeException e) {
    // expected
    }
}
Also used : Allocator(org.apache.flink.runtime.state.heap.space.Allocator) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Test(org.junit.Test)

Example 64 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class RocksDBPriorityQueueSetFactory method tryRegisterPriorityQueueMetaInfo.

@Nonnull
private <T> RocksDBKeyedStateBackend.RocksDbKvStateInfo tryRegisterPriorityQueueMetaInfo(@Nonnull String stateName, @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
    RocksDBKeyedStateBackend.RocksDbKvStateInfo stateInfo = kvStateInformation.get(stateName);
    if (stateInfo == null) {
        // Currently this class is for timer service and TTL feature is not applicable here,
        // so no need to register compact filter when creating column family
        RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo = new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
        stateInfo = RocksDBOperationUtils.createStateInfo(metaInfo, db, columnFamilyOptionsFactory, null, writeBufferManagerCapacity);
        RocksDBOperationUtils.registerKvStateInformation(kvStateInformation, nativeMetricMonitor, stateName, stateInfo);
    } else {
        // TODO we implement the simple way of supporting the current functionality, mimicking
        // keyed state
        // because this should be reworked in FLINK-9376 and then we should have a common
        // algorithm over
        // StateMetaInfoSnapshot that avoids this code duplication.
        @SuppressWarnings("unchecked") RegisteredPriorityQueueStateBackendMetaInfo<T> castedMetaInfo = (RegisteredPriorityQueueStateBackendMetaInfo<T>) stateInfo.metaInfo;
        TypeSerializer<T> previousElementSerializer = castedMetaInfo.getPreviousElementSerializer();
        if (previousElementSerializer != byteOrderedElementSerializer) {
            TypeSerializerSchemaCompatibility<T> compatibilityResult = castedMetaInfo.updateElementSerializer(byteOrderedElementSerializer);
            // migrating them. Therefore, here we only check for incompatibility.
            if (compatibilityResult.isIncompatible()) {
                throw new FlinkRuntimeException(new StateMigrationException("The new priority queue serializer must not be incompatible."));
            }
            // update meta info with new serializer
            stateInfo = new RocksDBKeyedStateBackend.RocksDbKvStateInfo(stateInfo.columnFamilyHandle, new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer));
            kvStateInformation.put(stateName, stateInfo);
        }
    }
    return stateInfo;
}
Also used : StateMigrationException(org.apache.flink.util.StateMigrationException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) RegisteredPriorityQueueStateBackendMetaInfo(org.apache.flink.runtime.state.RegisteredPriorityQueueStateBackendMetaInfo) Nonnull(javax.annotation.Nonnull)

Example 65 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class RocksDBStateDownloader method downloadDataForAllStateHandles.

/**
 * Copies all the files from the given stream state handles to the given path, renaming the
 * files w.r.t. their {@link StateHandleID}.
 */
private void downloadDataForAllStateHandles(Map<StateHandleID, StreamStateHandle> stateHandleMap, Path restoreInstancePath, CloseableRegistry closeableRegistry) throws Exception {
    try {
        List<Runnable> runnables = createDownloadRunnables(stateHandleMap, restoreInstancePath, closeableRegistry);
        List<CompletableFuture<Void>> futures = new ArrayList<>(runnables.size());
        for (Runnable runnable : runnables) {
            futures.add(CompletableFuture.runAsync(runnable, executorService));
        }
        FutureUtils.waitForAll(futures).get();
    } catch (ExecutionException e) {
        Throwable throwable = ExceptionUtils.stripExecutionException(e);
        throwable = ExceptionUtils.stripException(throwable, RuntimeException.class);
        if (throwable instanceof IOException) {
            throw (IOException) throwable;
        } else {
            throw new FlinkRuntimeException("Failed to download data for state handles.", e);
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ThrowingRunnable(org.apache.flink.util.function.ThrowingRunnable) ArrayList(java.util.ArrayList) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

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