hadoop debug script
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.
package chapter3; import java.net.URI; import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class WordcountWithDebugScript {
private static final String scriptFileLocation = "resources/chapter3/debugscript";
private static final String HDFS_ROOT = "/debug"; public static void setupFailedTaskScript(JobConf conf) throws Exception { // create a directory on HDFS where we'll upload the fail scripts
FileSystem fs = FileSystem.get(conf);
// Path debugDir = new Path("/debug");
Path debugDir = new Path(HDFS_ROOT); // who knows what's already in this directory; let's just clear it.
if (fs.exists(debugDir)) {
fs.delete(debugDir, true);
} // ...and then make sure it exists again
fs.mkdirs(debugDir); // upload the local scripts into HDFS
fs.copyFromLocalFile(new Path(scriptFileLocation), new Path(HDFS_ROOT
+ "/fail-script")); FileStatus[] list = fs.listStatus(new Path(HDFS_ROOT));
if (list == null || list.length == 0) {
System.out.println("No File found");
} else {
for (FileStatus f : list) {
System.out.println("File found " + f.getPath());
}
} conf.setMapDebugScript("./fail-script");
conf.setReduceDebugScript("./fail-script");
// this create a simlink from the job directory to cache directory of
// the mapper node
DistributedCache.createSymlink(conf); URI fsUri = fs.getUri(); String mapUriStr = fsUri.toString() + HDFS_ROOT
+ "/fail-script#fail-script";
System.out.println("added " + mapUriStr + "to distributed cache 1");
URI mapUri = new URI(mapUriStr);
// Following copy the map uri to the cache directory of the job node
DistributedCache.addCacheFile(mapUri, conf);
} public static void main(String[] args) throws Exception {
JobConf conf = new JobConf();
setupFailedTaskScript(conf);
Job job = new Job(conf, "word count"); job.setJarByClass(FaultyWordCount.class);
job.setMapperClass(FaultyWordCount.TokenizerMapper.class);
job.setReducerClass(FaultyWordCount.IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileSystem.get(conf).delete(new Path(args[1]), true);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
} }
digest from mapreduce cookbook
hadoop debug script的更多相关文章
- Hadoop官方文档翻译——MapReduce Tutorial
MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...
- hadoop mapreduce核心功能描述
核心功能描述 应用程序通常会通过提供map和reduce来实现 Mapper和Reducer接口,它们组成作业的核心. Mapper Mapper将输入键值对(key/value pair)映射到一组 ...
- hadoop之 hadoop 2.2.X 弃用的配置属性名称及其替换名称对照表
Deprecated Properties 弃用属性 The following table lists the configuration property names that are depr ...
- Hadoop专业解决方案-第5章 开发可靠的MapReduce应用
本章主要内容: 1.利用MRUnit创建MapReduce的单元测试. 2.MapReduce应用的本地实例. 3.理解MapReduce的调试. 4.利用MapReduce防御式程序设计. 在WOX ...
- Hadoop Map/Reduce教程
原文地址:http://hadoop.apache.org/docs/r1.0.4/cn/mapred_tutorial.html 目的 先决条件 概述 输入与输出 例子:WordCount v1.0 ...
- 一步一步跟我学习hadoop(5)----hadoop Map/Reduce教程(2)
Map/Reduce用户界面 本节为用户採用框架要面对的各个环节提供了具体的描写叙述,旨在与帮助用户对实现.配置和调优进行具体的设置.然而,开发时候还是要相应着API进行相关操作. 首先我们须要了解M ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- oracle中文显示为问号
在用PL/sql查询时,中文显示为问号.经查证,发现问题为oracle字符集不支持中文导致的.修改oracle字符集,改为支持中文即可. 方法: 第一步:修改注册表. 开始-运行-输入regedit- ...
- SQL Server密码管理的六个危险判断
当管理SQL Server内在的帐户和密码时,我们很容易认为这一切都相当的安全.但实际上并非如此.在这里,我们列出了一些对于SQL Server密码来说非常危险的判断. 当管理SQL Server内在 ...
- LODOP打印插件
HTML代码(请先下载对应LODOP插件安装) - 打印onclike事件CreatePrintPage()打印函数,LODOP.PREVIEW()打印预览. <div class=&q ...
- 重新想象 Windows 8 Store Apps (61) - 通信: http, oauth
[源码下载] 重新想象 Windows 8 Store Apps (61) - 通信: http, oauth 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 通信 ...
- javascript:Bing Maps AJAX Control, Version 7.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- x3dom 1.6 发布
X3DOM 库的1.6版本发布了,以下是最重要的一些变化: 完整的新的文档频道 - http://doc.x3dom.org x3dom实例频道 - http://examples.x3dom.or ...
- Linux命令详解之–cd命令
cd命令是linux实际使用当中另一个非常重要的命令,本文就为大家介绍下Linux中cd命令的用法. 更多Linux命令详情请看:Linux命令速查手册 Linux cd命令用于切换当前工作目录至 d ...
- oGrid 介绍如何从 server 取的资料
接着前次 oGrid 初探,其中有介绍如何操作local 资料,本次介绍如何从 server 取的资料. 依照 MVC 架构原理以及一条小龙本身经验来看,一个好的架构,必须要有着分工明确的设计层次,让 ...
- [WCF REST] Web消息主体风格(Message Body Style)
对于Web HTTP编程模型来说,服务契约中作为操作的方法无须应用OperationContractAttribute特性,只需要根据需要应用WebGetAttribute与WebInvokeAttr ...
- 【读书笔记】iOS-查看一个软件ipa包的内容
一,打开itunes----->我的iPhone应用程序. 二,右键点击app---->在Finder中显示---->出现下图所示界面. 三,将上图中的ipa包拷贝到桌面,如下图所示 ...