MAPREDUCE-1894. Fixed a bug in DistributedRaidFileSystem.readFully() 
that was causing it to loop infinitely. (Ramkumar Vadali via dhruba)



git-svn-id: https://svn.apache.org/repos/asf/hadoop/mapreduce/trunk@960802 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index b76c72b..2460030 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -143,6 +143,9 @@
     MAPREDUCE-577. Fixes duplicate records in StreamXmlRecordReader.
     (Ravi Gummadi via amareshwari)
 
+    MAPREDUCE-1894. Fixed a bug in DistributedRaidFileSystem.readFully() 
+    that was causing it to loop infinitely. (Ramkumar Vadali via dhruba)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES
diff --git a/src/contrib/raid/src/java/org/apache/hadoop/hdfs/DistributedRaidFileSystem.java b/src/contrib/raid/src/java/org/apache/hadoop/hdfs/DistributedRaidFileSystem.java
index 72cda6b..e3b8088 100644
--- a/src/contrib/raid/src/java/org/apache/hadoop/hdfs/DistributedRaidFileSystem.java
+++ b/src/contrib/raid/src/java/org/apache/hadoop/hdfs/DistributedRaidFileSystem.java
@@ -297,6 +297,7 @@
           try {
             underLyingStream.readFully(pos, b, offset, length);
             nextLocation = 0;
+            return;
           } catch (BlockMissingException e) {
             setAlternateLocations(e, post);
           } catch (ChecksumException e) {
@@ -312,6 +313,7 @@
           try {
             underLyingStream.readFully(pos, b);
             nextLocation = 0;
+            return;
           } catch (BlockMissingException e) {
             setAlternateLocations(e, post);
           } catch (ChecksumException e) {
diff --git a/src/contrib/raid/src/test/org/apache/hadoop/hdfs/TestRaidDfs.java b/src/contrib/raid/src/test/org/apache/hadoop/hdfs/TestRaidDfs.java
index b70c19a..c788a1e 100644
--- a/src/contrib/raid/src/test/org/apache/hadoop/hdfs/TestRaidDfs.java
+++ b/src/contrib/raid/src/test/org/apache/hadoop/hdfs/TestRaidDfs.java
@@ -200,6 +200,40 @@
     }
     LOG.info("Test testPathFilter completed.");
   }
+
+  /**
+   * Test DistributedRaidFileSystem.readFully()
+   */
+  public void testReadFully() throws Exception {
+    mySetup();
+
+    try {
+      Path file = new Path("/user/raid/raidtest/file1");
+      createOldFile(fileSys, file, 1, 7, 8192L);
+
+      // filter all filesystem calls from client
+      Configuration clientConf = new Configuration(conf);
+      clientConf.set("fs.hdfs.impl",
+                      "org.apache.hadoop.hdfs.DistributedRaidFileSystem");
+      clientConf.set("fs.raid.underlyingfs.impl",
+                      "org.apache.hadoop.hdfs.DistributedFileSystem");
+      URI dfsUri = dfs.getFileSystem().getUri();
+      FileSystem.closeAll();
+      FileSystem raidfs = FileSystem.get(dfsUri, clientConf);
+
+      FileStatus stat = raidfs.getFileStatus(file);
+      byte[] filebytes = new byte[(int)stat.getLen()];
+      FSDataInputStream stm = raidfs.open(file);
+      // Test that readFully returns.
+      stm.readFully(filebytes, 0, (int)stat.getLen());
+
+      stm = raidfs.open(file);
+      // Test that readFully returns.
+      stm.readFully(filebytes);
+    } finally {
+      myTearDown();
+    }
+  }
   
   //
   // creates a file and populate it with random data. Returns its crc.