Repository: mlflow/mlflow

Issue:
[BUG] MLFlow UI fails to load experiment artifacts stored in remote HDFS
### Issues Policy acknowledgement

- [X] I have read and agree to submit bug reports in accordance with the [issues policy](https://www.github.com/mlflow/mlflow/blob/master/ISSUE_POLICY.md)

### Willingness to contribute

Yes. I can contribute a fix for this bug independently.

### MLflow version

- Client: 2.0.1
- Tracking server: 2.0.1

### System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Linux Ubuntu 20.04
- **Python version**: 3.8
- **yarn version, if running the dev UI**: -


### Describe the problem

After successfully logging artifacts to a remote HDFS server, when trying to inspect them through the MLFlow UI, it is not possible to load their contents.
As seen in the image below, the contents are located successfully, but cant be loaded properly.
![Screenshot](https://user-images.githubusercontent.com/11291967/208936910-be513169-a749-4ac1-a6ee-04a1b44f5cec.png)

These are the server logs:
`mlflow_tracking_server-artifacts-server-1  | PermissionError: [Errno 13] Opening HDFS file '/user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt' failed. Detail: [errno 13] Permission denied`

It seems that when `hdfs_artifact_repo.py` lists the hdfs contents, is not properly recognizing that the certain path is actually a file and tries to append the file name on top of the full path - hence the double requirements.txt in the error line.

### Tracking information

_No response_

### Code to reproduce issue

It is a UI issue but here is a minimal configuration of the `docker compose` services

```
artifacts-server:
  build:
    context: .
    dockerfile: "${DOCKERFILE:-Dockerfile}"
  expose:
    - "5500"
  command: >
    mlflow server --host 0.0.0.0 --port 5500 --artifacts-destination hdfs://XX:9000/path/to/mlflow --gunicorn-opts "--log-level debug" --serve-artifacts --artifacts-only

tracking-server:
    build:
      context: .
      dockerfile: "${DOCKERFILE:-Dockerfile}"
    restart: always
    depends_on:
      - postgres
      - artifacts-server
    expose:
      - "5000"
    ports:
      - "5000:5000"
    command: >
      mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri postgresql://user:password@postgres:5432/db --default-artifact-root http://artifacts-server:5500/api/2.0/mlflow-artifacts/artifacts/experiments --gunicorn-opts "--log-level debug"
```

### Stack trace

```
mlflow_tracking_server-artifacts-server-1  | [2022-12-21 14:45:39 +0000] [27] [DEBUG] GET /api/2.0/mlflow-
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
mlflow_tracking_server-artifacts-server-1  |    at java.security.AccessController.doPrivileged(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at javax.security.auth.Subject.doAs(Subject.java:422)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
mlflow_tracking_server-artifacts-server-1  | org.apache.hadoop.security.AccessControlException: /user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt (is not a directory)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirectory.resolvePath(FSDirectory.java:679)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getBlockLocations(FSDirStatAndListingOp.java:151)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getBlockLocations(FSNamesystem.java:1946)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getBlockLocations(NameNodeRpcServer.java:739)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getBlockLocations(ClientNamenodeProtocolServerSideTranslatorPB.java:432)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
mlflow_tracking_server-artifacts-server-1  |    at java.security.AccessController.doPrivileged(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at javax.security.auth.Subject.doAs(Subject.java:422)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
mlflow_tracking_server-artifacts-server-1  | 
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
mlflow_tracking_server-artifacts-server-1  |    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:121)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:88)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.callGetBlockLocations(DFSClient.java:879)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.getLocatedBlocks(DFSClient.java:866)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.getLocatedBlocks(DFSClient.java:855)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.open(DFSClient.java:1023)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DistributedFileSystem$4.doCall(DistributedFileSystem.java:322)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DistributedFileSystem$4.doCall(DistributedFileSystem.java:318)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DistributedFileSystem.open(DistributedFileSystem.java:330)
mlflow_tracking_server-artifacts-server-1  | Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): /user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt (is not a directory)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirectory.resolvePath(FSDirectory.java:679)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getBlockLocations(FSDirStatAndListingOp.java:151)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getBlockLocations(FSNamesystem.java:1946)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getBlockLocations(NameNodeRpcServer.java:739)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getBlockLocations(ClientNamenodeProtocolServerSideTranslatorPB.java:432)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
mlflow_tracking_server-artifacts-server-1  |    at java.security.AccessController.doPrivileged(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at javax.security.auth.Subject.doAs(Subject.java:422)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
mlflow_tracking_server-artifacts-server-1  | 
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Client.getRpcResponse(Client.java:1612)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Client.call(Client.java:1558)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Client.call(Client.java:1455)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:231)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:118)
mlflow_tracking_server-artifacts-server-1  |    at com.sun.proxy.$Proxy9.getBlockLocations(Unknown Source)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getBlockLocations(ClientNamenodeProtocolTranslatorPB.java:327)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
mlflow_tracking_server-artifacts-server-1  |    at java.lang.reflect.Method.invoke(Method.java:498)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:433)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:166)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:158)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:96)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:362)
mlflow_tracking_server-artifacts-server-1  |    at com.sun.proxy.$Proxy10.getBlockLocations(Unknown Source)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.callGetBlockLocations(DFSClient.java:877)
mlflow_tracking_server-artifacts-server-1  |    ... 7 more
mlflow_tracking_server-artifacts-server-1  | /usr/local/lib/python3.8/site-packages/mlflow/store/artifact/hdfs_artifact_repo.py:199: FutureWarning: pyarrow.hdfs.connect is deprecated as of 2.0.0, please use pyarrow.fs.HadoopFileSystem instead.
mlflow_tracking_server-artifacts-server-1  |   connected = pa.hdfs.connect(
mlflow_tracking_server-artifacts-server-1  | 2022/12/21 14:45:39 ERROR mlflow.server: Exception on /api/2.0/mlflow-artifacts/artifacts/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt [GET]
mlflow_tracking_server-artifacts-server-1  | Traceback (most recent call last):
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
mlflow_tracking_server-artifacts-server-1  |     response = self.full_dispatch_request()
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1822, in full_dispatch_request
mlflow_tracking_server-artifacts-server-1  |     rv = self.handle_user_exception(e)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1820, in full_dispatch_request
mlflow_tracking_server-artifacts-server-1  |     rv = self.dispatch_request()
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1796, in dispatch_request
mlflow_tracking_server-artifacts-server-1  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/server/handlers.py", line 456, in wrapper
mlflow_tracking_server-artifacts-server-1  |     return func(*args, **kwargs)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/server/handlers.py", line 507, in wrapper
mlflow_tracking_server-artifacts-server-1  |     return func(*args, **kwargs)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/server/handlers.py", line 1478, in _download_artifact
mlflow_tracking_server-artifacts-server-1  |     dst = artifact_repo.download_artifacts(artifact_path, tmp_dir.name)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/store/artifact/hdfs_artifact_repo.py", line 151, in download_artifacts
mlflow_tracking_server-artifacts-server-1  |     _download_hdfs_file(hdfs, hdfs_base_path, local_path)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/store/artifact/hdfs_artifact_repo.py", line 248, in _download_hdfs_file
mlflow_tracking_server-artifacts-server-1  |     f.write(hdfs.open(remote_file_path, "rb").read())
mlflow_tracking_server-artifacts-server-1  |   File "pyarrow/_hdfsio.pyx", line 419, in pyarrow._hdfsio.HadoopFileSystem.open
mlflow_tracking_server-artifacts-server-1  |   File "pyarrow/error.pxi", line 113, in pyarrow.lib.check_status
mlflow_tracking_server-artifacts-server-1  | PermissionError: [Errno 13] Opening HDFS file '/user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt' failed. Detail: [errno 13] Permission denied
mlflow_tracking_server-artifacts-server-1  | [2022-12-21 14:45:55 +0000] [27] [DEBUG] GET /api/2.0/mlflow-artifacts/artifacts/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt
mlflow_tracking_server-artifacts-server-1  | hdfsOpenFile(/user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt): FileSystem#open((Lorg/apache/hadoop/fs/Path;I)Lorg/apache/hadoop/fs/FSDataInputStream;) error:
mlflow_tracking_server-artifacts-server-1  | RemoteException: /user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt (is not a directory)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirectory.resolvePath(FSDirectory.java:679)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getBlockLocations(FSDirStatAndListingOp.java:151)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getBlockLocations(FSNamesystem.java:1946)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getBlockLocations(NameNodeRpcServer.java:739)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getBlockLocations(ClientNamenodeProtocolServerSideTranslatorPB.java:432)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
mlflow_tracking_server-artifacts-server-1  |    at java.security.AccessController.doPrivileged(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at javax.security.auth.Subject.doAs(Subject.java:422)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
mlflow_tracking_server-artifacts-server-1  | org.apache.hadoop.security.AccessControlException: /user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt (is not a directory)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirectory.resolvePath(FSDirectory.java:679)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getBlockLocations(FSDirStatAndListingOp.java:151)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getBlockLocations(FSNamesystem.java:1946)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getBlockLocations(NameNodeRpcServer.java:739)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getBlockLocations(ClientNamenodeProtocolServerSideTranslatorPB.java:432)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
mlflow_tracking_server-artifacts-server-1  |    at java.security.AccessController.doPrivileged(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at javax.security.auth.Subject.doAs(Subject.java:422)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
mlflow_tracking_server-artifacts-server-1  | 
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
mlflow_tracking_server-artifacts-server-1  |    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:121)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:88)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.callGetBlockLocations(DFSClient.java:879)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.getLocatedBlocks(DFSClient.java:866)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.getLocatedBlocks(DFSClient.java:855)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.open(DFSClient.java:1023)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DistributedFileSystem$4.doCall(DistributedFileSystem.java:322)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DistributedFileSystem$4.doCall(DistributedFileSystem.java:318)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DistributedFileSystem.open(DistributedFileSystem.java:330)
mlflow_tracking_server-artifacts-server-1  | Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): /user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt (is not a directory)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirectory.resolvePath(FSDirectory.java:679)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getBlockLocations(FSDirStatAndListingOp.java:151)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getBlockLocations(FSNamesystem.java:1946)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getBlockLocations(NameNodeRpcServer.java:739)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getBlockLocations(ClientNamenodeProtocolServerSideTranslatorPB.java:432)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
mlflow_tracking_server-artifacts-server-1  |    at java.security.AccessController.doPrivileged(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at javax.security.auth.Subject.doAs(Subject.java:422)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
mlflow_tracking_server-artifacts-server-1  | 
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Client.getRpcResponse(Client.java:1612)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Client.call(Client.java:1558)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.Client.call(Client.java:1455)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:231)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:118)
mlflow_tracking_server-artifacts-server-1  |    at com.sun.proxy.$Proxy9.getBlockLocations(Unknown Source)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getBlockLocations(ClientNamenodeProtocolTranslatorPB.java:327)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
mlflow_tracking_server-artifacts-server-1  |    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
mlflow_tracking_server-artifacts-server-1  |    at java.lang.reflect.Method.invoke(Method.java:498)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:433)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:166)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:158)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:96)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:362)
mlflow_tracking_server-artifacts-server-1  |    at com.sun.proxy.$Proxy10.getBlockLocations(Unknown Source)
mlflow_tracking_server-artifacts-server-1  |    at org.apache.hadoop.hdfs.DFSClient.callGetBlockLocations(DFSClient.java:877)
mlflow_tracking_server-artifacts-server-1  |    ... 7 more
mlflow_tracking_server-artifacts-server-1  | /usr/local/lib/python3.8/site-packages/mlflow/store/artifact/hdfs_artifact_repo.py:199: FutureWarning: pyarrow.hdfs.connect is deprecated as of 2.0.0, please use pyarrow.fs.HadoopFileSystem instead.
mlflow_tracking_server-artifacts-server-1  |   connected = pa.hdfs.connect(
mlflow_tracking_server-artifacts-server-1  | 2022/12/21 14:45:56 ERROR mlflow.server: Exception on /api/2.0/mlflow-artifacts/artifacts/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt [GET]
mlflow_tracking_server-artifacts-server-1  | Traceback (most recent call last):
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
mlflow_tracking_server-artifacts-server-1  |     response = self.full_dispatch_request()
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1822, in full_dispatch_request
mlflow_tracking_server-artifacts-server-1  |     rv = self.handle_user_exception(e)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1820, in full_dispatch_request
mlflow_tracking_server-artifacts-server-1  |     rv = self.dispatch_request()
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1796, in dispatch_request
mlflow_tracking_server-artifacts-server-1  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/server/handlers.py", line 456, in wrapper
mlflow_tracking_server-artifacts-server-1  |     return func(*args, **kwargs)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/server/handlers.py", line 507, in wrapper
mlflow_tracking_server-artifacts-server-1  |     return func(*args, **kwargs)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/server/handlers.py", line 1478, in _download_artifact
mlflow_tracking_server-artifacts-server-1  |     dst = artifact_repo.download_artifacts(artifact_path, tmp_dir.name)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/store/artifact/hdfs_artifact_repo.py", line 151, in download_artifacts
mlflow_tracking_server-artifacts-server-1  |     _download_hdfs_file(hdfs, hdfs_base_path, local_path)
mlflow_tracking_server-artifacts-server-1  |   File "/usr/local/lib/python3.8/site-packages/mlflow/store/artifact/hdfs_artifact_repo.py", line 248, in _download_hdfs_file
mlflow_tracking_server-artifacts-server-1  |     f.write(hdfs.open(remote_file_path, "rb").read())
mlflow_tracking_server-artifacts-server-1  |   File "pyarrow/_hdfsio.pyx", line 419, in pyarrow._hdfsio.HadoopFileSystem.open
mlflow_tracking_server-artifacts-server-1  |   File "pyarrow/error.pxi", line 113, in pyarrow.lib.check_status
mlflow_tracking_server-artifacts-server-1  | PermissionError: [Errno 13] Opening HDFS file '/user/ichatzigianellis/mlflow/experiments/6/23788831488c4091b9008435390b8df9/artifacts/model/requirements.txt/requirements.txt' failed. Detail: [errno 13] Permission denied
```

### Other info / logs

_No response_

### What component(s) does this bug affect?

- [x] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [ ] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [ ] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/recipes`: Recipes, Recipe APIs, Recipe configs, Recipe Templates
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [x] `area/server-infra`: MLflow Tracking server backend
- [ ] `area/tracking`: Tracking Service, tracking client APIs, autologging

### What interface(s) does this bug affect?

- [ ] `area/uiux`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [ ] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [ ] `area/windows`: Windows support

### What language(s) does this bug affect?

- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

### What integration(s) does this bug affect?

- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations


Discussion:

Resolving patch:
diff --git a/mlflow/store/artifact/hdfs_artifact_repo.py b/mlflow/store/artifact/hdfs_artifact_repo.py
--- a/mlflow/store/artifact/hdfs_artifact_repo.py
+++ b/mlflow/store/artifact/hdfs_artifact_repo.py
@@ -91,12 +91,17 @@ def list_artifacts(self, path=None):
             if hdfs.exists(hdfs_base_path):
                 for file_detail in hdfs.ls(hdfs_base_path, detail=True):
                     file_name = file_detail.get("name")
+
+                    # file_name is hdfs_base_path and not a child of that path
+                    if file_name == hdfs_base_path:
+                        continue
+
                     # Strip off anything that comes before the artifact root e.g. hdfs://name
                     offset = file_name.index(self.path)
                     rel_path = _relative_path_remote(self.path, file_name[offset:])
                     is_dir = file_detail.get("kind") == "directory"
                     size = file_detail.get("size")
-                    paths.append(FileInfo(rel_path, is_dir, size))
+                    paths.append(FileInfo(rel_path, is_dir=is_dir, file_size=size))
             return sorted(paths, key=lambda f: paths)
 
     def _walk_path(self, hdfs, hdfs_path):


Test patch: