You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by sm...@apache.org on 2009/07/21 19:03:04 UTC

svn commit: r796382 - in /hadoop/pig/trunk: ./ src/org/apache/pig/ src/org/apache/pig/backend/executionengine/ src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/ src/org/apache/pig/impl/util/

Author: sms
Date: Tue Jul 21 17:03:04 2009
New Revision: 796382

URL: http://svn.apache.org/viewvc?rev=796382&view=rev
Log:
PIG-695: Pig should not fail when error logs cannot be created

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/Main.java
    hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/PigSlicer.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/Launcher.java
    hadoop/pig/trunk/src/org/apache/pig/impl/util/LogUtils.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=796382&r1=796381&r2=796382&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Tue Jul 21 17:03:04 2009
@@ -40,6 +40,8 @@
 
 BUG FIXES
 
+    PIG-695: Pig should not fail when error logs cannot be created (sms)
+
 	PIG-878: Pig is returning too many blocks in the input split. (arunc via gates).
 
     PIG-888: Pig do not pass udf to the backend in some situation (daijy)

Modified: hadoop/pig/trunk/src/org/apache/pig/Main.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/Main.java?rev=796382&r1=796381&r2=796382&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/Main.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/Main.java Tue Jul 21 17:03:04 2009
@@ -76,6 +76,7 @@
     boolean verbose = false;
     boolean gruntCalled = false;
     String logFileName = null;
+    boolean userSpecifiedLog = false;
 
     try {
         BufferedReader pin = null;
@@ -199,7 +200,8 @@
                 } else {
                     logFileName = validateLogFile(logFileName, null);
                 }
-                properties.setProperty("pig.logfile", logFileName);
+                userSpecifiedLog = true;
+                properties.setProperty("pig.logfile", (logFileName == null? "": logFileName));
                 break;
 
             case 'm':
@@ -263,11 +265,15 @@
         // create the context with the parameter
         PigContext pigContext = new PigContext(execType, properties);
         
-        if(logFileName == null) {
+        if(logFileName == null && !userSpecifiedLog) {
             logFileName = validateLogFile(null, null);
         }
         
-        pigContext.getProperties().setProperty("pig.logfile", logFileName);
+        if(logFileName != null) {
+            log.info("Logging error messages to: " + logFileName);
+        }
+        
+        pigContext.getProperties().setProperty("pig.logfile", (logFileName == null? "": logFileName));
         
         if(optimizerRules.size() > 0) {
         	pigContext.getProperties().setProperty("pig.optimizer.rules", ObjectSerializer.serialize(optimizerRules));
@@ -547,7 +553,7 @@
         System.out.println("    -m, -param_file path to the parameter file");
         System.out.println("    -o, -hod read hod server from system property ssh.gateway");
         System.out.println("    -p, -param key value pair of the form param=val");
-        System.out.println("    -r, -dryrun CmdLineParser.ValueExpected.NOT_ACCEPTED");
+        System.out.println("    -r, -dryrun");
         System.out.println("    -t, -optimizer_off optimizer rule name, turn optimizer off for this rule; use all to turn all rules off, optimizer is turned on by default");
         System.out.println("    -v, -verbose print all error messages to screen");
         System.out.println("    -w, -warning turn warning on; also turns warning aggregation off");
@@ -567,7 +573,8 @@
             try {
                 scriptFileAbsPath = scriptFile.getCanonicalPath();
             } catch (IOException ioe) {
-                throw new AssertionError("Could not compute canonical path to the script file " + ioe.getMessage());      
+                log.warn("Could not compute canonical path to the script file " + ioe.getMessage());
+                return null;
             }            
             strippedDownScriptName = getFileFromCanonicalPath(scriptFileAbsPath);
         }
@@ -586,11 +593,13 @@
                 try {
                     logFileName = logFile.getCanonicalPath() + File.separator + defaultLogFileName;
                 } catch (IOException ioe) {
-                    throw new AssertionError("Could not compute canonical path to the log file " + ioe.getMessage());       
+                    log.warn("Could not compute canonical path to the log file " + ioe.getMessage());
+                    return null;
                 }
                 return logFileName;
             } else {
-                throw new AssertionError("Need write permission in the directory: " + logFileName + " to create log file.");
+                log.warn("Need write permission in the directory: " + logFileName + " to create log file.");
+                return null;
             }
         } else {
             //we have a relative path or an absolute path to the log file
@@ -601,13 +610,15 @@
                     try {
                         logFileName = new File(logFileName).getCanonicalPath();
                     } catch (IOException ioe) {
-                        throw new AssertionError("Could not compute canonical path to the log file " + ioe.getMessage());
+                        log.warn("Could not compute canonical path to the log file " + ioe.getMessage());
+                        return null;
                     }
                     return logFileName;
                 } else {
                     //do not have write permissions for the log file
                     //bail out with an error message
-                    throw new AssertionError("Cannot write to file: " + logFileName + ". Need write permission.");
+                    log.warn("Cannot write to file: " + logFileName + ". Need write permission.");
+                    return logFileName;
                 }
             } else {
                 logFile = logFile.getParentFile();
@@ -618,11 +629,13 @@
                         try {
                             logFileName = new File(logFileName).getCanonicalPath();
                         } catch (IOException ioe) {
-                            throw new AssertionError("Could not compute canonical path to the log file " + ioe.getMessage());
+                            log.warn("Could not compute canonical path to the log file " + ioe.getMessage());
+                            return null;
                         }
                         return logFileName;
                     } else {
-                        throw new AssertionError("Need write permission in the directory: " + logFile + " to create log file.");
+                        log.warn("Need write permission in the directory: " + logFile + " to create log file.");
+                        return logFileName;
                     }
                 }//end if logFile != null else is the default in fall through                
             }//end else part of logFile.exists()
