hadoop - Hadoop RawLocalFileSystem和getPos

标签 hadoop recordreader

我已经发现,如果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

RecordReader中的getPos()的正确行为应该是什么?

最佳答案

随着时间的推移,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;
}

因此,使用新的mapreduce API,RecordReader被抽象为不必返回getPos()。可以重写RecordReaders的较新实现,这些实现可能要使用此基础实现,可以直接使用FSInputStream对象重写,该对象确实提供了getPos()。

关于hadoop - Hadoop RawLocalFileSystem和getPos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18708832/

相关文章:

hadoop - RecordReader 的概念

database - Sqoop 是否使用 Reducer?

hadoop - 错误启动 hadoop 2.2.0 minicluster : java. lang.NoClassDefFoundError: org/apache/hadoop/yarn/server/MiniYARNCluster

hadoop - Mahout CPU在群集中的利用率

java - mapreduce.TextInputFormat hadoop

java - Hadoop + Jackson 解析: ObjectMapper reads Object and then breaks

json - jackson jsonparser 在损坏的 JSON 中重新开始解析

linux - 如何让Windows上的Apache Spark访问Linux上的Hadoop?

hadoop - MapReduce,FileNotFoundException