How to debug hadoop mapreduce jobs from eclipse?
Solution 1
Make changes in /bin/hadoop
(hadoop-env.sh
) script. Check to see what command has been fired. If the command is jar
, then only add remote debug configuration.
if [ "$COMMAND" = "jar" ] ; then
exec "$JAVA" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8999 $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
else
exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
fi
Solution 2
The only way you can debug hadoop in eclipse is running hadoop in local mode. The reason being, each map reduce task run in ist own JVM and when you don't hadoop in local mode, eclipse won't be able to debug.
When you set hadoop to local mode, instead of using hdfs API(which is default), hadoop file system changes to file:///
. Thus, running hadoop fs -ls
will not be a hdfs command, but more of hadoop fs -ls file:///
, a path to your local directory. None of the JobTracker or NameNode runs.
These blogposts might help:
- http://let-them-c.blogspot.com/2011/07/running-hadoop-locally-on-eclipse.html
- http://let-them-c.blogspot.com/2011/07/configurations-of-running-hadoop.html
Solution 3
Besides the recommended MRUnit I like to debug with eclipse as well. I have a main program. It instantiates a Configuration and executes the MapReduce job directly. I just debug with standard eclipse Debug configurations. Since I include hadoop jars in my mvn spec, I have all hadoop per se in my class path and I have no need to run it against my installed hadoop. I always test with small data sets in local directories to make things easy. The defaults for the configuration behaves as a stand alone hadoop (file system is available)
sangfroid
Updated on May 04, 2021Comments
-
sangfroid about 3 years
I'm running hadoop in a single-machine, local-only setup, and I'm looking for a nice, painless way to debug mappers and reducers in eclipse. Eclipse has no problem running mapreduce tasks. However, when I go to debug, it gives me this error :
12/03/28 14:03:23 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
Okay, so I do some research. Apparently, I should use eclipse's remote debugging facility, and add this to my
hadoop-env.sh
:-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5000
I do that and I can step through my code in eclipse. Only problem is that, because of the "suspend=y", I can't use the "hadoop" command from the command line to do things like look at the job queue; it hangs, I'm imagining because it's waiting for a debugger to attach. Also, I can't run "hbase shell" when I'm in this mode, probably for the same reason.
So basically, if I want to flip back and forth between "debug mode" and "normal mode", I need to update
hadoop-env.sh
and restart my machine. Major pain. So I have a few questions :Is there an easier way to do debug mapreduce jobs in eclipse?
How come eclipse can run my mapreduce jobs just fine, but for debugging I need to use remote debugging?
Is there a way to tell hadoop to use remote debugging for mapreduce jobs, but to operate in normal mode for all other tasks? (such as "hadoop queue" or "hbase shell").
Is there an easier way to switch
hadoop-env.sh
configurations without rebooting my machine? hadoop-env.sh is not executable by default.This is a more general question : what exactly is happening when I run hadoop in local-only mode? Are there any processes on my machine that are "always on" and executing hadoop jobs? Or does hadoop only do things when I run the "hadoop" command from the command line? What is eclipse doing when I run a mapreduce job from eclipse? I had to reference
hadoop-core
in mypom.xml
in order to make my project work. Is eclipse submitting jobs to my installed hadoop instance, or is it somehow running it all from thehadoop-core-1.0.0.jar
in my maven cache?
Here is my Main class :
public class Main { public static void main(String[] args) throws Exception { Job job = new Job(); job.setJarByClass(Main.class); job.setJobName("FirstStage"); FileInputFormat.addInputPath(job, new Path("/home/sangfroid/project/in")); FileOutputFormat.setOutputPath(job, new Path("/home/sangfroid/project/out")); job.setMapperClass(FirstStageMapper.class); job.setReducerClass(FirstStageReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
-
sangfroid about 12 yearsThanks for your answer. I, too, have hadoop-core set up as a dependency in my POM. Since that is the case, why am I getting the "No job jar file set" error? Is it because I'm calling job.setJarByClass()? Could you please post some example code?
-
ali-hussain about 11 yearsI didn't try exactly this but I replaced $JAVA with jdb (I was trying to debug using jdb). jdb never recognized the breakpoint I tried to place where I wanted the program to stop. I'm assuming the problem was that I wasn't running in local mode. I haven't tried it yet but I'm assuming Kapil D's suggestion is what I need to follow.
-
Steve Goodman about 11 yearsYou could alos add the debugging options to your shell's $HADOOP_OPTS var, and not have to modify the hadoop script. export HADOOP_OPTS="$HADOOP_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8999"
-
Pedro Dusso about 10 yearsHi @Kapil, What you described is possible in Hadoop 2.4 (with Yarn, etc..). I'm trying to run a local job in eclipse with the new version and facing
Cannot initialize Cluster. Please check your configuration...
-
erichfw over 9 years@PedroDusso have you gotten local debug to work with Hadoop 2.4+?
-
Pedro Dusso over 9 years@erichfw I never tried... I was using 2.2 in the time I asked this question.