@@ -637,7 +650,8 @@
     if(logFile.canWrite()) {        
         return logFileName;
     }    
-    throw new RuntimeException("Cannot write to log file: " + logFileName);
+    log.warn("Cannot write to log file: " + logFileName);
+    return null;
 }
 
 private static String getFileFromCanonicalPath(String canonicalPath) {

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/PigSlicer.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/PigSlicer.java?rev=796382&r1=796381&r2=796382&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/PigSlicer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/PigSlicer.java Tue Jul 21 17:03:04 2009
@@ -82,7 +82,7 @@
                 }
             } catch (Exception e) {
                 int errCode = 2099;
-                String msg = "Problem in constructing slices.";
+                String msg = "Problem in constructing slices: " + e.getMessage();
                 throw new ExecException(msg, errCode, PigException.BUG, e);
             }
             Map<String, Object> stats = fullPath.getStatistics();

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/Launcher.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/Launcher.java?rev=796382&r1=796381&r2=796382&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/Launcher.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/Launcher.java Tue Jul 21 17:03:04 2009
@@ -489,7 +489,7 @@
             		}		                		
             	} else { //else for if(object instanceof PigException)
             		//its not PigException; create the exception with the message
-            		object = PigContext.instantiateFuncFromSpec(exceptionName + "(" + exceptionMessage + ")");
+            		object = PigContext.instantiateFuncFromSpec(new FuncSpec(exceptionName, exceptionMessage));
             	}
             	
             	StackTraceElement[] steArr = new StackTraceElement[stackTraceElements.size()];

Modified: hadoop/pig/trunk/src/org/apache/pig/impl/util/LogUtils.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/util/LogUtils.java?rev=796382&r1=796381&r2=796382&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/util/LogUtils.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/util/LogUtils.java Tue Jul 21 17:03:04 2009
@@ -119,7 +119,7 @@
             log.error(bs.toString());
         }
         
-        if(logFileName == null) {
+        if(logFileName == null || logFileName.equals("")) {
             //if exec is invoked programmatically then logFileName will be null
             log.warn("There is no log file to write to.");
             log.error(bs.toString());
@@ -163,10 +163,10 @@
     }
     
     public static void writeLog(String headerMessage, String message, String logFileName, Log log) {
-        if(logFileName == null) {
+        if(logFileName == null || logFileName.equals("")) {
             //if exec is invoked programmatically then logFileName will be null
             log.warn("There is no log file to write to.");
-            log.error(message);
+            log.error(headerMessage + "\n" + message);
             return;
         }