Flink源码之JobMaster启动流程

Flink中Graph转换流程如下:

Flink Job提交时各种类型Graph转换流程中,JobGraph是Client端形成StreamGraph后经过Operator Chain优化后形成的,然后提交给JobManager的Restserver,最终转发给JobManager的Dispatcher处理。

复制代码
CompletableFuture<Acknowledge> submitJob(JobGraph jobGraph, @RpcTimeout Time timeout);

本文主要解析从JobGraph转换为ExecutionGraph过程,执行栈如下:

复制代码
Dispacher::submitJob
Dispacher::internalSubmitJob
Dispacher::persistAndRunJob
Dispacher::runJob
Dispacher::createJobManagerRunner
JobMasterServiceLeadershipRunnerFactory::createJobManagerRunner
JobMasterServiceLeadershipRunner:start
JobMasterServiceLeadershipRunner::grantLeadership
JobMasterServiceLeadershipRunner::startJobMasterServiceProcessAsync
JobMasterServiceLeadershipRunner::verifyJobSchedulingStatusAndCreateJobMasterServiceProcess
JobMasterServiceLeadershipRunner::createNewJobMasterServiceProcess
DefaultJobMasterServiceProcessFactory::create
DefaultJobMasterServiceProcess::new
DefaultJobMasterServiceFactory::createJobMasterService
DefaultJobMasterServiceFactory::internalCreateJobMasterService //创建JobMaster并调用其start
JobMaster::new //调用DefaultSlotPoolServiceSchedulerFactory::createScheduler
DefaultSlotPoolServiceSchedulerFactory::createScheduler //根据调度模式选择调度器
DefaultSchedulerFactory::createInstance //创建SchedulerNG
DefaultScheduler::new //
SchedulerBase::new
    SchedulerBase::createAndRestoreExecutionGraph 
    DefaultExecutionGraphFactory::createAndRestoreExecutionGraph
    DefaultExecutionGraphBuilder.buildGraph//在此会将JobGraph转换为ExecutionGraph
        DefaultExecutionGraph::new
        DefaultExecutionGraph::attachJobGraph //创建ExecutionJobVertex
        	DefaultExecutionTopology.fromExecutionGraph //创建ExecutionTopology
        DefaultExecutionGraph::enableCheckpointing //创建CheckpointCoordinator
        	CheckpointCoordinator::new   
PipelinedRegionSchedulingStrategy.Factory.createInstance //创建PipelinedRegionSchedulingStrategy

JobMaster::start
JobMaster::onStart
JobMaster::startJobExecution
JobMaster::startJobMasterServices //获取RM地址后与RM建立连接
JobMaster::startScheduling
SchedulerBase::startScheduling
DefaultScheduler::startSchedulingInternal
PipelinedRegionSchedulingStrategy::startScheduling
PipelinedRegionSchedulingStrategy::maybeScheduleRegions
DefaultScheduler::allocateSlotsAndDeploy
DefaultScheduler::allocateSlots
	SlotSharingExecutionSlotAllocator::allocateSlotsFor //分配Slot
DefaultScheduler::waitForAllSlotsAndDeploy
    DefaultScheduler::assignAllResourcesAndRegisterProducedPartitions
        DefaultScheduler::assignResource //为每个Execution分配Slot
        DefaultScheduler::registerProducedPartitions
    DefaultScheduler::deployAll
    DefaultScheduler::deployOrHandleError
    DefaultScheduler::deployTaskSafe
    DefaultExecutionVertexOperations::deploy
        ExecutionVertex::deploy
        Execution::deploy //提交任务向TM提交Deploymen
        TaskManagerGateway.submitTask

在整个提交过程中,首先获取JobMasterService的Leader权限,然后对一个JobGraph生成一个JobMaster,JobMaster先将JobGraph转换为ExecutionGraph,转换核心逻辑在DefaultExecutionGraph::attachJobGraph方法中,最后为每个Execution申请Slot资源,对每个Execution向TM提交TaskDeploymentDescriptor调度执行。

JobMaster管理整个Job的生命周期,主要有以下功能:

  1. 将JobGraph转换为ExecutionGraph,创建调度器调度执行
  2. 通过心跳保持与ResourceManager的连接,为当前Job向RM申请Slot资源
  3. 接受TaskManager的OfferSlot, 向TM提交task, 主动发送心跳请求保持与执行当前Job的TM的连接
  4. 创建CheckpointCoordinator,触发Checkpoint

Flink中可通过jobmanager.scheduler配置调度类型,默认为NG:

: 复制代码
NG:new generation scheduler
Adaptive: adaptive scheduler; supports reactive mode
相关推荐
写代码的【黑咖啡】8 分钟前
大数据环境下如何维护模型文档:策略与实践
大数据
焦糖玛奇朵婷11 分钟前
扭蛋机小程序:线上扭蛋机模式发展新形势[特殊字符]
大数据·数据库·程序人生·小程序·软件需求
番茄撒旦在上19 分钟前
什么样的表适合做拉链表
大数据·数据仓库·hive
Elastic 中国社区官方博客36 分钟前
在 Kibana 中可视化你的 Bosch Smart Home 数据
大数据·运维·elasticsearch·搜索引擎·信息可视化·全文检索·kibana
云老大TG:@yunlaoda3601 小时前
如何使用华为云国际站代理商的FunctionGraph进行事件驱动的应用开发?
大数据·数据库·华为云·云计算
yiersansiwu123d1 小时前
生成式AI重构内容生态,人机协同定义创作新范式
大数据·人工智能·重构
老蒋新思维1 小时前
创客匠人:从个人IP到知识变现,如何构建可持续的内容生态?
大数据·网络·人工智能·网络协议·tcp/ip·创客匠人·知识变现
Sui_Network1 小时前
Mysten Labs 与不丹王国政府的创新与技术部携手探索离线区块链
大数据·人工智能·web3·去中心化·区块链
互联科技报1 小时前
GEO优化工具、AI搜索引擎优化软件平台实测报告:四大平台深度体验与选型指南
大数据·人工智能·搜索引擎
递归尽头是星辰2 小时前
AI 驱动的报表系统:从传统到智能的落地与演进
大数据·人工智能·大模型应用·spring ai·ai 报表·报表智能化