flink源码解析之任务执行流程

  1. LocalStreamEnvironment#execute
  2. MiniCluster#executeJobBlocking -> MiniCluster#submitJob
  3. dispatcherGateway.submitJob(jobGraph, rpcTimeout)
  4. Dispatcher#submitJob --> Dispatcher#internalSubmitJob --> Dispatcher#persistAndRunJob --> Dispatcher#runJob
  5. Dispatcher#createJobManagerRunner
    –>jobManagerRunnerFactory.createJobManagerRunner
    –>this::startJobManagerRunner
  6. JobManagerRunner#start 成功之后回调JobManagerRunner#grantLeadership
  7. JobManagerRunner#verifyJobSchedulingStatusAndStartJobManager --> JobManagerRunner#startJobMaster
  8. JobMasterService#start
  9. JobMaster#start --> JobMaster#startJobExecution
    startJobMasterServices
    resetAndScheduleExecutionGraph
  10. JobMaster#resetAndScheduleExecutionGraph --> JobMaster#scheduleExecutionGraph
  11. ExecutionGraph#scheduleForExecution --> ExecutionGraph#scheduleEager
  12. org.apache.flink.runtime.executiongraph.Execution#deploy
  13. taskManagerGateway.submitTask(deployment, rpcTimeout) taskManagerGateway这里是RpcTaskManagerGateway#submitTask --> TaskExecutor#submitTask
  14. task.startTaskThread();开始执行。在task线程的run方法中,通过
    invokable.invoke();反射的方式来执行任务。对于WordCount例子来说,invokable就是OneInputStreamTask,调用invoke的 时候,就会调用OneInputStreamTask的父类StreamTask的invoke方法。invoke方法中调用抽象方法run方法来执行,然后进入OneInputStreamTask#run

	@Override
	protected void run() throws Exception {
		// cache processor reference on the stack, to make the code more JIT friendly
		final StreamInputProcessor<IN> inputProcessor = this.inputProcessor;

		while (running && inputProcessor.processInput()) {
			// all the work happens in the "processInput" method
		}
	}

  1. StreamInputProcessor#processInput,真正的执行代码在streamOperator.processElement(record);中,然后执行相应的子类的方法,对于StreamFlatMap来说,进入processElement方法,处理用户所写的代码逻辑。
@Override
	public void processElement(StreamRecord<IN> element) throws Exception {
		collector.setTimestamp(element);
		userFunction.flatMap(element.getValue(), collector);
	}
}

你可能感兴趣的:(flink)