You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by na...@apache.org on 2012/03/31 16:30:06 UTC

svn commit: r1307814 - in /hive/trunk: common/src/java/org/apache/hadoop/hive/common/io/ data/scripts/ ql/src/java/org/apache/hadoop/hive/ql/ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/session/ ql/src/test/org/apa...

Author: namit
Date: Sat Mar 31 14:30:05 2012
New Revision: 1307814

URL: http://svn.apache.org/viewvc?rev=1307814&view=rev
Log:
HIVE-2866 Cache local map reduce job errors for additional logging
(Kevin Wilfong via namit)


Added:
    hive/trunk/data/scripts/cat_error.py
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/hooks/VerifySessionStateLocalErrorsHook.java
    hive/trunk/ql/src/test/queries/clientnegative/local_mapred_error_cache.q
    hive/trunk/ql/src/test/results/clientnegative/local_mapred_error_cache.q.out
Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/common/io/CachingPrintStream.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/io/CachingPrintStream.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/io/CachingPrintStream.java?rev=1307814&r1=1307813&r2=1307814&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/io/CachingPrintStream.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/io/CachingPrintStream.java Sat Mar 31 14:30:05 2012
@@ -36,6 +36,11 @@ public class CachingPrintStream extends 
     super(out, autoFlush, encoding);
   }
 
+  public CachingPrintStream(OutputStream out) {
+
+    super(out);
+  }
+
   @Override
   public void println(String out) {
     output.add(out);

Added: hive/trunk/data/scripts/cat_error.py
URL: http://svn.apache.org/viewvc/hive/trunk/data/scripts/cat_error.py?rev=1307814&view=auto
==============================================================================
--- hive/trunk/data/scripts/cat_error.py (added)
+++ hive/trunk/data/scripts/cat_error.py Sat Mar 31 14:30:05 2012
@@ -0,0 +1,6 @@
+import sys
+
+for line in sys.stdin:
+  print line
+
+sys.exit(1)

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java?rev=1307814&r1=1307813&r2=1307814&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java Sat Mar 31 14:30:05 2012
@@ -1100,6 +1100,7 @@ public class Driver implements CommandPr
       DriverContext driverCxt = new DriverContext(runnable, ctx);
 
       SessionState.get().setLastMapRedStatsList(new ArrayList<MapRedStats>());
+      SessionState.get().setLocalMapRedErrors(new HashMap<String, List<String>>());
 
       // Add root Tasks to runnable
 

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java?rev=1307814&r1=1307813&r2=1307814&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java Sat Mar 31 14:30:05 2012
@@ -31,6 +31,7 @@ import org.apache.hadoop.fs.ContentSumma
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.io.CachingPrintStream;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.hadoop.hive.ql.Context;
@@ -266,12 +267,15 @@ public class MapRedTask extends ExecDriv
       // Run ExecDriver in another JVM
       executor = Runtime.getRuntime().exec(cmdLine, env, new File(workDir));
 
+      CachingPrintStream errPrintStream =
+          new CachingPrintStream(SessionState.getConsole().getChildErrStream());
+
       StreamPrinter outPrinter = new StreamPrinter(
           executor.getInputStream(), null,
           SessionState.getConsole().getChildOutStream());
       StreamPrinter errPrinter = new StreamPrinter(
           executor.getErrorStream(), null,
-          SessionState.getConsole().getChildErrStream());
+          errPrintStream);
 
       outPrinter.start();
       errPrinter.start();
@@ -280,6 +284,9 @@ public class MapRedTask extends ExecDriv
 
       if (exitVal != 0) {
         LOG.error("Execution failed with exit status: " + exitVal);
+        if (SessionState.get() != null) {
+          SessionState.get().addLocalMapRedErrors(getId(), errPrintStream.getOutput());
+        }
       } else {
         LOG.info("Execution completed successfully");
       }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java?rev=1307814&r1=1307813&r2=1307814&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java Sat Mar 31 14:30:05 2012
@@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.io.CachingPrintStream;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.ql.Context;
 import org.apache.hadoop.hive.ql.DriverContext;
@@ -216,8 +217,10 @@ public class MapredLocalTask extends Tas
       // Run ExecDriver in another JVM
       executor = Runtime.getRuntime().exec(cmdLine, env, new File(workDir));
 
+      CachingPrintStream errPrintStream = new CachingPrintStream(System.err);
+
       StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out);
-      StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err);
+      StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, errPrintStream);
 
       outPrinter.start();
       errPrinter.start();
