bilaharith commented on a change in pull request #2464:
URL: https://github.com/apache/hadoop/pull/2464#discussion_r526588250



##########
File path: 
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java
##########
@@ -162,14 +172,86 @@ private int readOneBlock(final byte[] b, final int off, 
final int len) throws IO
       throw new IndexOutOfBoundsException();
     }
 
-    //If buffer is empty, then fill the buffer.
-    if (bCursor == limit) {
+    if (firstRead && this.readSmallFilesCompletely
+        && contentLength <= bufferSize) { //  Read small files completely
+      if (readFileCompletely() == -1) {
+        return -1;
+      }
+    } else if (firstRead && this.optimizeFooterRead && fCursor
+        == contentLength - FOOTER_DELTA) {  //  Read the last one block if the
+      // read is for the footer
+      if (readLastBlock() == -1) {
+        return -1;
+      }
+    } else {
+      if (readOneBlock(b) == -1) {
+        return -1;
+      }
+    }
+    fCursorAfterLastRead = fCursor;
+
+    //If there is anything in the buffer, then return lesser of (requested 
bytes) and (bytes in buffer)
+    //(bytes returned may be less than requested)
+    int bytesRemaining = limit - bCursor;
+    int bytesToRead = Math.min(len, bytesRemaining);
+    System.arraycopy(buffer, bCursor, b, off, bytesToRead);
+    bCursor += bytesToRead;
+    if (statistics != null) {
+      statistics.incrementBytesRead(bytesToRead);
+    }
+    if (streamStatistics != null) {
+      // Bytes read from the local buffer.
+      streamStatistics.bytesReadFromBuffer(bytesToRead);
+      streamStatistics.bytesRead(bytesToRead);
+    }
+    return bytesToRead;
+  }
+
+  private long readFileCompletely() throws IOException {
+    bCursor = (int) getPos();

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to