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);
}
}
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;
}
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
}
}
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;
}
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);
}
}
}
Aggregations