hadoop使用PB协议(protocol buffer)来传输数据与命令
ProtocolBuffer是用于序列化结构数据的灵活、高效、自动的方法,有如XML,不过它更小、更快、也更简单。一旦定义了你自己的数据结构,然后就可以使用特殊生成的源代码轻松的在各种数据流和使用的各种高级语言之间读写你的结构化数据。你甚至可以在不破坏根据“旧”格式编译的已部署程序的情况下更新你的数据结构。
PB协议使用了proto文件保存交互数据的结构,因此首先hadoop需要将proto编译成为java文件
执行maven命令打包的期间,会执行protoc命令将protopuf文件生成Java类
<plugin>
<groupId>org.apache.hadoopgroupId>
<artifactId>hadoop-maven-pluginsartifactId>
<executions>
<execution>
<id>compile-protocid>
<phase>generate-sourcesphase>
<goals>
<goal>protocgoal>
goals>
<configuration>
<protocVersion>${protobuf.version}protocVersion>
<protocCommand>${protoc.path}protocCommand>
<imports>
<param>${basedir}/../../hadoop-common-project/hadoop-common/src/main/protoparam>
<param>${basedir}/src/main/protoparam>
imports>
<source>
<directory>${basedir}/src/main/protodirectory>
<includes>
<include>ClientDatanodeProtocol.protoinclude>
<include>ClientNamenodeProtocol.protoinclude>
<include>DatanodeProtocol.protoinclude>
<include>HAZKInfo.protoinclude>
<include>InterDatanodeProtocol.protoinclude>
<include>JournalProtocol.protoinclude>
<include>NamenodeProtocol.protoinclude>
<include>QJournalProtocol.protoinclude>
<include>acl.protoinclude>
<include>xattr.protoinclude>
<include>datatransfer.protoinclude>
<include>fsimage.protoinclude>
<include>hdfs.protoinclude>
<include>encryption.protoinclude>
<include>inotify.protoinclude>
includes>
source>
<output>${project.build.directory}/generated-sources/javaoutput>
configuration>
execution>
executions>
plugin>
NameNode.main() —> MainNode.createNameNode()—>new NameNode() —> NameNode.initialize() —> createRpcServer() —> new NameNodeRpcServer(conf, this) —> BlockingService clientNNPbService = ClientNamenodeProtocol.newReflectiveBlockingService(new ClientNamenodeProtocolServerSideTransltatorPB(this)) —> new PRC.Builder(conf).setInstance(clientNNPbService ) —> NameNodePrcServer.start()
客户端请求执行命令 —> Reader —> Call —> ClientNamenodeProtocolTranslatorPB(implements ProtocolMetaInterface, ClientProtocol, Closeable, ProtocolTranslator)
—> ClientNamenodeProtocolServerSideTranslatorPB(implements
ClientNamenodeProtocolPB).mkdirs() —> NameNodeRpcServer(implements ClientProtocol).mkdirs() —> FSNamesystem.mkdirs() —> FSDirMkdirOp
.mkdirs()