You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2008/03/26 23:15:09 UTC

svn commit: r641602 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/Trash.java src/test/org/apache/hadoop/dfs/TestTrash.java

Author: omalley
Date: Wed Mar 26 15:15:02 2008
New Revision: 641602

URL: http://svn.apache.org/viewvc?rev=641602&view=rev
Log:
HADOOP-3070. Protect the trash emptier thread from null pointer
exceptions. Contributed by Koji Noguchi.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/fs/Trash.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestTrash.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=641602&r1=641601&r2=641602&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Mar 26 15:15:02 2008
@@ -410,6 +410,9 @@
     making sure the directory is created first. (cdouglas and acmurthy 
     via omalley)
 
+    HADOOP-3070. Protect the trash emptier thread from null pointer
+    exceptions. (Koji Noguchi via omalley)
+
 Release 0.16.1 - 2008-03-13
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/Trash.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/Trash.java?rev=641602&r1=641601&r2=641602&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/Trash.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/Trash.java Wed Mar 26 15:15:02 2008
@@ -26,6 +26,7 @@
 
 import org.apache.hadoop.conf.*;
 import org.apache.hadoop.fs.permission.*;
+import org.apache.hadoop.util.StringUtils;
 
 /** Provides a <i>trash</i> feature.  Files are moved to a user's trash
  * directory, a subdirectory of their home directory named ".Trash".  Files are
@@ -142,6 +143,9 @@
   /** Delete old checkpoints. */
   public void expunge() throws IOException {
     Path[] dirs = fs.listPaths(trash);            // scan trash sub-directories
+    if( dirs == null){
+      return;
+    }
     long now = System.currentTimeMillis();
     for (int i = 0; i < dirs.length; i++) {
       Path path = dirs[i];
@@ -211,31 +215,36 @@
           return;                                 // exit on interrupt
         }
           
-        now = System.currentTimeMillis();
-        if (now >= end) {
-
-          FileStatus[] homes = null;
-          try {
-            homes = fs.listStatus(HOMES);         // list all home dirs
-          } catch (IOException e) {
-            LOG.warn("Trash can't list homes: "+e+" Sleeping.");
-            continue;
-          }
-
-          if (homes == null)
-            continue;
+        try {
+          now = System.currentTimeMillis();
+          if (now >= end) {
 
-          for (FileStatus home : homes) {         // dump each trash
-            if (!home.isDir())
-              continue;
+            FileStatus[] homes = null;
             try {
-              Trash trash = new Trash(home.getPath(), conf);
-              trash.expunge();
-              trash.checkpoint();
+              homes = fs.listStatus(HOMES);         // list all home dirs
             } catch (IOException e) {
-              LOG.warn("Trash caught: "+e+". Skipping "+home.getPath()+".");
+              LOG.warn("Trash can't list homes: "+e+" Sleeping.");
+              continue;
+            }
+
+            if (homes == null)
+              continue;
+
+            for (FileStatus home : homes) {         // dump each trash
+              if (!home.isDir())
+                continue;
+              try {
+                Trash trash = new Trash(home.getPath(), conf);
+                trash.expunge();
+                trash.checkpoint();
+              } catch (IOException e) {
+                LOG.warn("Trash caught: "+e+". Skipping "+home.getPath()+".");
+              } 
             }
           }
+        } catch (Exception e) {
+          LOG.warn("RuntimeException during Trash.Emptier.run() " + 
+                   StringUtils.stringifyException(e));
         }
       }
     }

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestTrash.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestTrash.java?rev=641602&r1=641601&r2=641602&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestTrash.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestTrash.java Wed Mar 26 15:15:02 2008
@@ -85,6 +85,21 @@
       Path myFile = new Path("/test/mkdirs/myFile");
       writeFile(fs, myFile);
 
+      // Verify that expunge without Trash directory 
+      // won't throw Exception
+      {
+        String[] args = new String[1];
+        args[0] = "-expunge";
+        int val = -1;
+        try {
+          val = shell.run(args);
+        } catch (Exception e) {
+          System.err.println("Exception raised from Trash.run " +
+                             e.getLocalizedMessage()); 
+        }
+        assertTrue(val == 0);
+      }
+
       // Verify that we succeed in removing the file we created.
       // This should go into Trash.
       {