[ 
https://issues.apache.org/jira/browse/HADOOP-19795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18070216#comment-18070216
 ] 

ASF GitHub Bot commented on HADOOP-19795:
-----------------------------------------

manika137 commented on code in PR #8212:
URL: https://github.com/apache/hadoop/pull/8212#discussion_r3019747576


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -561,11 +579,73 @@ protected int readInternal(final long position, final 
byte[] b, final int offset
     }
   }
 
+  /**
+   * Convert a {@link Path} to the relative path string used by ABFS.
+   *
+   * <p>This returns the URI path component of the supplied {@code path}. If 
the
+   * resulting path is empty, this method returns {@code ROOT_PATH}.
+   *
+   * @param path the {@link Path} to convert; must not be null
+   * @return the relative path as a {@link String}; never null
+   */
+  String getRelativePath(final Path path) {
+    Preconditions.checkNotNull(path, "path");
+    String relPath = path.toUri().getPath();
+    if (relPath.isEmpty()) {
+      // This means that path passed by user is absolute path of root without 
"/" at end.
+      relPath = ROOT_PATH;
+    }
+    return relPath;
+  }
+
+  /**
+   * Creates an exception indicating that a read operation was attempted on a 
directory.
+   *
+   * @return an {@link AbfsRestOperationException} indicating the operation is 
not permitted on a directory
+   */
+  private IOException directoryReadException() {
+    return new AbfsRestOperationException(
+            AzureServiceErrorCode.PATH_NOT_FOUND.getStatusCode(),
+            AzureServiceErrorCode.PATH_NOT_FOUND.getErrorCode(),
+            readOnDirectoryErrorMsg,
+            null);
+  }
+
+  /**
+   * Checks if the current path is a directory (for both implicit and 
explicit) in FNS account.
+   * If the path is a directory, throws an exception indicating that read 
operations are not permitted.
+   *
+   * @throws IOException if the path is a directory or if there is an error 
accessing the path status
+   */
+  private void checkIfDirPathInFNS() throws IOException {
+    AbfsHttpOperation gpsOp = client.getPathStatus(
+            getRelativePath(new Path(path)),
+            false,
+            tracingContext,
+            contextEncryptionAdapter).getResult();
+
+    if (client.checkIsDir(gpsOp)) {
+      throw directoryReadException();
+    }
+  }
+
+  private long extractContentLength(AbfsHttpOperation op) {
+    // We need to use content range header instead of content length to take 
care of partial reads
+    String contentRange = 
op.getResponseHeader(HttpHeaderConfigurations.CONTENT_RANGE);
+    if (!StringUtils.isEmpty(contentRange)) {

Review Comment:
   if null, isEmpty method takes care of it and returns true





> ABFS: GetPathStatus Optimization on OpenFileForRead
> ---------------------------------------------------
>
>                 Key: HADOOP-19795
>                 URL: https://issues.apache.org/jira/browse/HADOOP-19795
>             Project: Hadoop Common
>          Issue Type: Task
>          Components: fs/azure
>    Affects Versions: 3.4.1, 3.4.2
>            Reporter: Manika Joshi
>            Assignee: Manika Joshi
>            Priority: Major
>              Labels: pull-request-available
>
> We do a getPathStatus call during file open for read. This call is primarily 
> used to fetch the file’s metadata properties before the actual read begins. 
> We are now introducing an optional, config-driven read flow that avoids the 
> getPathStatus call during open and instead derives required metadata from the 
> read response itself. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to