【Hadoop】RPC Serialization Format - 代码描述

在前面一篇文章http://blog.csdn.net/tragicjun/article/details/8958154中大致总结了RPC消息序列化的格式,这里从代码层来描述。

Client-side

RPC Header

org.apache.hadoop.ipc.Client.call() --> getConnection() --> Connection.setupIOstreams() --> writeRpcHeader()

      out.write(Server.HEADER.array());
      out.write(Server.CURRENT_VERSION);
      authMethod.write(out);

Protocol Header

org.apache.hadoop.ipc.Client.call() --> getConnection() --> Connection.setupIOstreams() --> writeHeader()

      header.write(buf);
      
      // Write out the payload length
      int bufLen = buf.getLength();
      out.writeInt(bufLen);
      out.write(buf.getData(), 0, bufLen);

Connection Header

org.apache.hadoop.ipc.Client.call() --> getConnection() --> Connection.setupIOstreams() --> writeHeader() --> ConnectionHeader.write()

    Text.writeString(out, (protocol == null) ? "" : protocol);
    if (ugi != null) {
      if (authMethod == AuthMethod.KERBEROS) {
        // Send effective user for Kerberos auth
        out.writeBoolean(true);
        out.writeUTF(ugi.getUserName());
        out.writeBoolean(false);
      }...

RPC Parameter

org.apache.hadoop.ipc.Client.call() --> Connection.sendParam()

          d = new DataOutputBuffer();
          d.writeInt(call.id);
          call.param.write(d);
          byte[] data = d.getData();
          int dataLength = d.getLength();
          out.writeInt(dataLength);      //first put the data length
          out.write(data, 0, dataLength);//write the data

Invaction

org.apache.hadoop.ipc.Client.call() --> Connection.sendParam() --> Invocation.write()

      UTF8.writeString(out, methodName);
      out.writeInt(parameterClasses.length);
      for (int i = 0; i < parameterClasses.length; i++) {
        ObjectWritable.writeObject(out, parameters[i], parameterClasses[i],
                                   conf);
      }


Server-side

org.apache.hadoop.ipc.Server.Handler.run() --> org.apache.hadoop.ipc.Server.setupResponse() 

   out.writeInt(call.id);                // write call id
    out.writeInt(status.state);           // write status

    if (status == Status.SUCCESS) {
      rv.write(out);
    } else {
      WritableUtils.writeString(out, errorClass);
      WritableUtils.writeString(out, error);
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值