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
相关推荐
Lill_bin12 小时前
深入理解ElasticSearch集群:架构、高可用性与数据一致性
大数据·分布式·elasticsearch·搜索引擎·zookeeper·架构·全文检索
涛思数据(TDengine)12 小时前
TDengine 与 SCADA 强强联合:提升工业数据管理的效率与精准
大数据·时序数据库·tdengine
isNotNullX13 小时前
如何用SQL Server和Oracle进行数据同步?
大数据·数据库·sql·oracle
RwTo14 小时前
Elasticsearch 聚合搜索
大数据·elasticsearch·搜索引擎·全文检索
isNotNullX14 小时前
HBase在大数据实时处理中的角色
大数据·数据库·hbase
白总Server15 小时前
MySQL在大数据场景应用
大数据·开发语言·数据库·后端·mysql·golang·php
求学小火龙15 小时前
ElasticSearch介绍+使用
java·大数据·elasticsearch
檀越剑指大厂15 小时前
【Elasticsearch系列六】系统命令API
大数据·elasticsearch·搜索引擎
数据运营新视界15 小时前
你知道企业架构中核心的4大架构联系和不同吗?
大数据·架构
h1771134720516 小时前
基于区块链的相亲交易系统源码解析
大数据·人工智能·安全·系统架构·交友