Java Hadoop具有推测性执行的多个输出

Java Hadoop具有推测性执行的多个输出,java,hadoop,yarn,multipleoutputs,speculative-execution,Java,Hadoop,Yarn,Multipleoutputs,Speculative Execution,我有一个任务,将avro输出写入由几个输入记录字段组织的多个目录中 For example : Process records of countries across years and write in a directory structure of country/year eg: outputs/usa/2015/outputs_usa_2015.avro outputs/uk/2014/outputs_uk_2014.avro 下面的代码将使用哪个输出提交器来编写输出。与推测性

我有一个任务,将avro输出写入由几个输入记录字段组织的多个目录中

For example : Process records of countries across years and write in a directory structure of country/year eg: outputs/usa/2015/outputs_usa_2015.avro outputs/uk/2014/outputs_uk_2014.avro 下面的代码将使用哪个输出提交器来编写输出。与推测性执行一起使用是否不安全? 对于推测性执行,这会导致(可能会导致)org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException

在这个岗位上 建议使用自定义输出提交器

以下来自hadoop AvroMultipleOutputs的代码没有说明推测执行的任何问题

 private synchronized RecordWriter getRecordWriter(TaskAttemptContext taskContext,
          String baseFileName) throws IOException, InterruptedException {

    writer =
                ((OutputFormat) ReflectionUtils.newInstance(taskContext.getOutputFormatClass(),
                    taskContext.getConfiguration())).getRecordWriter(taskContext);
...
}
如果baseoutput路径在作业目录之外,write方法也不会记录任何问题

public void write(String namedOutput, Object key, Object value, String baseOutputPath)
在作业目录外写入时,AvroMultipleOutputs(其他输出)是否存在投机性执行的实际问题?
如果,,那么如何覆盖AvroMultipleOutputs以拥有自己的输出提交程序。我在AvroMultipleOutputs中看不到任何outputformat,它使用的输出提交程序将使用您在添加命名输出时注册到作业配置的
输出格式,例如使用
addNamedOutput
API来自
AvroMultipleOutputs
(例如
AvroKeyValueOutputFormat

使用
AvroMultipleOutputs
,您可能无法使用推测性任务执行功能。即使覆盖它也无济于事,也不简单

相反,您应该编写自己的
OutputFormat
(最有可能扩展一种可用的Avro输出格式,例如
AvroKeyValueOutputFormat
),并重写/实现其
getRecordWriter
API,其中它将返回一个
RecordWriter
实例,例如
MainRecordWriter
(仅供参考)

MainRecordWriter
将维护
RecordWriter
(例如
AvroKeyValueRecordWriter
)实例的映射。这些
RecordWriter
实例中的每一个都属于其中一个输出文件。在
MainRecordWriter
write
API中,您将从映射中获得实际的
RecordWriter
实例(基于您将要编写的记录),并使用此RecordWriter编写记录。因此,
MainRecordWriter
将只是作为多个
RecordWriter
实例的包装器


对于一些类似的实现,您可能希望研究
piggybank
库中的类代码。

当您将命名输出添加到
AvroMultipleOutputs
时,它将调用
AvroKeyOutputFormat.getRecordWriter()
AvroKeyValueOutputFormat.getRecordWriter()
,哪个调用
AvroOutputFormatBase.getAvroFileOutputStream()
,其内容为

protected OutputStream getAvroFileOutputStream(TaskAttemptContext context) throws IOException {
  Path path = new Path(((FileOutputCommitter)getOutputCommitter(context)).getWorkPath(),
    getUniqueFile(context,context.getConfiguration().get("avro.mo.config.namedOutput","part"),org.apache.avro.mapred.AvroOutputFormat.EXT));
  return path.getFileSystem(context.getConfiguration()).create(path);
}

AvroOutputFormatBase
扩展了
FileOutputFormat
(上述方法中的
getOutputCommitter()
实际上是对
FileOutputFormat.getOutputCommitter()的调用)
。因此,
AvroMultipleOutputs
应该与
MultipleOutputs

具有相同的约束,您是否编写了自己的实现?我有相同的问题。当您说“对于推测性执行,这会导致(可能导致)org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException”,您是否在任何地方看到过此文档,或者您是根据经验说话的。我们看到了相同的行为,但没有找到任何明确的引用来禁用使用多个输出时的推测执行。是的,有文档记录。这里有一个警告
protected OutputStream getAvroFileOutputStream(TaskAttemptContext context) throws IOException {
  Path path = new Path(((FileOutputCommitter)getOutputCommitter(context)).getWorkPath(),
    getUniqueFile(context,context.getConfiguration().get("avro.mo.config.namedOutput","part"),org.apache.avro.mapred.AvroOutputFormat.EXT));
  return path.getFileSystem(context.getConfiguration()).create(path);
}