You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/05/09 18:24:02 UTC

[GitHub] [hive] ayushtkn commented on a diff in pull request #3264: HVIE-26199 Reduce FileSystem init during user impersonation

ayushtkn commented on code in PR #3264:
URL: https://github.com/apache/hive/pull/3264#discussion_r868298191


##########
common/src/java/org/apache/hadoop/hive/common/FileUtils.java:
##########
@@ -408,10 +408,23 @@ public static FileStatus getPathOrParentThatExists(FileSystem fs, Path path) thr
     return getPathOrParentThatExists(fs, parentPath);
   }
 
-  public static void checkFileAccessWithImpersonation(final FileSystem fs, final FileStatus stat,
-      final FsAction action, final String user)
-      throws IOException, AccessControlException, InterruptedException, Exception {
-    checkFileAccessWithImpersonation(fs, stat, action, user, null);
+  public static void checkFileAccessWithImpersonation(final FileSystem fs, final FileStatus stat, final FsAction action,
+      final String user) throws IOException, AccessControlException, InterruptedException, Exception {
+    UserGroupInformation ugi = Utils.getUGI();
+    String currentUser = ugi.getShortUserName();
+    UserGroupInformation proxyUser = null;
+    FileSystem fsAsUser = null;
+    try {
+      if (user != null && !user.equals(currentUser)) {
+        proxyUser = UserGroupInformation.createProxyUser(user, UserGroupInformation.getLoginUser());
+        fsAsUser = FileUtils.getFsAsUser(fs, proxyUser);
+      }
+      checkFileAccessWithImpersonation(fs, stat, action, user, null, fsAsUser);

Review Comment:
   Is the optimisation preventing doing multiple times FileSystem.get() for same user and FileSystem to prevent multiple `` fs.initialize(uri, conf);`` calls?
   In that case even if we call FileSystem.get() multiple times it would do init only once, from the next time it will return the same FileSystem instance from the cache.
   
   It is there in the Javadoc as well
   ```
      *   If the there is a cached FS instance matching the same URI, it will
      *   be returned.
   ```



-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org