Flink1.15源码阅读——执行图executiongraph

执行图是在JobManager生成的,且在创建JobMaster的过程中创建的。
本篇是基于per job模式

查看JobGraph作业图

client生成JobGraph之后,就通过submitJob提交给JobManager,JobManager会根据JobGraph生成对应的ExecutionGraph。

ExecutionGraph 是Flink作业调度时使用到的核心数据结构,它包含每一个并行的task,每一个intermediate stream以及它们之间的关系。

查看JobMaster类

在JobMaster类的构造方法中有如下代码

this.schedulerNG =
                createScheduler(
                        slotPoolServiceSchedulerFactory,
                        executionDeploymentTracker,
                        jobManagerJobMetricGroup,
                        jobStatusListener);

createScheduler

final SchedulerNG scheduler =
                slotPoolServiceSchedulerFactory.createScheduler(
                        log,
                        jobGraph,
                        ioExecutor,
                        jobMasterConfiguration.getConfiguration(),
                        slotPoolService,
                        futureExecutor,
                        userCodeLoader,
                        highAvailabilityServices.getCheckpointRecoveryFactory(),
                        rpcTimeout,
                        blobWriter,
                        jobManagerJobMetricGroup,
                        jobMasterConfiguration.getSlotRequestTimeout(),
                        shuffleMaster,
                        partitionTracker,
                        executionDeploymentTracker,
                        initializationTimestamp,
                        getMainThreadExecutor(),
                        fatalErrorHandler,
                        jobStatusListener);

        return scheduler;

看到工厂类调用了一个createScheduler 方法,现在只有默认实现类DefaultSlotPoolServiceSchedulerFactory.java。
又调用了一个方法,并且直接返回结果。

return schedulerNGFactory.createInstance(
                log,
                jobGraph,
                ioExecutor,
                configuration,
                slotPoolService,
                futureExecutor,
                userCodeLoader,
                checkpointRecoveryFactory,
                rpcTimeout,
                blobWriter,
                jobManagerJobMetricGroup,
                slotRequestTimeout,
                shuffleMaster,
                partitionTracker,
                executionDeploymentTracker,
                initializationTimestamp,
                mainThreadExecutor,
                fatalErrorHandler,
                jobStatusListener);

createInstance

在这里插入图片描述
这里实现类之前1.11版本的时候只有一个默认的实现类,现在加了AdaptiveSchedulerFactory和AdaptiveBatchSchedulerFactory两种调度器;

然后里面有一个方法

final ExecutionGraphFactory executionGraphFactory =
                new DefaultExecutionGraphFactory(
                        jobMasterConfiguration,
                        userCodeLoader,
                        executionDeploymentTracker,
                        futureExecutor,
                        ioExecutor,
                        rpcTimeout,
                        jobManagerJobMetricGroup,
                        blobWriter,
                        shuffleMaster,
                        partitionTracker);
new DefaultExecutionGraphFactory()

这个类里有一个buildGraph方法

final ExecutionGraph newExecutionGraph =
                DefaultExecutionGraphBuilder.buildGraph(
                        jobGraph,
                        configuration,
                        futureExecutor,
                        ioExecutor,
                        userCodeClassLoader,
                        completedCheckpointStore,
                        checkpointsCleaner,
                        checkpointIdCounter,
                        rpcTimeout,
                        blobWriter,
                        log,
                        shuffleMaster,
                        jobMasterPartitionTracker,
                        partitionLocationConstraint,
                        executionDeploymentListener,
                        combinedExecutionStateUpdateListener,
                        initializationTimestamp,
                        vertexAttemptNumberStore,
                        vertexParallelismStore,
                        checkpointStatsTrackerFactory,
                        isDynamicGraph,
                        executionJobVertexFactory);

看了这么多弯弯绕,才找到这个真正构建执行图的方法,看着这代码,虽然说用了很多设计模式,但是看着还是晕。

DefaultExecutionGraphBuilder.buildGraph()

核心逻辑

final DefaultExecutionGraph executionGraph;
        try {
            executionGraph =
                    new DefaultExecutionGraph(
                            jobInformation,
                            futureExecutor,
                            ioExecutor,
                            rpcTimeout,
                            executionHistorySizeLimit,
                            classLoader,
                            blobWriter,
                            partitionGroupReleaseStrategyFactory,
                            shuffleMaster,
                            partitionTracker,
                            partitionLocationConstraint,
                            executionDeploymentListener,
                            executionStateUpdateListener,
                            initializationTimestamp,
                            vertexAttemptNumberStore,
                            vertexParallelismStore,
                            isDynamicGraph,
                            executionJobVertexFactory);
        }

...
...
...

// 核心逻辑:将拓扑排序过的JobGraph添加到executionGraph数据结构中
        executionGraph.attachJobGraph(sortedTopology);

attachJobGraph(sortedTopology)

核心逻辑

attachJobVertices(verticesToAttach);
initializeJobVertices(verticesToInitialize);

attachJobVertices(verticesToAttach)

// 实例化执行图节点,根据每一个job vertex, 创建对应的ExecutionVertex
            ExecutionJobVertex ejv =
                    executionJobVertexFactory.createExecutionJobVertex(
                            this, jobVertex, parallelismInfo);

...

            // 将当前执行图节点加入到图中
            this.verticesInCreationOrder.add(ejv);

initializeJobVertices(verticesToInitialize)

初始化作业顶点

for (JobVertex jobVertex : topologicallySorted) {
            final ExecutionJobVertex ejv = tasks.get(jobVertex.getID());
            initializeJobVertex(ejv, createTimestamp);
        }
initializeJobVertex(ejv, createTimestamp)
 ejv.initialize(
                executionHistorySizeLimit,
                rpcTimeout,
                createTimestamp,
                this.initialAttemptCounts.getAttemptCounts(ejv.getJobVertexId()),
                coordinatorStore);

        // 将创建的ExecutionJobVertex与前置的IntermediateResults连接起来
        ejv.connectToPredecessors(this.intermediateResults);

...


// 最后注册执行顶点和结果中间分区
registerExecutionVerticesAndResultPartitionsFor(ejv);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

京河小蚁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值