[ 
https://issues.apache.org/jira/browse/HADOOP-17890?focusedWorklogId=650005&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-650005
 ]

ASF GitHub Bot logged work on HADOOP-17890:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Sep/21 13:11
            Start Date: 13/Sep/21 13:11
    Worklog Time Spent: 10m 
      Work Description: snvijaya commented on a change in pull request #3381:
URL: https://github.com/apache/hadoop/pull/3381#discussion_r707319307



##########
File path: 
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpOperation.java
##########
@@ -369,58 +378,75 @@ public void processResponse(final byte[] buffer, final 
int offset, final int len
       startTime = System.nanoTime();
     }
 
-    if (statusCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
-      processStorageErrorResponse();
+    long totalBytesRead = 0;
+
+    try {
+      totalBytesRead = parseResponse(buffer, offset, length);
+    } finally {
       if (this.isTraceEnabled) {
         this.recvResponseTimeMs += elapsedTimeMs(startTime);
       }
-      this.bytesReceived = 
this.connection.getHeaderFieldLong(HttpHeaderConfigurations.CONTENT_LENGTH, 0);
-    } else {
-      // consume the input stream to release resources
-      int totalBytesRead = 0;
+      this.bytesReceived = totalBytesRead;
+    }
+  }
 
+  public long parseResponse(final byte[] buffer,

Review comment:
       Have added the javadocs.

##########
File path: 
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsHttpOperation.java
##########
@@ -369,58 +378,75 @@ public void processResponse(final byte[] buffer, final 
int offset, final int len
       startTime = System.nanoTime();
     }
 
-    if (statusCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
-      processStorageErrorResponse();
+    long totalBytesRead = 0;
+
+    try {
+      totalBytesRead = parseResponse(buffer, offset, length);
+    } finally {
       if (this.isTraceEnabled) {
         this.recvResponseTimeMs += elapsedTimeMs(startTime);
       }
-      this.bytesReceived = 
this.connection.getHeaderFieldLong(HttpHeaderConfigurations.CONTENT_LENGTH, 0);
-    } else {
-      // consume the input stream to release resources
-      int totalBytesRead = 0;
+      this.bytesReceived = totalBytesRead;
+    }
+  }
 
+  public long parseResponse(final byte[] buffer,
+      final int offset,
+      final int length) throws IOException {
+    if (statusCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
+      processStorageErrorResponse();
+      return this.connection.getHeaderFieldLong(
+          HttpHeaderConfigurations.CONTENT_LENGTH, 0);
+    } else {
       try (InputStream stream = this.connection.getInputStream()) {
         if (isNullInputStream(stream)) {
-          return;
+          return 0;
         }
-        boolean endOfStream = false;
 
-        // this is a list operation and need to retrieve the data
-        // need a better solution
-        if (AbfsHttpConstants.HTTP_METHOD_GET.equals(this.method) && buffer == 
null) {
+        if (AbfsHttpConstants.HTTP_METHOD_GET.equals(this.method)
+            && buffer == null) {
           parseListFilesResponse(stream);
         } else {
-          if (buffer != null) {
-            while (totalBytesRead < length) {
-              int bytesRead = stream.read(buffer, offset + totalBytesRead, 
length - totalBytesRead);
-              if (bytesRead == -1) {
-                endOfStream = true;
-                break;
-              }
-              totalBytesRead += bytesRead;
-            }
-          }
-          if (!endOfStream && stream.read() != -1) {
-            // read and discard
-            int bytesRead = 0;
-            byte[] b = new byte[CLEAN_UP_BUFFER_SIZE];
-            while ((bytesRead = stream.read(b)) >= 0) {
-              totalBytesRead += bytesRead;
-            }
-          }
+          return readDataFromStream(stream, buffer, offset, length);
         }
-      } catch (IOException ex) {
-        LOG.warn("IO/Network error: {} {}: {}",
-            method, getMaskedUrl(), ex.getMessage());
-        LOG.debug("IO Error: ", ex);
-        throw ex;
-      } finally {
-        if (this.isTraceEnabled) {
-          this.recvResponseTimeMs += elapsedTimeMs(startTime);
+      }
+    }
+
+    return 0;
+  }
+
+  public long readDataFromStream(final InputStream stream,

Review comment:
       Have added the javadocs.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 650005)
    Time Spent: 40m  (was: 0.5h)

> ABFS: Refactor HTTP request handling code
> -----------------------------------------
>
>                 Key: HADOOP-17890
>                 URL: https://issues.apache.org/jira/browse/HADOOP-17890
>             Project: Hadoop Common
>          Issue Type: Sub-task
>          Components: fs/azure
>    Affects Versions: 3.4.0
>            Reporter: Sneha Vijayarajan
>            Assignee: Sneha Vijayarajan
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Aims at Http request handling code refactoring.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to