Block源代码

Block是HDFS中的最基本单位是对数据块的抽象,它通过一个final long(blkid)来进行标识。一个Block拥有三个longs,它们分别是block-id 、block length和generation stamp。Block名的格式是”blk”+blkid。通过set和get等方法能够得到关于Block的id、name、len等信息
 
一个Block对应着两个文件,其中一个存数据,一个存放元数据信息。它的元数据信息文件的格式如下:”blk_”+blkid+”_”+version.meta
和Block相关的类如下所示:

 
  private long blockId;
 
例如${hadoop.tmp.dir}/dfs/data/current /blk_826540629399449945,这一串数字就是blockId
 blockId 是block编号
 
  private long numBytes;
 blockId 是文件实际大小
 
  private long generationStamp;
 类似个时间戳,每次修改加1
 
在equals中用到 generationStamp
在hashcode没有用到generationStamp
 
 
 
 
文件名称和block的转换
  static long filename2id(String name) {
    return Long.parseLong(name.substring("blk_".length()));
 
  }
 
 
 
  public boolean   public boolean equals(Object o) {    if (!(o instanceof Block)) {      return false;    }    final Block that = (Block)o;    //Wildcard generationStamp is ALLOWED here    return this.blockId == that.blockId      && GenerationStamp.equalsWithWildcard(          this.generationStamp, that.generationStamp);  }
  /** {@inheritDoc} */  public int hashCode() {    //GenerationStamp is IRRELEVANT and should not be used here    return 37 * 17 + (int) (blockId^(blockId>>>32));  }(Object o) {    if (!(o instanceof Block)) {      return false;    }    final Block that = (Block)o;    //Wildcard generationStamp is ALLOWED here    return this.blockId == that.blockId      && GenerationStamp.equalsWithWildcard(          this.generationStamp, that.generationStamp);  }
  /** {@inheritDoc} */  public int hashCode() {    //GenerationStamp is IRRELEVANT and should not be used here    return 37 * 17 + (int) (blockId^(blockId>>>32));  }
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

手把手教你学AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值