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)); }
猜你喜欢
转载自zhaomengsen.iteye.com/blog/2059644
今日推荐
周排行