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

ASF GitHub Bot commented on TWILL-223:
--------------------------------------

Github user albertshau commented on a diff in the pull request:

    https://github.com/apache/twill/pull/47#discussion_r108811273
  
    --- Diff: 
twill-yarn/src/main/java/org/apache/twill/filesystem/FileContextLocationFactory.java
 ---
    @@ -103,16 +138,32 @@ public Location create(URI uri) {
     
       @Override
       public Location getHomeLocation() {
    +    FileContext fc = getFileContext();
         // Fix for TWILL-163. FileContext.getHomeDirectory() uses 
System.getProperty("user.name") instead of UGI
         return new FileContextLocation(this, fc,
                                        new 
Path(fc.getHomeDirectory().getParent(), fc.getUgi().getShortUserName()));
       }
     
       /**
    -   * Returns the {@link FileContext} used by this {@link LocationFactory}.
    +   * Returns the {@link FileContext} for the current user based on {@link 
UserGroupInformation#getCurrentUser()}.
    +   *
    +   * @throws IllegalStateException if failed to determine the current user 
or fail to create the FileContext.
    +   * @throws RuntimeException if failed to get the {@link FileContext} 
object for the current user due to exception
        */
       public FileContext getFileContext() {
    -    return fc;
    +    try {
    +      return 
fileContextCache.getUnchecked(UserGroupInformation.getCurrentUser());
    +    } catch (IOException e) {
    +      throw new IllegalStateException("Failed to get current user 
information", e);
    +    } catch (UncheckedExecutionException e) {
    +      Throwable cause = e.getCause();
    +      if (cause instanceof UnsupportedFileSystemException) {
    +        String defaultURI = 
configuration.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
    +                                              
CommonConfigurationKeysPublic.FS_DEFAULT_NAME_DEFAULT);
    +        throw new IllegalStateException("File system with URI '" + 
defaultURI + "' is not supported", cause);
    +      }
    +      throw new RuntimeException(cause);
    --- End diff --
    
    at this point the cause should be a RuntimeException right? in which case 
we should just propagate it directly rather than wrapping it.


> FileContextLocationFactory should use FileContext instance based on the 
> caller UGI
> ----------------------------------------------------------------------------------
>
>                 Key: TWILL-223
>                 URL: https://issues.apache.org/jira/browse/TWILL-223
>             Project: Apache Twill
>          Issue Type: Bug
>            Reporter: Terence Yim
>            Assignee: Terence Yim
>             Fix For: 0.11.0
>
>
> The {{FileContextLocationFactory}} internally has a cached {{FileContext}} 
> object that was created when the factory was created. However, when the 
> {{getFileContext}} is called (directly or via one of those {{create}} 
> methods), the UGI might be different then the cached one. If the cached one 
> is returning, FS operations will be performed with the user who creates the 
> factory, not the one who calls the {{create}} method.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to