Repository: hadoop
Updated Branches:
  refs/heads/ozone-0.3 2cad68b48 -> ca1d4c46d
  refs/heads/trunk 85ccab7d3 -> 56b18b9df


HDDS-639. ChunkGroupInputStream gets into infinite loop after reading a block. 
Contributed by Mukul Kumar Singh.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/56b18b9d
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/56b18b9d
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/56b18b9d

Branch: refs/heads/trunk
Commit: 56b18b9df14b91c02cf3b7f548ab58755475b374
Parents: 85ccab7
Author: Arpit Agarwal <[email protected]>
Authored: Fri Oct 12 13:33:38 2018 -0700
Committer: Arpit Agarwal <[email protected]>
Committed: Fri Oct 12 13:33:38 2018 -0700

----------------------------------------------------------------------
 .../hadoop/ozone/client/io/ChunkGroupInputStream.java    |  6 +++++-
 .../apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java  | 11 ++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/56b18b9d/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ChunkGroupInputStream.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ChunkGroupInputStream.java
 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ChunkGroupInputStream.java
index 7791613..125784c 100644
--- 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ChunkGroupInputStream.java
+++ 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/ChunkGroupInputStream.java
@@ -111,7 +111,11 @@ public class ChunkGroupInputStream extends InputStream 
implements Seekable {
     }
     int totalReadLen = 0;
     while (len > 0) {
-      if (streamEntries.size() <= currentStreamIndex) {
+      // if we are at the last block and have read the entire block, return
+      if (streamEntries.size() == 0 ||
+              (streamEntries.size() - 1 <= currentStreamIndex &&
+                      streamEntries.get(currentStreamIndex)
+                              .getRemaining() == 0)) {
         return totalReadLen == 0 ? EOF : totalReadLen;
       }
       ChunkInputStreamEntry current = streamEntries.get(currentStreamIndex);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/56b18b9d/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java
----------------------------------------------------------------------
diff --git 
a/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java
 
b/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java
index 7cf6e3d..2176031 100644
--- 
a/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java
+++ 
b/hadoop-ozone/ozonefs/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileInterfaces.java
@@ -174,9 +174,18 @@ public class TestOzoneFileInterfaces {
 
     try (FSDataInputStream inputStream = fs.open(path)) {
       byte[] buffer = new byte[stringLen];
-      inputStream.readFully(0, buffer);
+      // This read will not change the offset inside the file
+      int readBytes = inputStream.read(0, buffer, 0, buffer.length);
       String out = new String(buffer, 0, buffer.length);
       assertEquals(data, out);
+      assertEquals(readBytes, buffer.length);
+      assertEquals(0, inputStream.getPos());
+
+      // The following read will change the internal offset
+      readBytes = inputStream.read(buffer, 0, buffer.length);
+      assertEquals(data, out);
+      assertEquals(readBytes, buffer.length);
+      assertEquals(buffer.length, inputStream.getPos());
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to