Hadoop调试信息的输出办法

 

Hadoop调试是比较麻烦的事情,考虑到只能通过reduce输出数据,我们可以把调试信息输出到reduce中,然后固定到某个文件中。

 

我们可以把所有的调试数据都是用key=Debug”,调试信息作为value=debugInfo”。

1)在map中直接使用

output.collect(new Text("debug"), new Text("调试信息"));

2)在reduce中判断

  1. if(key. equals ("debug"))
  2. {
  3.                             while (values.hasNext()) 
  4.                             {
  5.                                 String line = values.next().toString();
  6.                                 output.collect(new Text("debug"), new Text(line));
  7.                             }
  8. }

(3)增加类ReportOutFormat

  1.  public static class ReportOutFormat<K extends WritableComparable<?>, V extends Writable>
  2.     extends MultipleOutputFormat<K, V> {
  3. private TextOutputFormat<K, V> theTextOutputFormat = null;
  4. @Override
  5. protected RecordWriter<K, V> getBaseRecordWriter(FileSystem fs,
  6.         JobConf job, String name, Progressable arg3) throws IOException {
  7.     if (theTextOutputFormat == null) {
  8.         theTextOutputFormat = new TextOutputFormat<K, V>();
  9.     }
  10.     return theTextOutputFormat.getRecordWriter(fs, job, name, arg3);
  11. }
  12. @Override
  13. protected String generateFileNameForKeyValue(K key, V value, String name) {
  14.     if(key.equals("debug"))   ///注意这个判断
  15.         return "debug"+name;
  16.     return name ;
  17. }
  18. }

4)在configJob里面添加代码

  1. protected void configJob(JobConf conf) 
  2. {
  3.           conf.setMapOutputKeyClass(Text.class);
  4.           conf.setMapOutputValueClass(Text.class);
  5.           conf.setOutputKeyClass(Text.class);  
  6.           conf.setOutputValueClass(Text.class); 
  7.           conf.setOutputFormat(ReportOutFormat.class); //增加该行
  8. }

这样在输出文件中我们就可以得到调试信息了。这个办法有点曲线救国的意思,不知道有没有其他方便的办法。

你可能感兴趣的:(hadoop,null)