hadoop(0.1.1.2)源码学习-org.apache.hadoop.dfs DatanodeProtocol (接口)

interface DatanodeProtocol extends VersionedProtocol

**********************************************************************
 * Protocol that a DFS datanode uses to communicate with the NameNode.
 * It's used to upload current load information and block reports.
 *
 * The only way a NameNode can communicate with a DataNode is by
 * returning values from these functions.

 **********************************************************************/

* Superclass of all protocols that use Hadoop RPC.
 * Subclasses of this interface are also supposed to have
 * a static final long versionID field.

public interface VersionedProtocol {
  
  /**
   * Return protocol version corresponding to protocol interface.
   * @param protocol The classname of the protocol interface
   * @param clientVersion The version of the protocol that the client speaks
   * @return the version that the server will speak
   */
  public long getProtocolVersion(String protocol, 
                                 long clientVersion) throws IOException;
}

 public static final long versionID = 5L;  // register takes a new parameter
  
  // error code
  final static int DISK_ERROR = 1;
  final static int INVALID_BLOCK = 2;

  /**
   * Determines actions that data node should perform 
   * when receiving a block command. 
   */
  public enum DataNodeAction{ DNA_UNKNOWN,    // unknown action   
                              DNA_TRANSFER,   // transfer blocks to another datanode
                              DNA_INVALIDATE, // invalidate blocks
                              DNA_SHUTDOWN,   // shutdown node
                              DNA_REGISTER; }   // re-register

 

/** 
   * Register Datanode.
   *
   * @see org.apache.hadoop.dfs.DataNode#register()
   * @see org.apache.hadoop.dfs.FSNamesystem#registerDatanode(DatanodeRegistration, String)
   * 
   * @return updated {@link org.apache.hadoop.dfs.DatanodeRegistration}, which contains 
   * new storageID if the datanode did not have one and
   * registration ID for further communication.
   */
   
public DatanodeRegistration register( DatanodeRegistration registration,
                                          String networkLocation
                                        ) throws IOException;
    /**
     * sendHeartbeat() tells the NameNode that the DataNode is still
     * alive and well.  Includes some status info, too. 
     * It also gives the NameNode a chance to return a "BlockCommand" object.
     * A BlockCommand tells the DataNode to invalidate local block(s), 
     * or to copy them to other DataNodes, etc.
     */
   
public BlockCommand sendHeartbeat(DatanodeRegistration registration,
                                      long capacity, long remaining,
                                      int xmitsInProgress,
                                      int xceiverCount) throws IOException;

    /**
     * blockReport() tells the NameNode about all the locally-stored blocks.
     * The NameNode returns an array of Blocks that have become obsolete
     * and should be deleted.  This function is meant to upload *all*
     * the locally-stored blocks.  It's invoked upon startup and then
     * infrequently afterwards.
     */
    public Block[] blockReport( DatanodeRegistration registration,
                                Block blocks[]) throws IOException;
    
    /**
     * blockReceived() allows the DataNode to tell the NameNode about
     * recently-received block data.  For example, whenever client code
     * writes a new Block here, or another DataNode copies a Block to
     * this DataNode, it will call blockReceived().
     */
   
public void blockReceived(DatanodeRegistration registration,
                              Block blocks[]) throws IOException;

    /**
     * errorReport() tells the NameNode about something that has gone
     * awry.  Useful for debugging.
     */
    public void errorReport(DatanodeRegistration registration,
                            int errorCode, 
                            String msg) throws IOException;
}

 

// 以上是NameNode与DataNode交换数据的全部信息与格式

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值