【问题标题】:Hadoop producing no outputHadoop不产生输出
【发布时间】:2014-03-18 10:39:18
【问题描述】:

我有一个使用旧 API 运行的 hadoop 作业,我将我的实现移至新 API 并且在运行它时遇到了问题。作业运行时不会引发异常,但我从未生成任何输出文件。在旧 API 下,它会生成带有我排序结果列表的输出文件。这是正在运行的作业:

Configuration config = new Configuration();
Job job = Job.getInstance(config, "sorting");

job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(IntWritable.class);

job.setMapperClass(SortMapper.class);
job.setCombinerClass(SortReducer.class);
job.setReducerClass(SortReducer.class);

job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);

FileInputFormat.setInputPaths(job, new Path(inputFileLocation));
FileOutputFormat.setOutputPath(job, new Path(outputFileLocation));

job.setJarByClass(HadoopTest.class);

long startTime = System.currentTimeMillis();
job.submit();
long endTime = System.currentTimeMillis();

long duration = endTime - startTime;
System.out.println("Duration: " + duration);

这是我的映射器实现:

public static class SortMapper extends MultithreadedMapper<LongWritable, Text, IntWritable, IntWritable> {
    private final static IntWritable one = new IntWritable(1);
    private IntWritable intKey = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        intKey.set(Integer.parseInt(value.toString()));
        context.write(intKey, one);
    }
}

这是我的减速器实现:

public static class SortReducer extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {
    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        Iterator<IntWritable> iterator = values.iterator();
        while (iterator.hasNext()) {
            sum += iterator.next().get();
        }
        context.write(key, new IntWritable(sum));
    }
}

日志显示如下(使用旧 API 运行时,我总是收到有关“无法加载领域映射信息...”和“无法加载本机 hadoop...”的抱怨:

2014-03-18 10:19:41.299 java[13311:1d03] Unable to load realm mapping info from SCDynamicStore
14/03/18 10:19:41 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/03/18 10:19:41 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
14/03/18 10:19:41 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
14/03/18 10:19:41 WARN mapreduce.JobSubmitter: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this.
14/03/18 10:19:41 WARN mapreduce.JobSubmitter: No job jar file set.  User classes may not be found. See Job or Job#setJar(String).
14/03/18 10:19:41 INFO input.FileInputFormat: Total input paths to process : 2
14/03/18 10:19:41 INFO mapreduce.JobSubmitter: number of splits:2
14/03/18 10:19:42 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local904621238_0001
14/03/18 10:19:42 WARN conf.Configuration: file:/tmp/hadoop-james.mchugh/mapred/staging/james.mchugh904621238/.staging/job_local904621238_0001/job.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.retry.interval;  Ignoring.
14/03/18 10:19:42 WARN conf.Configuration: file:/tmp/hadoop-james.mchugh/mapred/staging/james.mchugh904621238/.staging/job_local904621238_0001/job.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.attempts;  Ignoring.
14/03/18 10:19:42 WARN conf.Configuration: file:/tmp/hadoop-james.mchugh/mapred/local/localRunner/james.mchugh/job_local904621238_0001/job_local904621238_0001.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.retry.interval;  Ignoring.
14/03/18 10:19:42 WARN conf.Configuration: file:/tmp/hadoop-james.mchugh/mapred/local/localRunner/james.mchugh/job_local904621238_0001/job_local904621238_0001.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.attempts;  Ignoring.
14/03/18 10:19:42 INFO mapreduce.Job: The url to track the job: http://localhost:8080/
14/03/18 10:19:42 INFO mapred.LocalJobRunner: OutputCommitter set in config null

【问题讨论】:

  • 您是否将工作打包为 JAR?
  • 可能不是,我正在通过 IDE 作为单元测试运行(也尝试通过 maven install 命令行运行)。原谅我的无知,因为我是 hadoop 的新手——你能解释一下为什么它很重要,与旧 API 有什么不同(因为它以同样的方式工作)等等?欢呼
  • @James 我不知道这是否是您的问题,但job.setJarByClass(HadoopTest.class); 会搜索 jar 文件以分发到集群中的节点。使用 IDE(比如 eclipse)时,没有要发送的 jar。

标签: java api sorting hadoop output


【解决方案1】:

尝试job.waitForCompletion(true); 而不是job.submit();。由于您在本地运行 mapreduce,因此您应该在 JUnit 杀死您的本地 jobtracker 之前等待结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-05
    • 2012-01-07
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 2014-05-06
    相关资源
    最近更新 更多