You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by yc...@apache.org on 2020/11/04 03:50:53 UTC

[hive] branch master updated: HIVE-24342: isPathEncrypted should make sure resolved path also from HDFS (Uma Maheswara Rao Gangumalla, reviewed by Yongzhi Chen) (#1639)

This is an automated email from the ASF dual-hosted git repository.

ychena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new fdc2c5c  HIVE-24342: isPathEncrypted should make sure resolved path also from HDFS (Uma Maheswara Rao Gangumalla, reviewed by Yongzhi Chen) (#1639)
fdc2c5c is described below

commit fdc2c5c9c8e3a22f68a160144003a98ac95d76bd
Author: Uma Maheswara Rao G <um...@apache.org>
AuthorDate: Tue Nov 3 19:50:37 2020 -0800

    HIVE-24342: isPathEncrypted should make sure resolved path also from HDFS (Uma Maheswara Rao Gangumalla, reviewed by Yongzhi Chen) (#1639)
---
 .../apache/hadoop/hive/shims/Hadoop23Shims.java    | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java b/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
index 858a799..3825434 100644
--- a/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
+++ b/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
@@ -1236,13 +1236,40 @@ public class Hadoop23Shims extends HadoopShimsSecure {
       } else {
         fullPath = path.getFileSystem(conf).makeQualified(path);
       }
-      if(!"hdfs".equalsIgnoreCase(path.toUri().getScheme())) {
+      if (!isFileInHdfs(path.getFileSystem(conf), path)) {
         return false;
       }
 
       return (getEncryptionZoneForPath(fullPath) != null);
     }
 
+    /**
+     * Returns true if the given fs supports mount functionality. In general we
+     * can have child file systems only in the case of mount fs like
+     * ViewFsOverloadScheme or ViewDistributedFileSystem. Returns false if the
+     * getChildFileSystems API returns null.
+     */
+    private boolean isMountedFs(FileSystem fs) {
+      return fs.getChildFileSystems() != null;
+    }
+
+    private boolean isFileInHdfs(FileSystem fs, Path path) throws IOException {
+      String hdfsScheme = "hdfs";
+      boolean isHdfs = hdfsScheme.equalsIgnoreCase(path.toUri().getScheme());
+      // The ViewHDFS supports that, any non-hdfs paths can be mounted as hdfs
+      // paths. Here HDFSEncryptionShim actually works only for hdfs paths. But
+      // in the case of ViewHDFS, paths can be with hdfs scheme, but they might
+      // actually resolve to other fs.
+      // ex: hdfs://ns1/test ---> o3fs://b.v.ozone1/test
+      // So, we need to lookup where the actual file is to know the filesystem
+      // in use. The resolvePath is a sure shot way of knowing which file system
+      // the file is.
+      if (isHdfs && isMountedFs(fs)) {
+        isHdfs = hdfsScheme.equals(fs.resolvePath(path).toUri().getScheme());
+      }
+      return isHdfs;
+    }
+
     public EncryptionZone getEncryptionZoneForPath(Path path) throws IOException {
       if (path.getFileSystem(conf).exists(path)) {
         return hdfsAdmin.getEncryptionZoneForPath(path);