网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
- Transformation:可查看 flink-streaming-java 模块中 org.apache.flink.streaming.api.transformations 下的类,有各种类型的 Transformation。
- 算子将用户逻辑封装,并构造出 Transformation,然后将 Transformation 存储到 StreamExecutionEnvironment:
// 将 Transformation 存储到执行环境中
getExecutionEnvironment().addOperator(resultTransform);
- 当调用 env.execute() 时,遍历执行环境中的 Transformation 集合,然后使用 StreamGraphGenerator.generate() 创建 StreamGraph。
StreamGraph streamGraph = getStreamGraph();
-> final StreamGraph streamGraph = getStreamGraph(transformations);
-> getStreamGraphGenerator(transformations).generate();
->
for (Transformation<?> transformation : transformations) {
transform(transformation);
}
// 记录slot共享组及其相应的细粒度资源档案
streamGraph.setSlotSharingGroupResource(slotSharingGroupResources);
for (StreamNode node : streamGraph.getStreamNodes()) {
if (node.getInEdges().stream().anyMatch(this::shouldDisableUnalignedCheckpointing)) {
for (StreamEdge edge : node.getInEdges()) {
edge.setSupportsUnalignedCheckpoints(false);
}
}
}
注:并不是每一个 StreamTransformation 都会转换成 runtime 层中物理操作。有一些只是逻辑概念,比如 union、split/select、partition等。
2. 生成 JobGraph
JobGraph 是在 Client 端生成的。
该部分代码主要在 flink-runtime 模块中的,该过程主要在 org.apache.flink.runtime.jobgraph包中。StreamingJobGraphGenerator.createJobGraph() 中实现。
- StreamNode 转成 JobVertex,将 one-to-one 且并行的相同的节点合并为一个节点。StreamEdge 转成 JobEdge。会为所有节点生成一个唯一的 hash id,如果节点在多次提交中没有改变(包括并发度、上下游等),那么这个 id 就不会改变,这主要用于故障恢复。
3. 集群接收并处理 JobGraph
这部分实现在 flink-runtime 模块中的 org.apache.flink.runtime.rest.handler.job.JobSubmitHandler.handleRequest() 方法中。在该方法中,会获取 restClient 的文件,获取 JobGraph 和对应的依赖、jar包,然后通过 dispatchergateway 提交 JobGraph。
下面代码负责继续处理 JobGraph。
CompletableFuture<Acknowledge> jobSubmissionFuture =
finalizedJobGraphFuture.thenCompose(
jobGraph -> gateway.submitJob(jobGraph, timeout));
可进而查看其调用的方法,如下所示。
gateway.submitJob(jobGraph, timeout)
-> internalSubmitJob(jobGraph)
-> this::persistAndRunJob
-> runJob(createJobMasterRunner(jobGraph), ExecutionType.SUBMISSION)
在 runJob() 中会创建 JobMaster,然后 JobGraph 在 JobMaster 中会被转化成 ExecutionGraph。
4. 生成 ExecutionGraph
Client 会将 JobGraph 进行提交,然后服务端会接收 JobGraph,创建 JobMaster,并将 JobGraph 转换为 ExecutionGraph。
- 集群会在创建调度器时,创建 ExecutionGraph。调度器会继承 SchedulerBase 类,在该类的构造函数中通过下面的代码创建 ExecutionGraph。
this.executionGraph =
createAndRestoreExecutionGraph(
completedCheckpointStore,
checkpointsCleaner,
checkpointIdCounter,
initializationTimestamp,
mainThreadExecutor,
jobStatusListener,
vertexParallelismStore);
查看其调用过程如下。
createAndRestoreExecutionGraph(...)
-> final ExecutionGraph newExecutionGraph =
executionGraphFactory.createAndRestoreExecutionGraph(...)
-> final ExecutionGraph newExecutionGraph =
DefaultExecutionGraphBuilder.buildGraph(...)
![img](https://img-blog.csdnimg.cn/img_convert/d7f34a071b05d5f0c3e4e82cde8ff5a1.png)
![img](https://img-blog.csdnimg.cn/img_convert/ca82dab150f81abeefb6eb23b55af9eb.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
5e56a57acb)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**