You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Michael Segel <ms...@hotmail.com> on 2014/06/03 14:04:05 UTC

How can a task know if its running as a MR1 or MR2 job?

Just a quick question... 

Suppose you have a M/R job running. 
How does the Mapper or Reducer task know or find out if its running as a M/R 1 or M/R 2 job? 

I would suspect the job context would hold that information... but on first glance I didn't see it. 
So what am I missing? 

Thx

-Mike



Re: How can a task know if its running as a MR1 or MR2 job?

Posted by Raj K Singh <ra...@gmail.com>.
Hi

I guess when we call submit() method that in tern call the setUseNewAPI()
method to set the MR2 relevent setting.. here what i found after code walk
through of hadoop

private void setUseNewAPI()
        throws IOException
    {
        int numReduces = conf.getNumReduceTasks();
        String oldMapperClass = "mapred.mapper.class";
        String oldReduceClass = "mapred.reducer.class";
        conf.setBooleanIfUnset("mapred.mapper.new-api",
conf.get(oldMapperClass) == null);
        if(conf.getUseNewMapper())
        {
            String mode = "new map API";
            ensureNotSet("mapred.input.format.class", mode);
            ensureNotSet(oldMapperClass, mode);
            if(numReduces != 0)
                ensureNotSet("mapred.partitioner.class", mode);
            else
                ensureNotSet("mapred.output.format.class", mode);
        } else
        {
            String mode = "map compatability";
            ensureNotSet("mapreduce.inputformat.class", mode);
            ensureNotSet("mapreduce.map.class", mode);
            if(numReduces != 0)
                ensureNotSet("mapreduce.partitioner.class", mode);
            else
                ensureNotSet("mapreduce.outputformat.class", mode);
        }
        if(numReduces != 0)
        {
            conf.setBooleanIfUnset("mapred.reducer.new-api",
conf.get(oldReduceClass) == null);
            if(conf.getUseNewReducer())
            {
                String mode = "new reduce API";
                ensureNotSet("mapred.output.format.class", mode);
                ensureNotSet(oldReduceClass, mode);
            } else
            {
                String mode = "reduce compatability";
                ensureNotSet("mapreduce.outputformat.class", mode);
                ensureNotSet("mapreduce.reduce.class", mode);
            }
        }
    }

::::::::::::::::::::::::::::::::::::::::
Raj K Singh
http://in.linkedin.com/in/rajkrrsingh
http://www.rajkrrsingh.blogspot.com
Mobile  Tel: +91 (0)9899821370


On Tue, Jun 3, 2014 at 5:34 PM, Michael Segel <ms...@hotmail.com>
wrote:

> Just a quick question...
>
> Suppose you have a M/R job running.
> How does the Mapper or Reducer task know or find out if its running as a
> M/R 1 or M/R 2 job?
>
> I would suspect the job context would hold that information... but on
> first glance I didn't see it.
> So what am I missing?
>
> Thx
>
> -Mike
>
>
>

Re: How can a task know if its running as a MR1 or MR2 job?

Posted by Raj K Singh <ra...@gmail.com>.
Hi

I guess when we call submit() method that in tern call the setUseNewAPI()
method to set the MR2 relevent setting.. here what i found after code walk
through of hadoop

private void setUseNewAPI()
        throws IOException
    {
        int numReduces = conf.getNumReduceTasks();
        String oldMapperClass = "mapred.mapper.class";
        String oldReduceClass = "mapred.reducer.class";
        conf.setBooleanIfUnset("mapred.mapper.new-api",
conf.get(oldMapperClass) == null);
        if(conf.getUseNewMapper())
        {
            String mode = "new map API";
            ensureNotSet("mapred.input.format.class", mode);
            ensureNotSet(oldMapperClass, mode);
            if(numReduces != 0)
                ensureNotSet("mapred.partitioner.class", mode);
            else
                ensureNotSet("mapred.output.format.class", mode);
        } else
        {
            String mode = "map compatability";
            ensureNotSet("mapreduce.inputformat.class", mode);
            ensureNotSet("mapreduce.map.class", mode);
            if(numReduces != 0)
                ensureNotSet("mapreduce.partitioner.class", mode);
            else
                ensureNotSet("mapreduce.outputformat.class", mode);
        }
        if(numReduces != 0)
        {
            conf.setBooleanIfUnset("mapred.reducer.new-api",
conf.get(oldReduceClass) == null);
            if(conf.getUseNewReducer())
            {
                String mode = "new reduce API";
                ensureNotSet("mapred.output.format.class", mode);
                ensureNotSet(oldReduceClass, mode);
            } else
            {
                String mode = "reduce compatability";
                ensureNotSet("mapreduce.outputformat.class", mode);
                ensureNotSet("mapreduce.reduce.class", mode);
            }
        }
    }

::::::::::::::::::::::::::::::::::::::::
Raj K Singh
http://in.linkedin.com/in/rajkrrsingh
http://www.rajkrrsingh.blogspot.com
Mobile  Tel: +91 (0)9899821370


On Tue, Jun 3, 2014 at 5:34 PM, Michael Segel <ms...@hotmail.com>
wrote:

