总的来说,ResultSubpartition是Flink数据流处理中的关键组件,它负责数据的存储、传输和消费,确保数据在不同Task之间的正确流动和高效处理。
创建ResultPartition、ResultSubpartition的相关源码
public ResultPartition create(
String taskNameWithSubtaskAndId,
int partitionIndex,
ResultPartitionID id,
ResultPartitionType type,
int numberOfSubpartitions,
int maxParallelism,
SupplierWithException<BufferPool, IOException> bufferPoolFactory) {
BufferCompressor bufferCompressor = null;
if (type.supportCompression() && batchShuffleCompressionEnabled) {
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 if (type == ResultPartitionType.HYBRID\_FULL
|| type == ResultPartitionType.HYBRID\_SELECTIVE) {
partition =
new HsResultPartition(
taskNameWithSubtaskAndId,
partitionIndex,
id,
type,
subpartitions.length,
maxParallelism,
batchShuffleReadBufferPool,
batchShuffleReadIOExecutor,
partitionManager,
channelManager.createChannel().getPath(),
networkBufferSize,
HybridShuffleConfiguration.builder(
numberOfSubpartitions,
batchShuffleReadBufferPool.getNumBuffersPerRequest())
.setSpillingStrategyType(
type == ResultPartitionType.HYBRID\_FULL
? HybridShuffleConfiguration
.SpillingStrategyType.FULL
: HybridShuffleConfiguration
.SpillingStrategyType.SELECTIVE)
.build(),
bufferCompressor,
bufferPoolFactory);
}
return partition;
}
四、InputGate
InputGate是对数据输入的封装,与JobGraph中的JobEdge一一对应。每个InputGate消费一个或多个ResultPartition,这些ResultPartition代表上游Task生成的数据。InputGate的主要作用是管理和控制数据的流入,确保数据能够按照正确的顺序和方式被Task所消费。
InputGate由多个InputChannel构成,每个InputChannel与ExecutionGraph中的ExecutionEdge以及ResultSubpartition一一对应。这意味着每个InputChannel负责接收一个ResultSubpartition的输出,从而实现了数据的精确传递和接收。
在Flink的物理执行过程中,InputGate和InputChannel起着至关重要的作用。它们不仅负责数据的接收和传递,还参与了数据的序列化和反序列化过程,确保数据在不同Task之间的正确流动。此外,InputGate和InputChannel还提供了对数据传输的控制和优化功能,可以根据实际需求调整数据传输的策略和方式。
总的来说,Flink的InputGate通过对数据输入的封装和管理,实现了数据的精确传递和高效处理。
五、InputChannel
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数大数据工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上大数据开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注大数据获取)
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
8 (备注大数据获取)**
[外链图片转存中…(img-8qskTcRp-1712962014771)]
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!