Search in sources :

Example 16 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class OrcBulkWriterFactory method getWriterOptions.

@VisibleForTesting
protected OrcFile.WriterOptions getWriterOptions() {
    if (null == writerOptions) {
        Configuration conf = new ThreadLocalClassLoaderConfiguration();
        for (Map.Entry<String, String> entry : confMap.entrySet()) {
            conf.set(entry.getKey(), entry.getValue());
        }
        writerOptions = OrcFile.writerOptions(writerProperties, conf);
        writerOptions.setSchema(this.vectorizer.getSchema());
    }
    return writerOptions;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Map(java.util.Map) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 17 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class ResultPartitionFactory method create.

@VisibleForTesting
public ResultPartition create(String taskNameWithSubtaskAndId, int partitionIndex, ResultPartitionID id, ResultPartitionType type, int numberOfSubpartitions, int maxParallelism, SupplierWithException<BufferPool, IOException> bufferPoolFactory) {
    BufferCompressor bufferCompressor = null;
    if (type.isBlocking() && blockingShuffleCompressionEnabled) {
        bufferCompressor = new BufferCompressor(networkBufferSize, compressionCodec);
    }
    ResultSubpartition[] subpartitions = new ResultSubpartition[numberOfSubpartitions];
    final ResultPartition partition;
    if (type == ResultPartitionType.PIPELINED || type == ResultPartitionType.PIPELINED_BOUNDED || type == ResultPartitionType.PIPELINED_APPROXIMATE) {
        final PipelinedResultPartition pipelinedPartition = new PipelinedResultPartition(taskNameWithSubtaskAndId, partitionIndex, id, type, subpartitions, maxParallelism, partitionManager, bufferCompressor, bufferPoolFactory);
        for (int i = 0; i < subpartitions.length; i++) {
            if (type == ResultPartitionType.PIPELINED_APPROXIMATE) {
                subpartitions[i] = new PipelinedApproximateSubpartition(i, configuredNetworkBuffersPerChannel, pipelinedPartition);
            } else {
                subpartitions[i] = new PipelinedSubpartition(i, configuredNetworkBuffersPerChannel, pipelinedPartition);
            }
        }
        partition = pipelinedPartition;
    } else if (type == ResultPartitionType.BLOCKING || type == ResultPartitionType.BLOCKING_PERSISTENT) {
        if (numberOfSubpartitions >= sortShuffleMinParallelism) {
            partition = new SortMergeResultPartition(taskNameWithSubtaskAndId, partitionIndex, id, type, subpartitions.length, maxParallelism, batchShuffleReadBufferPool, batchShuffleReadIOExecutor, partitionManager, channelManager.createChannel().getPath(), bufferCompressor, bufferPoolFactory);
        } else {
            final BoundedBlockingResultPartition blockingPartition = new BoundedBlockingResultPartition(taskNameWithSubtaskAndId, partitionIndex, id, type, subpartitions, maxParallelism, partitionManager, bufferCompressor, bufferPoolFactory);
            initializeBoundedBlockingPartitions(subpartitions, blockingPartition, blockingSubpartitionType, networkBufferSize, channelManager, sslEnabled);
            partition = blockingPartition;
        }
    } else {
        throw new IllegalArgumentException("Unrecognized ResultPartitionType: " + type);
    }
    LOG.debug("{}: Initialized {}", taskNameWithSubtaskAndId, this);
    return partition;
}
Also used : BufferCompressor(org.apache.flink.runtime.io.network.buffer.BufferCompressor) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 18 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class NettyShuffleServiceFactory method createNettyShuffleEnvironment.

@VisibleForTesting
static NettyShuffleEnvironment createNettyShuffleEnvironment(NettyShuffleEnvironmentConfiguration config, ResourceID taskExecutorResourceId, TaskEventPublisher taskEventPublisher, ResultPartitionManager resultPartitionManager, MetricGroup metricGroup, Executor ioExecutor) {
    checkNotNull(config);
    checkNotNull(taskExecutorResourceId);
    checkNotNull(taskEventPublisher);
    checkNotNull(resultPartitionManager);
    checkNotNull(metricGroup);
    NettyConfig nettyConfig = config.nettyConfig();
    FileChannelManager fileChannelManager = new FileChannelManagerImpl(config.getTempDirs(), DIR_NAME_PREFIX);
    if (LOG.isInfoEnabled()) {
        LOG.info("Created a new {} for storing result partitions of BLOCKING shuffles. Used directories:\n\t{}", FileChannelManager.class.getSimpleName(), Arrays.stream(fileChannelManager.getPaths()).map(File::getAbsolutePath).collect(Collectors.joining("\n\t")));
    }
    ConnectionManager connectionManager = nettyConfig != null ? new NettyConnectionManager(resultPartitionManager, taskEventPublisher, nettyConfig, config.getMaxNumberOfConnections(), config.isConnectionReuseEnabled()) : new LocalConnectionManager();
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(config.numNetworkBuffers(), config.networkBufferSize(), config.getRequestSegmentsTimeout());
    // we create a separated buffer pool here for batch shuffle instead of reusing the network
    // buffer pool directly to avoid potential side effects of memory contention, for example,
    // dead lock or "insufficient network buffer" error
    BatchShuffleReadBufferPool batchShuffleReadBufferPool = new BatchShuffleReadBufferPool(config.batchShuffleReadMemoryBytes(), config.networkBufferSize());
    // we create a separated IO executor pool here for batch shuffle instead of reusing the
    // TaskManager IO executor pool directly to avoid the potential side effects of execution
    // contention, for example, too long IO or waiting time leading to starvation or timeout
    ExecutorService batchShuffleReadIOExecutor = Executors.newFixedThreadPool(Math.max(1, Math.min(batchShuffleReadBufferPool.getMaxConcurrentRequests(), 4 * Hardware.getNumberCPUCores())), new ExecutorThreadFactory("blocking-shuffle-io"));
    registerShuffleMetrics(metricGroup, networkBufferPool);
    ResultPartitionFactory resultPartitionFactory = new ResultPartitionFactory(resultPartitionManager, fileChannelManager, networkBufferPool, batchShuffleReadBufferPool, batchShuffleReadIOExecutor, config.getBlockingSubpartitionType(), config.networkBuffersPerChannel(), config.floatingNetworkBuffersPerGate(), config.networkBufferSize(), config.isBlockingShuffleCompressionEnabled(), config.getCompressionCodec(), config.getMaxBuffersPerChannel(), config.sortShuffleMinBuffers(), config.sortShuffleMinParallelism(), config.isSSLEnabled());
    SingleInputGateFactory singleInputGateFactory = new SingleInputGateFactory(taskExecutorResourceId, config, connectionManager, resultPartitionManager, taskEventPublisher, networkBufferPool);
    return new NettyShuffleEnvironment(taskExecutorResourceId, config, networkBufferPool, connectionManager, resultPartitionManager, fileChannelManager, resultPartitionFactory, singleInputGateFactory, ioExecutor, batchShuffleReadBufferPool, batchShuffleReadIOExecutor);
}
Also used : BatchShuffleReadBufferPool(org.apache.flink.runtime.io.disk.BatchShuffleReadBufferPool) NettyConfig(org.apache.flink.runtime.io.network.netty.NettyConfig) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) FileChannelManager(org.apache.flink.runtime.io.disk.FileChannelManager) FileChannelManagerImpl(org.apache.flink.runtime.io.disk.FileChannelManagerImpl) NettyConnectionManager(org.apache.flink.runtime.io.network.netty.NettyConnectionManager) ResultPartitionFactory(org.apache.flink.runtime.io.network.partition.ResultPartitionFactory) ExecutorService(java.util.concurrent.ExecutorService) SingleInputGateFactory(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateFactory) NettyConnectionManager(org.apache.flink.runtime.io.network.netty.NettyConnectionManager) File(java.io.File) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 19 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class BufferDecompressor method decompressToOriginalBuffer.

/**
 * The difference between this method and {@link #decompressToIntermediateBuffer(Buffer)} is
 * that this method copies the decompressed data to the input {@link Buffer} starting from
 * offset 0.
 *
 * <p>The caller must guarantee that the input {@link Buffer} is writable and there's enough
 * space left.
 */
@VisibleForTesting
public Buffer decompressToOriginalBuffer(Buffer buffer) {
    int decompressedLen = decompress(buffer);
    // copy the decompressed data back
    int memorySegmentOffset = buffer.getMemorySegmentOffset();
    MemorySegment segment = buffer.getMemorySegment();
    segment.put(memorySegmentOffset, internalBuffer.array(), 0, decompressedLen);
    return new ReadOnlySlicedNetworkBuffer(buffer.asByteBuf(), 0, decompressedLen, memorySegmentOffset, false);
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 20 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class ZooKeeperUtils method startCuratorFramework.

/**
 * Starts a {@link CuratorFramework} instance and connects it to the given ZooKeeper quorum from
 * a builder.
 *
 * @param builder {@link CuratorFrameworkFactory.Builder} A builder for curatorFramework.
 * @param fatalErrorHandler {@link FatalErrorHandler} fatalErrorHandler to handle unexpected
 *     errors of {@link CuratorFramework}
 * @return {@link CuratorFrameworkWithUnhandledErrorListener} instance
 */
@VisibleForTesting
public static CuratorFrameworkWithUnhandledErrorListener startCuratorFramework(CuratorFrameworkFactory.Builder builder, FatalErrorHandler fatalErrorHandler) {
    CuratorFramework cf = builder.build();
    UnhandledErrorListener unhandledErrorListener = (message, throwable) -> {
        LOG.error("Unhandled error in curator framework, error message: {}", message, throwable);
        // The exception thrown in UnhandledErrorListener will be caught by
        // CuratorFramework. So we mostly trigger exit process or interact with main
        // thread to inform the failure in FatalErrorHandler.
        fatalErrorHandler.onFatalError(throwable);
    };
    cf.getUnhandledErrorListenable().addListener(unhandledErrorListener);
    cf.start();
    return new CuratorFrameworkWithUnhandledErrorListener(cf, unhandledErrorListener);
}
Also used : SecurityOptions(org.apache.flink.configuration.SecurityOptions) Arrays(java.util.Arrays) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LoggerFactory(org.slf4j.LoggerFactory) ObjectInputStream(java.io.ObjectInputStream) TreeCacheSelector(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheSelector) StringUtils(org.apache.commons.lang3.StringUtils) BooleanSupplier(java.util.function.BooleanSupplier) FileSystemStateStorageHelper(org.apache.flink.runtime.persistence.filesystem.FileSystemStateStorageHelper) LeaderRetrievalDriverFactory(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalDriverFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ZooKeeperStateHandleStore(org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) DefaultLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.DefaultLeaderRetrievalService) LeaderElectionDriverFactory(org.apache.flink.runtime.leaderelection.LeaderElectionDriverFactory) ZooKeeperLeaderRetrievalDriver(org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriver) PathChildrenCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache) Collection(java.util.Collection) HighAvailabilityServicesUtils(org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils) DefaultJobGraphStore(org.apache.flink.runtime.jobmanager.DefaultJobGraphStore) UUID(java.util.UUID) ZooKeeperLeaderElectionDriver(org.apache.flink.runtime.leaderelection.ZooKeeperLeaderElectionDriver) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ACLProvider(org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider) Stat(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat) List(java.util.List) ZooKeeperCheckpointStoreUtil(org.apache.flink.runtime.checkpoint.ZooKeeperCheckpointStoreUtil) CuratorFrameworkFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory) CreateMode(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.CreateMode) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) ZooKeeperLeaderElectionDriverFactory(org.apache.flink.runtime.leaderelection.ZooKeeperLeaderElectionDriverFactory) ZooKeeperLeaderRetrievalDriverFactory(org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriverFactory) JobGraphStore(org.apache.flink.runtime.jobmanager.JobGraphStore) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) ZooDefs(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.ZooDefs) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultLeaderElectionService(org.apache.flink.runtime.leaderelection.DefaultLeaderElectionService) CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) ACL(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL) KeeperException(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException) DefaultCompletedCheckpointStoreUtils(org.apache.flink.runtime.checkpoint.DefaultCompletedCheckpointStoreUtils) RunnableWithException(org.apache.flink.util.function.RunnableWithException) SessionConnectionStateErrorPolicy(org.apache.flink.shaded.curator5.org.apache.curator.framework.state.SessionConnectionStateErrorPolicy) SharedStateRegistryFactory(org.apache.flink.runtime.state.SharedStateRegistryFactory) ZooKeeperJobGraphStoreWatcher(org.apache.flink.runtime.jobmanager.ZooKeeperJobGraphStoreWatcher) TreeCacheListener(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheListener) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ObjectOutputStream(java.io.ObjectOutputStream) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) Nonnull(javax.annotation.Nonnull) DefaultLastStateConnectionStateListener(org.apache.flink.runtime.checkpoint.DefaultLastStateConnectionStateListener) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) ZooKeeperCheckpointIDCounter(org.apache.flink.runtime.checkpoint.ZooKeeperCheckpointIDCounter) Configuration(org.apache.flink.configuration.Configuration) CompletedCheckpointStore(org.apache.flink.runtime.checkpoint.CompletedCheckpointStore) IOException(java.io.IOException) DefaultCompletedCheckpointStore(org.apache.flink.runtime.checkpoint.DefaultCompletedCheckpointStore) DefaultACLProvider(org.apache.flink.shaded.curator5.org.apache.curator.framework.imps.DefaultACLProvider) LeaderInformation(org.apache.flink.runtime.leaderelection.LeaderInformation) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) Executors(org.apache.flink.util.concurrent.Executors) UnhandledErrorListener(org.apache.flink.shaded.curator5.org.apache.curator.framework.api.UnhandledErrorListener) JobID(org.apache.flink.api.common.JobID) ExponentialBackoffRetry(org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry) TreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache) RetrievableStateStorageHelper(org.apache.flink.runtime.persistence.RetrievableStateStorageHelper) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) ZooKeeperJobGraphStoreUtil(org.apache.flink.runtime.jobmanager.ZooKeeperJobGraphStoreUtil) CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) UnhandledErrorListener(org.apache.flink.shaded.curator5.org.apache.curator.framework.api.UnhandledErrorListener) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)64 HashMap (java.util.HashMap)11 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 Configuration (org.apache.flink.configuration.Configuration)7 Map (java.util.Map)6 File (java.io.File)5 URI (java.net.URI)4 List (java.util.List)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 Field (java.lang.reflect.Field)3 Set (java.util.Set)3 Nullable (javax.annotation.Nullable)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Matcher (java.util.regex.Matcher)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)2