【问题标题】:mount error when trying to access the Azure DBFS file system in Azure Databricks尝试访问 Azure Databricks 中的 Azure DBFS 文件系统时出现挂载错误
【发布时间】:2020-03-18 16:27:53
【问题描述】:

我能够与我的 Databricks FileStore DBFS 建立连接并访问文件存储。

可以使用 Pyspark 读取、写入和转换数据,但是当我尝试使用本地 Python API(例如 pathlib 或 OS 模块)时,我无法通过第一级 DBFS 文件系统

我可以使用魔法命令:

%fs ls dbfs:\mnt\my_fs\... 完美运行并列出所有子目录?

但如果我这样做 os.listdir('\dbfs\mnt\my_fs\') 它会返回 ['mount.err'] 作为返回值

我在新集群上测试过,结果是一样的

我在 Databricks Runtine 6.1 版和 Apache Spark 2.4.4 上使用 Python

有没有人可以提供建议。

编辑:

连接脚本:

我使用 Databricks CLI 库来存储我的凭据,这些凭据根据 databricks 文档进行格式化:

 def initialise_connection(secrets_func):
  configs = secrets_func()
  # Check if the mount exists
  bMountExists = False
  for item in dbutils.fs.ls("/mnt/"):
      if str(item.name) == r"WFM/":
          bMountExists = True
      # drop if exists to refresh credentials
      if bMountExists:
        dbutils.fs.unmount("/mnt/WFM")
        bMountExists = False

      # Mount a drive
      if not (bMountExists):
          dbutils.fs.mount(
              source="adl://test.azuredatalakestore.net/WFM",
              mount_point="/mnt/WFM",
              extra_configs=configs
          )
          print("Drive mounted")
      else:
          print("Drive already mounted")

【问题讨论】:

    标签: python azure databricks azure-databricks


    【解决方案1】:

    当同一个容器安装到工作区中的两个不同路径时,我们遇到了这个问题。卸载所有并重新安装解决了我们的问题。我们使用的是 Databricks 6.2 版(Spark 2.4.4、Scala 2.11)。我们的 blob 存储容器配置:

    • 性能/访问层:标准/热
    • 复制:读取访问异地冗余存储 (RA-GRS)
    • 帐户类型:StorageV2(通用 v2)

    运行笔记本脚本以卸载 /mnt 中的所有挂载:

    # Iterate through all mounts and unmount 
    print('Unmounting all mounts beginning with /mnt/')
    dbutils.fs.mounts()
    for mount in dbutils.fs.mounts():
      if mount.mountPoint.startswith('/mnt/'):
        dbutils.fs.unmount(mount.mountPoint)
    
    # Re-list all mount points
    print('Re-listing all mounts')
    dbutils.fs.mounts()
    

    在自动化作业集群上测试的最小作业

    假设您有一个单独的过程来创建挂载。创建作业定义 (job.json) 以在自动化集群上运行 Python 脚本:

    {
      "name": "Minimal Job",
      "new_cluster": {
        "spark_version": "6.2.x-scala2.11",
        "spark_conf": {},
        "node_type_id": "Standard_F8s",
        "driver_node_type_id": "Standard_F8s",
        "num_workers": 2,
        "enable_elastic_disk": true,
        "spark_env_vars": {
          "PYSPARK_PYTHON": "/databricks/python3/bin/python3"
        }
      },
      "timeout_seconds": 14400,
      "max_retries": 0,
      "spark_python_task": {
        "python_file": "dbfs:/minimal/job.py"
      }
    }
    

    Python 文件 (job.py) 打印出挂载:

    import os
    
    path_mounts = '/dbfs/mnt/'
    print(f"Listing contents of {path_mounts}:")
    print(os.listdir(path_mounts))
    
    path_mount = path_mounts + 'YOURCONTAINERNAME'
    print(f"Listing contents of {path_mount }:")
    print(os.listdir(path_mount))
    

    运行 databricks CLI 命令来运行作业。查看 Spark 驱动程序日志的输出,确认 mount.err 不存在。

    databricks fs mkdirs dbfs:/minimal
    databricks fs cp job.py dbfs:/minimal/job.py --overwrite
    databricks jobs create --json-file job.json
    databricks jobs run-now --job-id <JOBID FROM LAST COMMAND>
    

    【讨论】:

    • 谢谢,对我们来说,这是由于 Databricks API 从 5.5 更改为 6.0 造成的——也就是说我使用 dbutils 解决了这个问题,但并不好玩。我在第 2 代没有这个问题。
    【解决方案2】:

    在连接到 Azure Generation2 存储帐户(没有分层名称空间)时,我们遇到了同样的问题。

    将 Databricks 运行时环境从 5.5 切换到 6.x 时,似乎会发生该错误。但是,我们无法查明造成这种情况的确切原因。我们假设某些功能可能已被弃用。

    【讨论】:

      【解决方案3】:

      更新答案:使用 Azure Data Lake Gen1 存储帐户:dbutils 可以访问 adls gen1 令牌/访问凭据,因此 mnt 点中的文件列表在 std py api 调用无法访问的情况下工作creds/spark conf,您看到的第一个调用是列出文件夹,它没有对 adls api 进行任何调用。

      我已经在 Databricks Runtime 6.1 版中进行了测试(包括 Apache Spark 2.4.4、Scala 2.11)

      命令正常工作,没有任何错误消息。

      更新:内部文件夹的输出。

      希望这会有所帮助。请您尝试并告诉我们。

      【讨论】:

      • 能否请您在问题中添加带有完整错误消息的屏幕截图?还请分享安装点源位置吗?和 DBFS API 命令哪个有效?
      • 感谢您的更新,我会尽快调查。
      • 我能够检索文件夹内的文件。这个问题看起来很奇怪。
      • 此外,对于我们没有 rootdir rwx 的湖,在 5.5 上列出失败,而这在 >5.5 上有效 - 真是一场 Databricks 灾难......
      • 在 gen1 上的 6.4 python 列表似乎正在工作;交易,
      猜你喜欢
      • 2021-04-02
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 2022-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多