> Just a quick question...
>
> Suppose you have a M/R job running.
> How does the Mapper or Reducer task know or find out if its running as a
> M/R 1 or M/R 2 job?
>
> I would suspect the job context would hold that information... but on
> first glance I didn't see it.
> So what am I missing?
>
> Thx
>
> -Mike
>
>
>

Re: How can a task know if its running as a MR1 or MR2 job?

Posted by Raj K Singh <ra...@gmail.com>.
Hi

I guess when we call submit() method that in tern call the setUseNewAPI()
method to set the MR2 relevent setting.. here what i found after code walk
through of hadoop

private void setUseNewAPI()
        throws IOException
    {
        int numReduces = conf.getNumReduceTasks();
        String oldMapperClass = "mapred.mapper.class";
        String oldReduceClass = "mapred.reducer.class";
        conf.setBooleanIfUnset("mapred.mapper.new-api",
conf.get(oldMapperClass) == null);
        if(conf.getUseNewMapper())
        {
            String mode = "new map API";
            ensureNotSet("mapred.input.format.class", mode);
            ensureNotSet(oldMapperClass, mode);
            if(numReduces != 0)
                ensureNotSet("mapred.partitioner.class", mode);
            else
                ensureNotSet("mapred.output.format.class", mode);
        } else
        {
            String mode = "map compatability";
            ensureNotSet("mapreduce.inputformat.class", mode);
            ensureNotSet("mapreduce.map.class", mode);
            if(numReduces != 0)
                ensureNotSet("mapreduce.partitioner.class", mode);
            else
                ensureNotSet("mapreduce.outputformat.class", mode);
        }
        if(numReduces != 0)
        {
            conf.setBooleanIfUnset("mapred.reducer.new-api",
conf.get(oldReduceClass) == null);
            if(conf.getUseNewReducer())
            {
                String mode = "new reduce API";
                ensureNotSet("mapred.output.format.class", mode);
                ensureNotSet(oldReduceClass, mode);
            } else
            {
                String mode = "reduce compatability";
                ensureNotSet("mapreduce.outputformat.class", mode);
                ensureNotSet("mapreduce.reduce.class", mode);
            }
        }
    }

::::::::::::::::::::::::::::::::::::::::
Raj K Singh
http://in.linkedin.com/in/rajkrrsingh
http://www.rajkrrsingh.blogspot.com
Mobile  Tel: +91 (0)9899821370


On Tue, Jun 3, 2014 at 5:34 PM, Michael Segel <ms...@hotmail.com>
wrote:

> Just a quick question...
>
> Suppose you have a M/R job running.
> How does the Mapper or Reducer task know or find out if its running as a
> M/R 1 or M/R 2 job?
>
> I would suspect the job context would hold that information... but on
> first glance I didn't see it.
> So what am I missing?
>
> Thx
>
> -Mike
>
>
>

Re: How can a task know if its running as a MR1 or MR2 job?

Posted by Raj K Singh <ra...@gmail.com>.
Hi

I guess when we call submit() method that in tern call the setUseNewAPI()
method to set the MR2 relevent setting.. here what i found after code walk
through of hadoop

private void setUseNewAPI()
        throws IOException
    {
        int numReduces = conf.getNumReduceTasks();
        String oldMapperClass = "mapred.mapper.class";
        String oldReduceClass = "mapred.reducer.class";
        conf.setBooleanIfUnset("mapred.mapper.new-api",
conf.get(oldMapperClass) == null);
        if(conf.getUseNewMapper())
        {
            String mode = "new map API";
            ensureNotSet("mapred.input.format.class", mode);
            ensureNotSet(oldMapperClass, mode);
            if(numReduces != 0)
                ensureNotSet("mapred.partitioner.class", mode);
            else
                ensureNotSet("mapred.output.format.class", mode);
        } else
        {
            String mode = "map compatability";
            ensureNotSet("mapreduce.inputformat.class", mode);
            ensureNotSet("mapreduce.map.class", mode);
            if(numReduces != 0)
                ensureNotSet("mapreduce.partitioner.class", mode);
            else
                ensureNotSet("mapreduce.outputformat.class", mode);
        }
        if(numReduces != 0)
        {
            conf.setBooleanIfUnset("mapred.reducer.new-api",
conf.get(oldReduceClass) == null);
            if(conf.getUseNewReducer())
            {
                String mode = "new reduce API";
                ensureNotSet("mapred.output.format.class", mode);
                ensureNotSet(oldReduceClass, mode);
            } else
            {
                String mode = "reduce compatability";
                ensureNotSet("mapreduce.outputformat.class", mode);
                ensureNotSet("mapreduce.reduce.class", mode);
            }
        }
    }

::::::::::::::::::::::::::::::::::::::::
Raj K Singh
http://in.linkedin.com/in/rajkrrsingh
http://www.rajkrrsingh.blogspot.com
Mobile  Tel: +91 (0)9899821370


On Tue, Jun 3, 2014 at 5:34 PM, Michael Segel <ms...@hotmail.com>
wrote:

> Just a quick question...
>
> Suppose you have a M/R job running.
> How does the Mapper or Reducer task know or find out if its running as a
> M/R 1 or M/R 2 job?
>
> I would suspect the job context would hold that information... but on
> first glance I didn't see it.
> So what am I missing?
>
> Thx
>
> -Mike
>
>
>