无法通过通用选项解析器设置 mapreduce.job.reduces

unable to set mapreduce.job.reduces through generic option parser

hadoop jar MapReduceTryouts-1.jar invertedindex.simple.MyDriver -D mapreduce.job.reduces=10 /user/notprabhu2/Input/potter/ /user/notprabhu2/output

我一直在尝试通过 GenericOptionParser 提供的 -D 选项来设置 reducer 的数量,但它似乎不起作用,我也不知道为什么。

我尝试了 -D mapreduce.job.reduces=10(在 -D 之后使用 space)以及

-Dmapreduce.job.reduces=10(-D 后没有 space)但似乎没有任何闪避。

在我的驱动程序中 class 我已经实现了工具。

package invertedindex.simple;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class MyDriver extends Configured implements Tool {

    @Override
    public int run(String[] args) throws Exception {

        Configuration conf = getConf();
        Job job = Job.getInstance(conf);

        job.setJarByClass(MyDriver.class);

        Path outputPath =  new Path(args[1]);
        outputPath.getFileSystem(getConf()).delete(outputPath, true);

        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyReducer.class);

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

        TextInputFormat.addInputPath(job, new Path(args[0]));
        TextOutputFormat.setOutputPath(job, outputPath);

        job.setNumReduceTasks(3);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        return job.waitForCompletion(true) ? 0 : 1;

    }

    public static void main(String[] args) throws Exception {
        int exitCode = ToolRunner.run(new Configuration(),new MyDriver(), args);
        System.exit(exitCode);
    }

}

因为我在我的驱动程序代码中明确地将减速器的数量设置为 3,所以我总是以 3 个减速器结束。

我正在使用 CDH 5.4.7,它在 Google Compute Engine 的 2 节点集群上有 Hadoop 2.6.0

想通了。原来如此愚蠢但仍然发布答案以防万一有人也犯同样的愚蠢错误。

似乎我的驱动程序 class 中的 job.setNumReduceTasks(3); 行优先于命令行中的 -D mapreduce.job.reduces=10

当我从代码中删除 job.setNumReduceTasks(3); 行时,一切正常。

在 xml 标签中设置 属性 减速器的数量 - mapreduce.job.reduces

在 mapred-site.xml 中设置 属性 将由配置中的代码调用:

<property>
    <name>mapreduce.job.reduces</name>
    <value>5</value>
</property>

重新启动 hadoop 进程