我试着去学习潜水HDFS中存储的文件到分裂和读给不同的过程(在不同的机器。)的Hadoop在同样大小分割文件
我想到的是,如果我有一个包含1200条记录与SequenceFile
12过程中,我会看到每个过程大约有100条记录。划分文件的方式是获取数据长度,然后除以进程数,为每个分割导出chunk/beg/end大小,然后将该分割通过例如SequenceFileRecordReader
,在简单的while循环中检索记录:代码如下。
private InputSplit getSplit(int id) throws IOException {
...
for(FileStatus file: status) {
long len = file.getLen();
BlockLocation[] locations =
fs.getFileBlockLocations(file, 0, len);
if (0 < len) {
long chunk = len/n;
long beg = (id*chunk)+(long)1;
long end = (id)*chunk;
if(n == (id+1)) end = len;
return new FileSplit(file, beg, end, locations[locations.length-1].getHosts());
}
}
...
}
但是,结果显示每个进程统计的总记录总数与存储在文件中的记录不同。将SequenceFile均匀分成块并将它们分发到不同主机的正确方法是什么?
谢谢。