HDFS分布式文件系统特征block底层

6 篇文章 0 订阅
HDFS分布式文件系统特征block底层

转载注明出处: http://blog.csdn.net/jackie_zhf/article/details/79467624

众多分布式文件系统为什么用HDFS?

a、可以移动计算到数据所在节点;
b、就近读取数据文件和计算
Look 代码:
private static void blk() throws Exception {
Path ifile = new Path("");
FileStatus file = fs.getFileStatus(ifile );
// 获取block的location信息 HDFS分布式文件存储系统根据其偏移量的位置信息来读取其内容
BlockLocation[] blk = fs.getFileBlockLocations(file , 0, file.getLen());
for (BlockLocation bb : blk) {
System.out.println(bb);
}
FSDataInputStream input = fs.open(ifile);
System.out.println((char)input.readByte());
System.out.println((char)input.readByte());
System.out.println((char)input.readByte());
System.out.println((char)input.readByte());
System.out.println((char)input.readByte());
// 指定从哪个offset的位置偏移量来读
input.seek(1048576);
System.out.println((char)input.readByte());
System.out.println((char)input.readByte());
System.out.println((char)input.readByte());
input.seek(1048576);
System.out.println((char)input.readByte());
}

结果可见 其offset偏移量和所在位置(当前完整文件大小为1.5MB左右;设置blocksize大小为1MB,一共切分为2个block;副本数为1个):

注意:

我们知道block存储位置但是数据文件【文件的block】对客户端计算程序不可见,一个程序只能通过HDFS的接口去分布式文件系统中的block所在位置去读取文件对应的数据区间位置offset(文件从哪里到哪里读)并计算。

转载注明出处: http://blog.csdn.net/jackie_zhf/article/details/79467624



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值