flink1.14流批一体源码原理

flink流批一体的原理(flink1.14源码)

  1. source

    1. taskmanager.Task#doRun的方法会调用taskmanager.Task#restoreAndInvoke
      1. 其会调用streamTask跑算子方法【map,filter等】(这一步会被阻塞,后面的代码暂不执行)
    2. 当sourceStreamTask的sourceFunction停止发送数据(数据已发完),则sourceStreamTask的线程(LegacySourceFunctionThread sourceThread)会结束,sourceStreamTask#processInput方法里会调用mailboxProcessor.suspend(),即将suspended设置为true,则MailboxProcessor#runMailboxLoop会跳出循环,所以streamTask会执行完invoke()方法
      1. sourceStreamTask的线程(LegacySourceFunctionThread sourceThread)会结束,即sourceThread .getCompletionFuture()不再阻塞
      2. MailboxProcessor#runMailboxLoop的循环条件是:isNextLoopPossible()【!suspended,即suspended为false】
      3. mailboxProcessor.suspend()方法会将suspended设置为true,即MailboxProcessor#runMailboxLoop跳出循环
    3. taskmanager.Task#restoreAndInvoke的阻塞结束,开始调用后面的代码
    4. 如果有下游输出算子,则循环调用partitionWriter.finish();(即BufferWritingResultPartition#finish)
      1. 循环调用subpartition.finish();(即PipelinedSubpartition#finish)
      2. PipelinedSubpartition#finish会发送EndOfPartitionEvent.INSTANCE的事件数据
    5. 到此此source准备完成task的finish
  2. 下游算子

    1. 下游算子会收到EndOfPartitionEvent.INSTANCE的事件数据

    2. SingleInputGate#transformEvent

      1. 接收到EndOfPartitionEvent.INSTANCE的事件数据
      2. hasReceivedAllEndOfPartitionEvents设置为true
    3. SingleInputGate#getNextBufferOrEvent返回Optional.empty()

      1. if (hasReceivedAllEndOfPartitionEvents) {
        	return Optional.empty();
        }
        
    4. AbstractStreamTaskNetworkInput#emitNext方法里,checkpointedInputGate.pollNext()收到Optional.empty()

      1. SingleInputGate#isFinished返回true,则checkpointedInputGate.isFinished()返回true,AbstractStreamTaskNetworkInput#emitNext返回DataInputStatus.END_OF_INPUT;
        
    5. StreamOneInputProcessor#processInput返回DataInputStatus.END_OF_INPUT

    6. StreamTask#processInput收到DataInputStatus.END_OF_INPUT,则调用mailboxProcessor.suspend();

    7. 则MailboxProcessor#runMailboxLoop会跳出循环,所以streamTask会执行完invoke()方法,该下游算子也开始finish

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值