hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r664202 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/FSDirectory.java src/java/org/apache/hadoop/dfs/FSNamesystem.java src/java/org/apache/hadoop/io/IOUtils.java
Date Fri, 06 Jun 2008 23:52:32 GMT
Author: shv
Date: Fri Jun  6 16:52:32 2008
New Revision: 664202

URL: http://svn.apache.org/viewvc?rev=664202&view=rev
Log:
HADOOP-3509. Fix NPE in FSNamesystem.close. Contributed by Tsz Wo (Nicholas), SZE.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
    hadoop/core/trunk/src/java/org/apache/hadoop/io/IOUtils.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=664202&r1=664201&r2=664202&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Jun  6 16:52:32 2008
@@ -526,6 +526,8 @@
 
     HADOOP-3489. Fix NPE in SafeModeMonitor. (Lohit Vijayarenu via shv)
 
+    HADOOP-3509. Fix NPE in FSNamesystem.close. (Tsz Wo (Nicholas), SZE via shv)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java?rev=664202&r1=664201&r2=664202&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java Fri Jun  6 16:52:32
2008
@@ -38,7 +38,7 @@
  * and logged to disk.
  * 
  *************************************************/
-class FSDirectory implements FSConstants {
+class FSDirectory implements FSConstants, Closeable {
 
   FSNamesystem namesystem = null;
   final INodeDirectoryWithQuota rootDir;

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?rev=664202&r1=664201&r2=664202&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Fri Jun  6 16:52:32
2008
@@ -38,6 +38,7 @@
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.*;
 import org.apache.hadoop.ipc.Server;
+import org.apache.hadoop.io.IOUtils;
 
 import java.io.BufferedWriter;
 import java.io.File;
@@ -250,6 +251,7 @@
     try {
       initialize(nn, conf);
     } catch(IOException e) {
+      LOG.error(getClass().getSimpleName() + " initialization failed.", e);
       close();
       throw e;
     }
@@ -461,11 +463,7 @@
         }
       } catch (InterruptedException ie) {
       } finally {
-        try {
-          dir.close();
-        } catch (IOException ex) {
-          // do nothing
-        }
+        IOUtils.close(LOG, dir);
       }
     }
   }

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/io/IOUtils.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/io/IOUtils.java?rev=664202&r1=664201&r2=664202&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/io/IOUtils.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/io/IOUtils.java Fri Jun  6 16:52:32 2008
@@ -21,6 +21,8 @@
 import java.io.*;
 import java.net.Socket;
 
+import org.apache.commons.logging.Log;
+
 import org.apache.hadoop.conf.Configuration;
 
 /**
@@ -121,17 +123,30 @@
   }
   
   /**
+   * Close the Closeable objects.
+   * Log {@link IOException} if there is any. 
+   * @param closeables the objects to close
+   */
+  public static void close(Log log, java.io.Closeable... closeables) {
+    for(java.io.Closeable c : closeables) {
+      if (c != null) {
+        try {
+          c.close();
+        } catch(IOException e) {
+          if (log != null && log.isDebugEnabled()) {
+            log.debug("Exception in closing " + c, e);
+          }
+        }
+      }
+    }
+  }
+
+  /**
    * Closes the stream ignoring {@link IOException} 
    * @param stream the Stream to close
    */
   public static void closeStream( java.io.Closeable stream ) {
-    // avoids try { close() } dance
-    if ( stream != null ) {
-      try {
-        stream.close();
-      } catch ( IOException ignored ) {
-      }
-    }
+    close(null, stream);
   }
   
   /**



Mime
View raw message