A Hadoop job may consist of many map tasks and reduce tasks. Therefore, debugging a
Hadoop job is often a complicated process. It is a good practice to first test a Hadoop job
using unit tests by running it with a subset of the data.
However, sometimes it is necessary to debug a Hadoop job in a distributed mode. To support
such cases, Hadoop provides a mechanism called debug scripts. This recipe explains how to
use debug scripts.

A debug script is a shell script, and Hadoop executes the script whenever a task encounters
an error. The script will have access to the $script, $stdout, $stderr, $syslog, and
$jobconfproperties, as environment variables populated by Hadoop. You can find a
sample script from resources/chapter3/debugscript. We can use the debug scripts
to copy all the logfiles to a single location, e-mail them to a single e-mail account, or perform
some analysis.
LOG_FILE=HADOOP_HOME/error.log
echo "Run the script" >> $LOG_FILE
echo $script >> $LOG_FILE
echo $stdout>> $LOG_FILE
echo $stderr>> $LOG_FILE
echo $syslog >> $LOG_FILE
echo $jobconf>> $LOG_FILE

when you execute this, you should pay attention to the execute path, or else it will not found debug script.

  1. package chapter3;
  2.  
  3. import java.net.URI;
  4.  
  5. import org.apache.hadoop.filecache.DistributedCache;
  6. import org.apache.hadoop.fs.FileStatus;
  7. import org.apache.hadoop.fs.FileSystem;
  8. import org.apache.hadoop.fs.Path;
  9. import org.apache.hadoop.io.IntWritable;
  10. import org.apache.hadoop.io.Text;
  11. import org.apache.hadoop.mapred.JobConf;
  12. import org.apache.hadoop.mapreduce.Job;
  13. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  14. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  15.  
  16. public class WordcountWithDebugScript {
  17. private static final String scriptFileLocation = "resources/chapter3/debugscript";
  18. private static final String HDFS_ROOT = "/debug";
  19.  
  20. public static void setupFailedTaskScript(JobConf conf) throws Exception {
  21.  
  22. // create a directory on HDFS where we'll upload the fail scripts
  23. FileSystem fs = FileSystem.get(conf);
  24. // Path debugDir = new Path("/debug");
  25. Path debugDir = new Path(HDFS_ROOT);
  26.  
  27. // who knows what's already in this directory; let's just clear it.
  28. if (fs.exists(debugDir)) {
  29. fs.delete(debugDir, true);
  30. }
  31.  
  32. // ...and then make sure it exists again
  33. fs.mkdirs(debugDir);
  34.  
  35. // upload the local scripts into HDFS
  36. fs.copyFromLocalFile(new Path(scriptFileLocation), new Path(HDFS_ROOT
  37. + "/fail-script"));
  38.  
  39. FileStatus[] list = fs.listStatus(new Path(HDFS_ROOT));
  40. if (list == null || list.length == 0) {
  41. System.out.println("No File found");
  42. } else {
  43. for (FileStatus f : list) {
  44. System.out.println("File found " + f.getPath());
  45. }
  46. }
  47.  
  48. conf.setMapDebugScript("./fail-script");
  49. conf.setReduceDebugScript("./fail-script");
  50. // this create a simlink from the job directory to cache directory of
  51. // the mapper node
  52. DistributedCache.createSymlink(conf);
  53.  
  54. URI fsUri = fs.getUri();
  55.  
  56. String mapUriStr = fsUri.toString() + HDFS_ROOT
  57. + "/fail-script#fail-script";
  58. System.out.println("added " + mapUriStr + "to distributed cache 1");
  59. URI mapUri = new URI(mapUriStr);
  60. // Following copy the map uri to the cache directory of the job node
  61. DistributedCache.addCacheFile(mapUri, conf);
  62. }
  63.  
  64. public static void main(String[] args) throws Exception {
  65. JobConf conf = new JobConf();
  66. setupFailedTaskScript(conf);
  67. Job job = new Job(conf, "word count");
  68.  
  69. job.setJarByClass(FaultyWordCount.class);
  70. job.setMapperClass(FaultyWordCount.TokenizerMapper.class);
  71. job.setReducerClass(FaultyWordCount.IntSumReducer.class);
  72. job.setOutputKeyClass(Text.class);
  73. job.setOutputValueClass(IntWritable.class);
  74. FileSystem.get(conf).delete(new Path(args[1]), true);
  75. FileInputFormat.addInputPath(job, new Path(args[0]));
  76. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  77. job.waitForCompletion(true);
  78. }
  79.  
  80. }

digest from mapreduce cookbook

