Jelajahi Sumber

HADOOP-553. Change main() routines in datanode and namenode to log exceptions rather than letting the JVM print them to standard error. Also change the hadoop-daemon.sh script to rotate standard i/o log files. Contributed by Raghu Angadi.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@469683 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 tahun lalu
induk
melakukan
f35ef67df3

+ 5 - 0
CHANGES.txt

@@ -100,6 +100,11 @@ Trunk (unreleased changes)
 27. HADOOP-651.  Fix DFSCk to correctly pass parameters to the servlet
     on the namenode.  (Milind Bhandarkar via cutting)
 
+28. HADOOP-553.  Change main() routines of DataNode and NameNode to
+    log exceptions rather than letting the JVM print them to standard
+    error.  Also, change the hadoop-daemon.sh script to rotate
+    standard i/o log files.  (Raghu Angadi via cutting)
+
 
 Release 0.7.2 - 2006-10-18
 

+ 18 - 0
bin/hadoop-daemon.sh

@@ -31,6 +31,23 @@ shift
 command=$1
 shift
 
+hadoop_rotate_log ()
+{
+    log=$1;
+    num=5;
+    if [ -n "$2" ]; then
+	num=$2
+    fi
+    if [ -f "$log" ]; then # rotate logs
+	while [ $num -gt 1 ]; do
+	    prev=`expr $num - 1`
+	    [ -f "$log.$prev" ] && mv "$log.$prev" "$log.$num"
+	    num=$prev
+	done
+	mv "$log" "$log.$num";
+    fi
+}
+
 if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then
   . "${HADOOP_CONF_DIR}/hadoop-env.sh"
 fi
@@ -76,6 +93,7 @@ case $startStop in
       rsync -a -e ssh --delete --exclude=.svn $HADOOP_MASTER/ "$HADOOP_HOME"
     fi
 
+    hadoop_rotate_log $log
     echo starting $command, logging to $log
     nohup nice -n $HADOOP_NICENESS "$HADOOP_HOME"/bin/hadoop --config $HADOOP_CONF_DIR $command "$@" > "$log" 2>&1 < /dev/null &
     echo $! > $pid

+ 5 - 0
src/java/org/apache/hadoop/dfs/DataNode.java

@@ -1105,8 +1105,13 @@ public class DataNode implements FSConstants, Runnable {
     /**
      */
     public static void main(String args[]) throws IOException {
+      try {
         Configuration conf = new Configuration();
         runAndWait(conf);
+      } catch ( Throwable e ) {
+        LOG.error( StringUtils.stringifyException( e ) );
+        System.exit(-1);
+      }
     }
 
 }

+ 7 - 0
src/java/org/apache/hadoop/dfs/NameNode.java

@@ -23,6 +23,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.*;
 import org.apache.hadoop.ipc.*;
 import org.apache.hadoop.conf.*;
+import org.apache.hadoop.util.StringUtils;
 
 import java.io.*;
 
@@ -568,6 +569,7 @@ public class NameNode implements ClientProtocol, DatanodeProtocol, FSConstants {
     /**
      */
     public static void main(String argv[]) throws Exception {
+      try {
         Configuration conf = new Configuration();
 
         if (argv.length == 1 && argv[0].equals("-format")) {
@@ -591,5 +593,10 @@ public class NameNode implements ClientProtocol, DatanodeProtocol, FSConstants {
         
         NameNode namenode = new NameNode(conf);
         namenode.join();
+        
+      } catch ( Throwable e ) {
+        LOG.error( StringUtils.stringifyException( e ) );
+        System.exit(-1);
+      }
     }
 }

+ 10 - 5
src/java/org/apache/hadoop/mapred/JobTracker.java

@@ -1230,12 +1230,17 @@ public class JobTracker implements MRConstants, InterTrackerProtocol, JobSubmiss
      * JobTracker should be run as part of the DFS Namenode process.
      */
     public static void main(String argv[]) throws IOException, InterruptedException {
-        if (argv.length != 0) {
-          System.out.println("usage: JobTracker");
-          System.exit(-1);
-        }
-
+      if (argv.length != 0) {
+        System.out.println("usage: JobTracker");
+        System.exit(-1);
+      }
+      
+      try {
         Configuration conf=new Configuration();
         startTracker(conf);
+      } catch ( Throwable e ) {
+        LOG.error( StringUtils.stringifyException( e ) );
+        System.exit(-1);
+      }
     }
 }

+ 4 - 4
src/java/org/apache/hadoop/mapred/TaskTracker.java

@@ -1367,10 +1367,10 @@ public class TaskTracker
           ReflectionUtils.setContentionTracing
               (conf.getBoolean("tasktracker.contention.tracking", false));
           new TaskTracker(conf).run();
-        } catch (IOException e) {
-            LOG.warn( "Can not start task tracker because "+
-                      StringUtils.stringifyException(e));
-            System.exit(-1);
+        } catch ( Throwable e ) {
+          LOG.error( "Can not start task tracker because "+
+                     StringUtils.stringifyException(e) );
+          System.exit(-1);
         }
     }