Explorar o código

HADOOP-1200. Restore disk checking lost in HADOOP-1170. Contributed by Hairong.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@535993 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting %!s(int64=18) %!d(string=hai) anos
pai
achega
7eb432d880
Modificáronse 2 ficheiros con 43 adicións e 14 borrados
  1. 3 0
      CHANGES.txt
  2. 40 14
      src/java/org/apache/hadoop/dfs/DataNode.java

+ 3 - 0
CHANGES.txt

@@ -348,6 +348,9 @@ Trunk (unreleased changes)
 103. HADOOP-1270.  Randomize the fetch of map outputs, speeding the
      shuffle.  (Arun C Murthy via cutting)
 
+104. HADOOP-1200.  Restore disk checking lost in HADOOP-1170.
+     (Hairong Kuang via cutting)
+
 
 Release 0.12.3 - 2007-04-06
 

+ 40 - 14
src/java/org/apache/hadoop/dfs/DataNode.java

@@ -389,8 +389,29 @@ public class DataNode implements FSConstants, Runnable {
       }
     }
   }
-
-  void handleDiskError(String errMsgr) {
+  
+  
+  /* Check if there is no space in disk or the disk is read-only
+   *  when IOException occurs. 
+   * If so, handle the error */
+  private void checkDiskError( IOException e ) throws IOException {
+    if (e.getMessage().startsWith("No space left on device")) {
+      throw new DiskOutOfSpaceException("No space left on device");
+    } else {
+      checkDiskError();
+    }
+  }
+  
+  /* Check if there is no disk space and if so, handle the error*/
+  private void checkDiskError( ) throws IOException {
+    try {
+      data.checkDataDir();
+    } catch(DiskErrorException de) {
+      handleDiskError(de.getMessage());
+    }
+  }
+  
+  private void handleDiskError(String errMsgr) {
     LOG.warn("DataNode is shutting down.\n" + errMsgr);
     try {
       namenode.errorReport(
@@ -494,9 +515,6 @@ public class DataNode implements FSConstants, Runnable {
             }
           }
         } // synchronized
-      } catch(DiskErrorException e) {
-        handleDiskError(e.getLocalizedMessage());
-        return;
       } catch(RemoteException re) {
         String reClass = re.getClassName();
         if (UnregisteredDatanodeException.class.getName().equals(reClass) ||
@@ -536,7 +554,12 @@ public class DataNode implements FSConstants, Runnable {
       // safely garbage-collected.
       //
       Block toDelete[] = ((BlockCommand)cmd).getBlocks();
-      data.invalidate(toDelete);
+      try {
+        data.invalidate(toDelete);
+      } catch(IOException e) {
+        checkDiskError();
+        throw e;
+      }
       myMetrics.removedBlocks(toDelete.length);
       break;
     case DNA_SHUTDOWN:
@@ -804,7 +827,14 @@ public class DataNode implements FSConstants, Runnable {
         //
         // Open local disk out
         //
-        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(data.writeToBlock(b)));
+        OutputStream o;
+        try {
+          o = data.writeToBlock(b);
+        } catch( IOException e ) {
+          checkDiskError( e );
+          throw e;
+        }
+        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(o));
         InetSocketAddress mirrorTarget = null;
         String mirrorNode = null;
         try {
@@ -893,12 +923,8 @@ public class DataNode implements FSConstants, Runnable {
                   out.write(buf, 0, bytesRead);
                   myMetrics.wroteBytes(bytesRead);
                 } catch (IOException iex) {
-                  if (iex.getMessage().startsWith("No space left on device")) {
-                    throw new DiskOutOfSpaceException("No space left on device");
-                  } else {
-                    shutdown();
-                    throw iex;
-                  }
+                  checkDiskError(iex);
+                  throw iex;
                 }
                 len -= bytesRead;
               }
@@ -972,7 +998,7 @@ public class DataNode implements FSConstants, Runnable {
           try {
             out.close();
           } catch (IOException iex) {
-            shutdown();
+            checkDiskError(iex);
             throw iex;
           }
         }