hadoop debug script的更多相关文章

  1. Hadoop官方文档翻译——MapReduce Tutorial

    MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...

  2. hadoop mapreduce核心功能描述

    核心功能描述 应用程序通常会通过提供map和reduce来实现 Mapper和Reducer接口,它们组成作业的核心. Mapper Mapper将输入键值对(key/value pair)映射到一组 ...

  3. hadoop之 hadoop 2.2.X 弃用的配置属性名称及其替换名称对照表

    Deprecated Properties  弃用属性 The following table lists the configuration property names that are depr ...

  4. Hadoop专业解决方案-第5章 开发可靠的MapReduce应用

    本章主要内容: 1.利用MRUnit创建MapReduce的单元测试. 2.MapReduce应用的本地实例. 3.理解MapReduce的调试. 4.利用MapReduce防御式程序设计. 在WOX ...

  5. Hadoop Map/Reduce教程

    原文地址:http://hadoop.apache.org/docs/r1.0.4/cn/mapred_tutorial.html 目的 先决条件 概述 输入与输出 例子:WordCount v1.0 ...

  6. 一步一步跟我学习hadoop(5)----hadoop Map/Reduce教程(2)

    Map/Reduce用户界面 本节为用户採用框架要面对的各个环节提供了具体的描写叙述,旨在与帮助用户对实现.配置和调优进行具体的设置.然而,开发时候还是要相应着API进行相关操作. 首先我们须要了解M ...

  7. VS2015/2013/2012 IIS Express Debug Classic ASP

    参考资料: https://msdn.microsoft.com/en-us/library/ms241740(v=vs.100).aspx When you attach to an ASP Web ...

  8. cdh版本的hue安装配置部署以及集成hadoop hbase hive mysql等权威指南

    hue下载地址:https://github.com/cloudera/hue hue学习文档地址:http://archive.cloudera.com/cdh5/cdh/5/hue-3.7.0-c ...

  9. Hadoop出现错误:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable,解决方案

    安装Hadoop的时候直接用的bin版本,根据教程安装好之后运行的时候发现出现了:WARN util.NativeCodeLoader: Unable to load native-hadoop li ...

随机推荐

  1. imfong.com,我的新博客地址

    imfong.com新博客采用jekyll+Github搭建,欢迎访问.

  2. sql语句分页多种方式ROW_NUMBER()OVER

    sql语句分页多种方式ROW_NUMBER()OVER 摘自: http://www.cnblogs.com/CodingArt/articles/1692468.html 方式一 select to ...

  3. 数据库sqlserver2008登陆名密码登陆不了怎么办?

    我用的是sql server2008数据库,原先创建的登录名是sa,但是密码就忘了.总是出现这个连接问题

  4. mbps

    Mbps=Mbit/s即兆比特每秒.Million bits per second的缩写 传输速率是指设备的的数据交换能力,也叫“带宽”,单位是Mbps(兆位/秒),目前主流的集线器带宽主要有10Mb ...

  5. python peewee.ImproperlyConfigured: MySQLdb or PyMySQL must be installed.

    最近在学习Python,打算先看两个在线教程,再在github上找几个开源的项目练习一下,在学到“被解放的姜戈”时遇到django同步数据库时无法执行的错误,记录一下. 错误现象: 执行python ...

  6. spring扫描classpath下特定package,并加载具有特定注解的接口

    spring扫描classpath下特定package,并加载具有特定注解的接口. 在框架平台的开发中,通常有很多的情况通过spring配置方式来实现某些功能会使得框架平台难以使用和扩展,我们通常的做 ...

  7. Ajax的实现

    一.JavaScript的ajax //Ajax var xhr; if(window.XMLHttpRequest){ //除IE外的浏览器 xhr = new XMLHttpRequest() } ...

  8. 百度Couldn't load BaiduMapSDK_v2_4_1 from loader dalvik

    原文链接:http://liuzhichao.com/p/1463.html 在使用百度定位SDK的时候,明明已经加入了liblocSDK3.so,Manifest中也添加了相应权限,注册了com.b ...

  9. Web应用程序系统的多用户权限控制设计及实现-首页模块【5】

    首页模块就是展示不同权限的最终结果了,在阅读这章之前若有些不明白,可看看后续的单独的权限模块,用户模块,目录模块后从整体上再看首页模块. 阅读该模块需要一定或者是比较熟练的js知识,EasyUI Ta ...

  10. NSTimer定时器的使用

    前言:这是关于NSTimer的学习笔记. 正文内容大纲: 1.关于计时器NSTimer的一个被添加进NSRunLoop的使用细节 2.关于NSTimer常用方法的使用 3.关于NSTimer的类别工具 ...