ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【Flink】Flink netty 通讯 PartitionRequestClient NettyPartitionRequestClient

2021-07-04 20:57:45  阅读:288  来源: 互联网

标签:netty PartitionRequestClient 请求 inputChannel Flink request 实例 new final


在这里插入图片描述

1.概述

转载:http://www.voidcn.com/article/p-tbmjvzhq-bkg.html

这篇文章不是很完善,这点我也不是很懂,以后补充

分区请求客户端(PartitionRequestClient)用于发起远程PartitionRequest请求,它也是RemoteChannel跟Netty通信层之间进行衔接的对象。

对单一的TaskManager而言只存在一个NettyClient实例。但处于同一TaskManager中不同的任务实例可能会跟不同的远程TaskManager上的任务之间交换数据,不同的TaskManager实例会有不同的ConnectionID(用于标识不同的IP地址)。因此,Flink采用PartitionRequestClient来对应ConnectionID,并提供了分区请求客户端工厂(PartitionRequestClientFactory)来创建PartitionRequestClient并保存ConnectionID与之的对应关系。

接下来,我们重点分析一下其请求ResultPartition的requestSubpartition方法:

/**
	 * Requests a remote intermediate result partition queue.
	 *
	 * <p>The request goes to the remote producer, for which this partition
	 * request client instance has been created.
	 *
	 * 请求一个远程中间结果分区队列。
	 *
	 * 请求被发送到远程生产者,这个分区请求客户端实例已经被创建。
	 */
	@Override
	public void requestSubpartition(
			final ResultPartitionID partitionId,
			final int subpartitionIndex,
			final RemoteInputChannel inputChannel,
			int delayMs) throws IOException {

		checkNotClosed();

		LOG.debug("Requesting subpartition {} of partition {} with {} ms delay.",
				subpartitionIndex, partitionId, delayMs);

		//将当前请求数据的RemoteInputChannel的实例注入到NettyClient的ChannelHandler管道的
		//PartitionRequestClientHandler实例中
		clientHandler.addInputChannel(inputChannel);

		//构建PartitionRequest请求对象
		final PartitionRequest request = new PartitionRequest(
				partitionId, subpartitionIndex, inputChannel.getInputChannelId(), inputChannel.getInitialCredit());

		//构建一个ChannelFutureListener的实例,当I/O操作执行失败后,会触发相关的错误处理逻辑
		final ChannelFutureListener listener = new ChannelFutureListener() {
			@Override
			public void operationComplete(ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					clientHandler.removeInputChannel(inputChannel);
					SocketAddress remoteAddr = future.channel().remoteAddress();
					inputChannel.onError(
							new LocalTransportException(
								String.format("Sending the partition request to '%s' failed.", remoteAddr),
								future.channel().localAddress(), future.cause()
							));
				}
			}
		};

		//立即发送该请求,并注册listener
		if (delayMs == 0) {
			ChannelFuture f = tcpChannel.writeAndFlush(request);
			f.addListener(listener);
		} else {
			//如果请求需要延迟一定的时间,则延迟发送请求
			final ChannelFuture[] f = new ChannelFuture[1];
			tcpChannel.eventLoop().schedule(new Runnable() {
				@Override
				public void run() {
					f[0] = tcpChannel.writeAndFlush(request);
					f[0].addListener(listener);
				}
			}, delayMs, TimeUnit.MILLISECONDS);
		}
	}

标签:netty,PartitionRequestClient,请求,inputChannel,Flink,request,实例,new,final
来源: https://blog.csdn.net/qq_21383435/article/details/118467138

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有