Search in sources :

Example 1 with StreamCompressionDecorator

use of org.apache.flink.runtime.state.StreamCompressionDecorator in project flink by apache.

the class StateChangeFsUploader method wrap.

private OutputStreamWithPos wrap(FSDataOutputStream fsStream) throws IOException {
    StreamCompressionDecorator instance = compression ? SnappyStreamCompressionDecorator.INSTANCE : UncompressedStreamCompressionDecorator.INSTANCE;
    OutputStream compressed = compression ? instance.decorateWithCompression(fsStream) : fsStream;
    return new OutputStreamWithPos(new BufferedOutputStream(compressed, bufferSize));
}
Also used : UncompressedStreamCompressionDecorator(org.apache.flink.runtime.state.UncompressedStreamCompressionDecorator) SnappyStreamCompressionDecorator(org.apache.flink.runtime.state.SnappyStreamCompressionDecorator) StreamCompressionDecorator(org.apache.flink.runtime.state.StreamCompressionDecorator) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FSDataOutputStream(org.apache.flink.core.fs.FSDataOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with StreamCompressionDecorator

use of org.apache.flink.runtime.state.StreamCompressionDecorator in project flink by apache.

the class HeapRestoreOperation method readStateHandleStateData.

private void readStateHandleStateData(FSDataInputStream fsDataInputStream, DataInputViewStreamWrapper inView, KeyGroupRangeOffsets keyGroupOffsets, Map<Integer, StateMetaInfoSnapshot> kvStatesById, int numStates, int readVersion, boolean isCompressed) throws IOException {
    final StreamCompressionDecorator streamCompressionDecorator = isCompressed ? SnappyStreamCompressionDecorator.INSTANCE : UncompressedStreamCompressionDecorator.INSTANCE;
    for (Tuple2<Integer, Long> groupOffset : keyGroupOffsets) {
        int keyGroupIndex = groupOffset.f0;
        long offset = groupOffset.f1;
        if (!keyGroupRange.contains(keyGroupIndex)) {
            LOG.debug("Key group {} doesn't belong to this backend with key group range: {}", keyGroupIndex, keyGroupRange);
            continue;
        }
        fsDataInputStream.seek(offset);
        int writtenKeyGroupIndex = inView.readInt();
        Preconditions.checkState(writtenKeyGroupIndex == keyGroupIndex, "Unexpected key-group in restore.");
        try (InputStream kgCompressionInStream = streamCompressionDecorator.decorateWithCompression(fsDataInputStream)) {
            readKeyGroupStateData(kgCompressionInStream, kvStatesById, keyGroupIndex, numStates, readVersion);
        }
    }
}
Also used : StreamCompressionDecorator(org.apache.flink.runtime.state.StreamCompressionDecorator) UncompressedStreamCompressionDecorator(org.apache.flink.runtime.state.UncompressedStreamCompressionDecorator) SnappyStreamCompressionDecorator(org.apache.flink.runtime.state.SnappyStreamCompressionDecorator) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) InputStream(java.io.InputStream)

Example 3 with StreamCompressionDecorator

use of org.apache.flink.runtime.state.StreamCompressionDecorator in project flink by apache.

the class EmbeddedRocksDBStateBackend method createKeyedStateBackend.

@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(Environment env, JobID jobID, String operatorIdentifier, TypeSerializer<K> keySerializer, int numberOfKeyGroups, KeyGroupRange keyGroupRange, TaskKvStateRegistry kvStateRegistry, TtlTimeProvider ttlTimeProvider, MetricGroup metricGroup, @Nonnull Collection<KeyedStateHandle> stateHandles, CloseableRegistry cancelStreamRegistry, double managedMemoryFraction) throws IOException {
    // first, make sure that the RocksDB JNI library is loaded
    // we do this explicitly here to have better error handling
    String tempDir = env.getTaskManagerInfo().getTmpWorkingDirectory().getAbsolutePath();
    ensureRocksDBIsLoaded(tempDir);
    // replace all characters that are not legal for filenames with underscore
    String fileCompatibleIdentifier = operatorIdentifier.replaceAll("[^a-zA-Z0-9\\-]", "_");
    lazyInitializeForJob(env, fileCompatibleIdentifier);
    File instanceBasePath = new File(getNextStoragePath(), "job_" + jobId + "_op_" + fileCompatibleIdentifier + "_uuid_" + UUID.randomUUID());
    LocalRecoveryConfig localRecoveryConfig = env.getTaskStateManager().createLocalRecoveryConfig();
    final OpaqueMemoryResource<RocksDBSharedResources> sharedResources = RocksDBOperationUtils.allocateSharedCachesIfConfigured(memoryConfiguration, env.getMemoryManager(), managedMemoryFraction, LOG);
    if (sharedResources != null) {
        LOG.info("Obtained shared RocksDB cache of size {} bytes", sharedResources.getSize());
    }
    final RocksDBResourceContainer resourceContainer = createOptionsAndResourceContainer(sharedResources);
    ExecutionConfig executionConfig = env.getExecutionConfig();
    StreamCompressionDecorator keyGroupCompressionDecorator = getCompressionDecorator(executionConfig);
    LatencyTrackingStateConfig latencyTrackingStateConfig = latencyTrackingConfigBuilder.setMetricGroup(metricGroup).build();
    RocksDBKeyedStateBackendBuilder<K> builder = new RocksDBKeyedStateBackendBuilder<>(operatorIdentifier, env.getUserCodeClassLoader().asClassLoader(), instanceBasePath, resourceContainer, stateName -> resourceContainer.getColumnOptions(), kvStateRegistry, keySerializer, numberOfKeyGroups, keyGroupRange, executionConfig, localRecoveryConfig, getPriorityQueueStateType(), ttlTimeProvider, latencyTrackingStateConfig, metricGroup, stateHandles, keyGroupCompressionDecorator, cancelStreamRegistry).setEnableIncrementalCheckpointing(isIncrementalCheckpointsEnabled()).setNumberOfTransferingThreads(getNumberOfTransferThreads()).setNativeMetricOptions(resourceContainer.getMemoryWatcherOptions(defaultMetricOptions)).setWriteBatchSize(getWriteBatchSize());
    return builder.build();
}
Also used : StreamCompressionDecorator(org.apache.flink.runtime.state.StreamCompressionDecorator) LatencyTrackingStateConfig(org.apache.flink.runtime.state.metrics.LatencyTrackingStateConfig) LocalRecoveryConfig(org.apache.flink.runtime.state.LocalRecoveryConfig) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) File(java.io.File)

Aggregations

StreamCompressionDecorator (org.apache.flink.runtime.state.StreamCompressionDecorator)3 SnappyStreamCompressionDecorator (org.apache.flink.runtime.state.SnappyStreamCompressionDecorator)2 UncompressedStreamCompressionDecorator (org.apache.flink.runtime.state.UncompressedStreamCompressionDecorator)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 FSDataOutputStream (org.apache.flink.core.fs.FSDataOutputStream)1 LocalRecoveryConfig (org.apache.flink.runtime.state.LocalRecoveryConfig)1 LatencyTrackingStateConfig (org.apache.flink.runtime.state.metrics.LatencyTrackingStateConfig)1