簡體   English   中英

嘗試訪問 Azure Databricks 中的 Azure DBFS 文件系統時出現掛載錯誤

[英]mount error when trying to access the Azure DBFS file system in Azure Databricks

我能夠建立與我的 Databricks FileStore DBFS的連接並訪問文件存儲。

可以使用 Pyspark 讀取、寫入和轉換數據,但是當我嘗試使用本地 Python API(例如pathlibOS模塊文件系統)時,我無法通過第一級 DBFS 文件系統

我可以使用一個魔術命令:

%fs ls dbfs:\mnt\my_fs\...完美運行並列出所有子目錄?

但是如果我執行os.listdir('\dbfs\mnt\my_fs\')它會返回['mount.err']作為返回值

我已經在一個新集群上測試過了,結果是一樣的

我在帶有 Apache Spark 2.4.4 的 Databricks Runtine 版本 6.1 上使用 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")

當同一個容器安裝到工作區中的兩個不同路徑時,我們遇到了這個問題。 卸載所有並重新安裝解決了我們的問題。 我們使用的是 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 命令來運行作業。 查看 output 的 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>

在連接到 Azure Generation2 存儲帳戶(沒有分層名稱空間)時,我們遇到了同樣的問題。

將 Databricks 運行時環境從 5.5 切換到 6.x 時似乎會發生該錯誤。 但是,我們無法查明造成這種情況的確切原因。 我們假設某些功能可能已被棄用。

更新答案:使用 Azure Data Lake Gen1 存儲帳戶:dbutils 可以訪問 adls gen1 令牌/訪問憑據,因此 mnt 點中的文件列表在 std py api 調用無權訪問 creds/spark conf 的情況下工作,首先調用正在列出文件夾並且它沒有對 adls api 進行任何調用。

我已經在 Databricks 運行時版本 6.1 中進行了測試(包括 Apache Spark 2.4.4、Scala 2.11)

命令按例外情況工作,沒有任何錯誤消息。

在此處輸入圖像描述

更新: Output 用於內部文件夾。

在此處輸入圖像描述

希望這可以幫助。 你能不能試着讓我們知道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM