Class NettyShuffleEnvironment
- java.lang.Object
-
- org.apache.flink.runtime.io.network.NettyShuffleEnvironment
-
- All Implemented Interfaces:
AutoCloseable,ShuffleEnvironment<ResultPartition,SingleInputGate>
public class NettyShuffleEnvironment extends Object implements ShuffleEnvironment<ResultPartition,SingleInputGate>
The implementation ofShuffleEnvironmentbased on netty network communication, local memory and disk files. The network environment contains the data structures that keep track of all intermediate results and shuffle data exchanges.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Tries to shut down all network I/O components.List<SingleInputGate>createInputGates(ShuffleIOOwnerContext ownerContext, PartitionProducerStateProvider partitionProducerStateProvider, List<InputGateDeploymentDescriptor> inputGateDeploymentDescriptors)Factory method for theInputGatesto consume result partitions.List<ResultPartition>createResultPartitionWriters(ShuffleIOOwnerContext ownerContext, List<ResultPartitionDeploymentDescriptor> resultPartitionDeploymentDescriptors)Factory method for theResultPartitionWritersto produce result partitions.ShuffleIOOwnerContextcreateShuffleIOOwnerContext(String ownerName, ExecutionAttemptID executionAttemptID, org.apache.flink.metrics.MetricGroup parentGroup)Create a context of the shuffle input/output owner used to create partitions or gates belonging to the owner.BatchShuffleReadBufferPoolgetBatchShuffleReadBufferPool()ScheduledExecutorServicegetBatchShuffleReadIOExecutor()NettyShuffleEnvironmentConfigurationgetConfiguration()ConnectionManagergetConnectionManager()Optional<Collection<SingleInputGate>>getInputGate(InputGateID id)Optional<ShuffleMetrics>getMetricsIfPartitionOccupyingLocalResource(ResultPartitionID partitionId)Get metrics of the partition if it still occupies some resources locally and have not been released yet.NetworkBufferPoolgetNetworkBufferPool()Collection<ResultPartitionID>getPartitionsOccupyingLocalResources()Report unreleased partitions.ResultPartitionManagergetResultPartitionManager()booleanisClosed()voidreleasePartitionsLocally(Collection<ResultPartitionID> partitionIds)Release local resources occupied by the given partitions.intstart()Start the internal related services before using the shuffle service environment.booleanupdatePartitionInfo(ExecutionAttemptID consumerID, PartitionInfo partitionInfo)Update a gate with the newly available partition information, previously unknown.
-
-
-
Method Detail
-
getResultPartitionManager
@VisibleForTesting public ResultPartitionManager getResultPartitionManager()
-
getConnectionManager
@VisibleForTesting public ConnectionManager getConnectionManager()
-
getNetworkBufferPool
@VisibleForTesting public NetworkBufferPool getNetworkBufferPool()
-
getBatchShuffleReadBufferPool
@VisibleForTesting public BatchShuffleReadBufferPool getBatchShuffleReadBufferPool()
-
getBatchShuffleReadIOExecutor
@VisibleForTesting public ScheduledExecutorService getBatchShuffleReadIOExecutor()
-
getConfiguration
@VisibleForTesting public NettyShuffleEnvironmentConfiguration getConfiguration()
-
getInputGate
@VisibleForTesting public Optional<Collection<SingleInputGate>> getInputGate(InputGateID id)
-
releasePartitionsLocally
public void releasePartitionsLocally(Collection<ResultPartitionID> partitionIds)
Description copied from interface:ShuffleEnvironmentRelease local resources occupied by the given partitions.This is called for partitions which occupy resources locally (can be checked by
ShuffleDescriptor.storesLocalResourcesOn()).- Specified by:
releasePartitionsLocallyin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Parameters:
partitionIds- identifying the partitions to be released
-
getPartitionsOccupyingLocalResources
public Collection<ResultPartitionID> getPartitionsOccupyingLocalResources()
Report unreleased partitions.- Specified by:
getPartitionsOccupyingLocalResourcesin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Returns:
- collection of partitions which still occupy some resources locally on this task executor and have been not released yet.
-
getMetricsIfPartitionOccupyingLocalResource
public Optional<ShuffleMetrics> getMetricsIfPartitionOccupyingLocalResource(ResultPartitionID partitionId)
Description copied from interface:ShuffleEnvironmentGet metrics of the partition if it still occupies some resources locally and have not been released yet.- Specified by:
getMetricsIfPartitionOccupyingLocalResourcein interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Parameters:
partitionId- the partition id- Returns:
- An Optional of
ShuffleMetrics, if found, of the given partition
-
createShuffleIOOwnerContext
public ShuffleIOOwnerContext createShuffleIOOwnerContext(String ownerName, ExecutionAttemptID executionAttemptID, org.apache.flink.metrics.MetricGroup parentGroup)
Description copied from interface:ShuffleEnvironmentCreate a context of the shuffle input/output owner used to create partitions or gates belonging to the owner.This method has to be called only once to avoid duplicated internal metric group registration.
- Specified by:
createShuffleIOOwnerContextin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Parameters:
ownerName- the owner name, used for logsexecutionAttemptID- execution attempt id of the producer or consumerparentGroup- parent of shuffle specific metric group- Returns:
- context of the shuffle input/output owner used to create partitions or gates belonging to the owner
-
createResultPartitionWriters
public List<ResultPartition> createResultPartitionWriters(ShuffleIOOwnerContext ownerContext, List<ResultPartitionDeploymentDescriptor> resultPartitionDeploymentDescriptors)
Description copied from interface:ShuffleEnvironmentFactory method for theResultPartitionWritersto produce result partitions.The order of the
ResultPartitionWritersin the returned collection should be the same as the iteration order of the passedresultPartitionDeploymentDescriptors.- Specified by:
createResultPartitionWritersin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Parameters:
ownerContext- the owner context relevant for partition creationresultPartitionDeploymentDescriptors- descriptors of the partition, produced by the owner- Returns:
- list of the
ResultPartitionWriters
-
createInputGates
public List<SingleInputGate> createInputGates(ShuffleIOOwnerContext ownerContext, PartitionProducerStateProvider partitionProducerStateProvider, List<InputGateDeploymentDescriptor> inputGateDeploymentDescriptors)
Description copied from interface:ShuffleEnvironmentFactory method for theInputGatesto consume result partitions.The order of the
InputGatesin the returned collection should be the same as the iteration order of the passedinputGateDeploymentDescriptors.- Specified by:
createInputGatesin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Parameters:
ownerContext- the owner context relevant for gate creationpartitionProducerStateProvider- producer state provider to query whether the producer is ready for consumptioninputGateDeploymentDescriptors- descriptors of the input gates to consume- Returns:
- list of the
InputGates
-
updatePartitionInfo
public boolean updatePartitionInfo(ExecutionAttemptID consumerID, PartitionInfo partitionInfo) throws IOException, InterruptedException
Description copied from interface:ShuffleEnvironmentUpdate a gate with the newly available partition information, previously unknown.- Specified by:
updatePartitionInfoin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Parameters:
consumerID- execution id to distinguish gates with the same id from the different consumer executionspartitionInfo- information needed to consume the updated partition, e.g. network location- Returns:
trueif the partition has been updated orfalseif the partition is not available anymore.- Throws:
IOException- IO problem by the updateInterruptedException- potentially blocking operation was interrupted
-
start
public int start() throws IOExceptionDescription copied from interface:ShuffleEnvironmentStart the internal related services before using the shuffle service environment.- Specified by:
startin interfaceShuffleEnvironment<ResultPartition,SingleInputGate>- Returns:
- a port to connect for the shuffle data exchange, -1 if only local connection is possible.
- Throws:
IOException
-
close
public void close()
Tries to shut down all network I/O components.- Specified by:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed()
-
-