@@ -226,6 +229,9 @@ public class MapredLocalTask extends Tas
 
       if (exitVal != 0) {
         LOG.error("Execution failed with exit status: " + exitVal);
+        if (SessionState.get() != null) {
+          SessionState.get().addLocalMapRedErrors(getId(), errPrintStream.getOutput());
+        }
       } else {
         LOG.info("Execution completed successfully");
         console.printInfo("Mapred Local Task Succeeded . Convert the Join into MapJoin");

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java?rev=1307814&r1=1307813&r2=1307814&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java Sat Mar 31 14:30:05 2012
@@ -24,6 +24,7 @@ import java.io.InputStream;
 import java.io.PrintStream;
 import java.net.URI;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
@@ -122,6 +123,8 @@ public class SessionState {
   // changes the value of a variable, the corresponding change will be made in this mapping.
   private Map<String, String> overriddenConfigurations;
 
+  private Map<String, List<String>> localMapRedErrors;
+
   /**
    * Lineage state.
    */
@@ -718,4 +721,20 @@ public class SessionState {
   public void setOverriddenConfigurations(Map<String, String> overriddenConfigurations) {
     this.overriddenConfigurations = overriddenConfigurations;
   }
+
+  public Map<String, List<String>> getLocalMapRedErrors() {
+    return localMapRedErrors;
+  }
+
+  public void addLocalMapRedErrors(String id, List<String> localMapRedErrors) {
+    if (!this.localMapRedErrors.containsKey(id)) {
+      this.localMapRedErrors.put(id, new ArrayList<String>());
+    }
+
+    this.localMapRedErrors.get(id).addAll(localMapRedErrors);
+  }
+
+  public void setLocalMapRedErrors(Map<String, List<String>> localMapRedErrors) {
+    this.localMapRedErrors = localMapRedErrors;
+  }
 }

Added: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/hooks/VerifySessionStateLocalErrorsHook.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/hooks/VerifySessionStateLocalErrorsHook.java?rev=1307814&view=auto
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/hooks/VerifySessionStateLocalErrorsHook.java (added)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/hooks/VerifySessionStateLocalErrorsHook.java Sat Mar 31 14:30:05 2012
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.hooks;
+
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
+
+/**
+ *
+ * VerifySessionStateLocalErrorsHook.
+ *
+ * This hook is intended for testing that the localMapRedErrors variable in SessionState is
+ * populated when a local map reduce job fails.  It prints the ID of the stage that failed, and
+ * the lines recorded in the variable.
+ */
+public class VerifySessionStateLocalErrorsHook implements ExecuteWithHookContext {
+
+  public void run(HookContext hookContext) {
+    LogHelper console = SessionState.getConsole();
+
+    for (Entry<String, List<String>> entry : SessionState.get().getLocalMapRedErrors().entrySet()) {
+      console.printError("ID: " + entry.getKey());
+
+      for (String line : entry.getValue()) {
+        console.printError(line);
+      }
+    }
+  }
+}

Added: hive/trunk/ql/src/test/queries/clientnegative/local_mapred_error_cache.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/local_mapred_error_cache.q?rev=1307814&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/local_mapred_error_cache.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/local_mapred_error_cache.q Sat Mar 31 14:30:05 2012
@@ -0,0 +1,4 @@
+set hive.exec.mode.local.auto=true;
+set hive.exec.failure.hooks=org.apache.hadoop.hive.ql.hooks.VerifySessionStateLocalErrorsHook;
+
+FROM src SELECT TRANSFORM(key, value) USING 'python ../data/scripts/cat_error.py' AS (key, value);

Added: hive/trunk/ql/src/test/results/clientnegative/local_mapred_error_cache.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/local_mapred_error_cache.q.out?rev=1307814&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/local_mapred_error_cache.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/local_mapred_error_cache.q.out Sat Mar 31 14:30:05 2012
@@ -0,0 +1,24 @@
+PREHOOK: query: FROM src SELECT TRANSFORM(key, value) USING 'python ../data/scripts/cat_error.py' AS (key, value)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+Execution failed with exit status: 2
+Obtaining error information
+
+Task failed!
+Task ID:
+  Stage-1
+
+Logs:
+
+#### A masked pattern was here ####
+ID: Stage-1
+org.apache.hadoop.hive.ql.metadata.HiveException: Hit error while closing ..
+#### A masked pattern was here ####
+org.apache.hadoop.hive.ql.metadata.HiveException: Hit error while closing ..
+#### A masked pattern was here ####
+org.apache.hadoop.hive.ql.metadata.HiveException: Hit error while closing ..
+#### A masked pattern was here ####
+Ended Job = job_local_0001 with errors
+Error during job, obtaining debugging information...
+FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.MapRedTask