hadoop本地文件系统和getpos

omvjsjqw  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(448)

我发现rawlocalfilesystem的输入流中的getpos可以在底层流关闭时抛出空指针异常。
我是在玩一个定制的读卡器时发现的。
为了修补它,我只需检查对“stream.available()”的调用是否引发异常,如果是,我在getpos()函数中返回0。
现有的getpos()实现可以在以下位置找到:
https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20/src/examples/org/apache/hadoop/examples/multifilewordcount.java
getpos()在recordreader中的正确行为应该是什么?

wnavrhmk

wnavrhmk1#

recordreader中的“getpos”随着时间的推移而改变。
在旧的mapred recordreader实现中,它被用来计算读取的字节数。

/**
   * Returns the current position in the input.
   * 
   * @return the current position in the input.
   * @throws IOException
   */
  long getPos() throws IOException;

在较新的mapreduce recordreader实现中,rr类不提供此信息,而是fsinputstream实现的一部分:

class LocalFSFileInputStream extends FSInputStream implements HasFileDescriptor {
private FileInputStream fis;
private long position;

public LocalFSFileInputStream(Path f) throws IOException {
  this.fis = new TrackingFileInputStream(pathToFile(f));
}

@Override
public void seek(long pos) throws IOException {
  fis.getChannel().position(pos);
  this.position = pos;
}

@Override
public long getPos() throws IOException {
  return this.position;
}

因此,使用新的mapreduceapi,recordreader被抽象为不一定返回getpos()。可能希望使用此底层实现的RecordReader的较新实现可以重写为直接使用fsinputstream对象,后者提供了getpos()。

相关问题