فهرست منبع

HADOOP-311. Change DFS client to retry failed reads, so that a single read failure alone will not cause failure of a task. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@416062 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 سال پیش
والد
کامیت
732dcbf414
2فایلهای تغییر یافته به همراه23 افزوده شده و 7 حذف شده
  1. 4 0
      CHANGES.txt
  2. 19 7
      src/java/org/apache/hadoop/dfs/DFSClient.java

+ 4 - 0
CHANGES.txt

@@ -26,6 +26,10 @@ Trunk (unreleased changes)
     protocol: clients and servers must both be upgraded to the new
     version to ensure correct operation.  (Devaraj Das via cutting)
 
+ 7. HADOOP-311.  Change DFS client to retry failed reads, so that a
+    single read failure will not alone cause failure of a task.
+    (omalley via cutting)
+
 
 Release 0.3.2 - 2006-06-09
 

+ 19 - 7
src/java/org/apache/hadoop/dfs/DFSClient.java

@@ -634,14 +634,26 @@ class DFSClient implements FSConstants {
                 throw new IOException("Stream closed");
             }
             if (pos < filelen) {
-                if (pos > blockEnd) {
-                    blockSeekTo(pos);
-                }
-                int result = blockStream.read(buf, off, Math.min(len, (int) (blockEnd - pos + 1)));
-                if (result >= 0) {
-                    pos += result;
+              int retries = 2;
+              while (retries > 0) {
+                try {
+                  if (pos > blockEnd) {
+                      blockSeekTo(pos);
+                  }
+                  int realLen = Math.min(len, (int) (blockEnd - pos + 1));
+                  int result = blockStream.read(buf, off, realLen);
+                  if (result >= 0) {
+                      pos += result;
+                  }
+                  return result;
+                } catch (IOException e) {
+                  LOG.warn("DFS Read: " + StringUtils.stringifyException(e));
+                  blockEnd = -1;
+                  if (--retries == 0) {
+                    throw e;
+                  }
                 }
-                return result;
+              }
             }
             return -1;
         }