Hadoop IPC的代码结构分析
与IPC相关的代码在org.apache.hadoop.ipc包下。共七个文件,其中4个辅助类:
RemoteException
Status
VersionedProtocol
ConnectionHeader
主要实现类3个:
Client
Server
RPC
客户端Client:

如上图:
与IPC连接相关的
- Client.Connection
- Client.ConnectionId
- ConnectionHeader
与远程调用Call相关的
- Client.Call
- Client.ParallelCall
- Client.ParallelResults
服务器端Server:

与IPC连接相关的
- Server.Connection
- ConnectionHeader
与远程调用Call相关的
- Server.Call
- Server.Responder
- Server.Listener
- Server.Handler
RPC
RPC是在Server及Client的基础上实现了Hadoop IPC。

与客户端相关的功能:
- RPC.ClientCache
- RPC.Invoker(继承java.lang.reflect.InvocationHandler)
- RPC.Invocation
与服务端相关的功能:
- RPC.Server
Connection
客户端与服务器端对连接的抽象不一样,所以有Server.Connection和Client.Connection。Hadoop远程调用采用TCP协议通信。
1)客户端Client.ConnectionId
连接复用:当多个IPC客户端的ConnectionId相同时,他们共享一个IPC连接。连接复用可以减少Hadoop Server、Client的资源占用,同时节省IPC连接时间。
2)ConnectionHeader
Server与Client间TCP连接建立后交换的第一条信息,包含ConnectionId.ticket(UserGroupInformation)用户信息和IPC接口信息,检验是否实现了IPC接口,以及该用户是否有权使用接口。
Call
建立连接后,即可以进行远程过程调用服务,即对IPC接口方法的调用,源码抽象为Call。
远程调用Client.Call对象和Server.Call对象,是一个IPC调用产生的,存在于IPC客户端(存根)和IPC服务端(骨架)中的实体。
Client.Call对象通过IPC连接到服务器后,自然会构成相应的Server.Call对象。
Client.Call何时产生以及如何产生?

如上图所示流程:
- 用户发起远程接口调用
- 动态代理,RPC.Invoker调用句柄捕获远程调用
- 根据invoke的输入参数method、args生成RPC.Invocation对象
- 并调用Client.call,call会将上一步的Invocation对象序列化并通过IPC连接发送到服务器。Client.call会等待服务端返回的结果。
- 服务器端Listener监听Client发来的连接请求和数据请求,并调用Server端的连接对象。
- 连接对象接收远程调用请求帧,反序列化,并将请求放于阻塞队列中,由Handler处理。
- Handler调用对应的IPC接口实现类,完成过程调用,将结果序列化。
- 如果此时连接的应答队列为空,返回给客户端。
- 否则,客户端比较忙,应答队列不为空,Handler将结果放入响应队列,由Responser通过IPC发送给客户端。
Client.Connection对象,需要通过setupIOstreams方法和服务器建立连接,该方法首先通过Java套接字与server建立Socket连接,如果失败,则进行一定次数的重试,如下代码,是setupIOstreams调用的setupConnection:
private synchronized void setupConnection() throws IOException {
short ioFailures = 0;
short timeoutFailures = 0;
while (true) {
try {
this.socket = socketFactory.createSocket();
this.socket.setTcpNoDelay(tcpNoDelay);
//禁用tcp的Nagle算法,关闭socket底层缓冲
// 配置项 ${ipc.client.tcpnodelay}
/*
* Bind the socket to the host specified in the principal name of the
* client, to ensure Server matching address of the client connection
* to host name in principal passed.
*/
if (UserGroupInformation.isSecurityEnabled()) {
KerberosInfo krbInfo =
remoteId.getProtocol().getAnnotation(KerberosInfo.class);
if (krbInfo != null && krbInfo.clientPrincipal() != null) {
String host =
SecurityUtil.getHostFromPrincipal(remoteId.getTicket().getUserName());
// If host name is a valid local address then bind socket to it
InetAddress localAddr = NetUtils.getLocalInetAddress(host);
if (localAddr != null) {
this.socket.bind(new InetSocketAddress(localAddr, 0));
}
}
}
// connection time out is 20s
NetUtils.connect(this.socket, server, 20000);
if (rpcTimeout > 0) {
pingInterval = rpcTimeout; // rpcTimeout overwrites pingInterval
}
this.socket.setSoTimeout(pingInterval);
return;
} catch (SocketTimeoutException toe) {
/* Check for an address change and update the local reference.
* Reset the failure counter if the address was changed
*/
if (updateAddress()) {
timeoutFailures = ioFailures = 0;
}
/* The max number of retries is 45,
* which amounts to 20s*45 = 15 minutes retries.
*/
handleConnectionFailure(timeoutFailures++, 45, toe);
} catch (IOException ie) {
if (updateAddress()) {
timeoutFailures = ioFailures = 0;
}
handleConnectionFailure(ioFailures++, maxRetries, ie);
}
}
}
IPC连接
- 连接建立
- 连接上的数据读写
- 连接维护
- 连接关闭
在接下来的几篇内分别介绍以上内容。
Hadoop IPC的代码结构分析的更多相关文章
- org.apache.hadoop.ipc.RemoteException(java.io.IOException)
昨晚突然之间mr跑步起来了 jps查看 进程都在的,但是在reduce任务跑了85%的时候会抛异常 异常情况如下: 2016-09-21 21:32:28,538 INFO [org.apache.h ...
- 一张图解释Hadoop IPC
基于hadoop2.6.2.... 一张图Server启动,Client访问..... RPC是IPC的一种,IPC还有另外一种LPC,相关请看参考中的3 使用hadoop ipc步骤: 1.定义RP ...
- 运行基准测试hadoop集群中的问题:org.apache.hadoop.ipc.RemoteException: java.io.IOException: File /benchmarks/TestDFSIO/io_data/test_
在master(即:host2)中执行 hadoop jar hadoop-test-1.1.2.jar DFSCIOTest -write -nrFiles 12 -fileSize 10240 - ...
- hive运行query语句时提示错误:org.apache.hadoop.ipc.RemoteException: java.io.IOException: java.io.IOException:
hive> select product_id, track_time from trackinfo limit 5; Total MapReduce jobs = 1 Launching Jo ...
- Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException):
用windows连接hadoop集群执行mapreduce任务的时候出现以下错误: org.apache.hadoop.security.AccessControlException:Permissi ...
- Hive JDBC:java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate anonymous
今天使用JDBC来操作Hive时,首先启动了hive远程服务模式:hiveserver2 &(表示后台运行),然后到eclipse中运行程序时出现错误: java.sql.SQLExcepti ...
- 一脸懵逼加从入门到绝望学习hadoop之 org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): Permission denied: user=Administrator, access=WRITE, inode="/":root:supergroup:drwxr-xr报错
1:初学hadoop遇到各种错误,这里贴一下,方便以后脑补吧,报错如下: 主要是在window环境下面搞hadoop,而hadoop部署在linux操作系统上面:出现这个错误是权限的问题,操作hado ...
- HBase中此类异常解决记录org.apache.hadoop.ipc.RemoteException(java.io.IOException):
ERROR: Can't get master address from ZooKeeper; znode data == null 一定注意这只是问题的第一层表象,真的问题是: File /hb ...
- Hadoop学习笔记之一:Hadoop IPC
因为某些原因需要把前一段时间对Hadoop(版本基于0.20.2)的学习积累搬到这里,成为一个系列.写得会很简单,只为必要时给自己提醒. IPC框架 所有Hadoop协议接口的实现都依赖Hadoop ...
随机推荐
- string int 转换
int转stringint n = 0;std::stringstream ss;std::string str;ss<<n;ss>>str;string转intstd::st ...
- [LeetCode] Remove Element (三种解法)
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- UVA 10828 Back to Kernighan-Ritchie(高斯消元)
高斯消元求概率 对于非起点,期望x[i] = ∑x[j] / deg[j] #include<cstdio> #include<iostream> #include<cs ...
- JqueryEasyUI 解决IE下加载时页面错乱的问题 分类: JavaScript JqueryEasyUI 2014-09-20 09:50 545人阅读 评论(1) 收藏
问题描述: 一直觉得jqueryeasyui在IE下的渲染效果不大好,尤其刚进入页面时的加载,页面会出现布局错乱,虽然是一闪而过,但是给用户的体验不好: 可以通过在页面onload时,增加一个遮罩层, ...
- iOS static
获得20条news 先实现,再提取到business 层. The static Keyword You can have a local variable retain its value thro ...
- php开启mysqli扩展之后如何连接数据库
Mysqli是php5之后才有的功能,没有开启扩展的朋友可以打开您的php.ini的配置文件;相对于mysql有很多新的特性和优势,需要了解的朋友可以参考下 Mysqli是php5之后才有的功能,没有 ...
- 在ASP.NET 5项目中使用和调试外部源代码包
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:由于在ASP.NET 5中,项目依赖都是通过"包"来引用,所以使用 ...
- jquery 仿百度搜索下拉框的插件
转载地址:http://www.open-open.com/lib/view/open1420624048437.html 今天写了个下拉插件分享出来 效果: , 可以搜素,也可以使用上下键选择匹配出 ...
- jackson对多态or多子类序列化的处理配置
[TOC] Jackson Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 多态类型的处理 jackson允许配置多态类型处理, ...
- 认识B/S架构
Browser/Server即浏览器/服务器模式. Web浏览器主要功能 1. 申请服务,包括服务器的Ip地址和文件 2. 从服务器上下载 3. 解析下载的文件 4. 用过http协议进行通信 Web ...