Forum Discussion

dbeavon3's avatar
dbeavon3
Memorable Member
10 months ago
Solved

File directory not synchronized - synfs after mssparkutils.fs.mount

I had been struggling for about 10 minutes to read a file from the lakehouse. I mounted like so:   fspath = mssparkutils.fs.mount(my_files_path, "/LakehouseFiles")         ... then ...
  • tayloramy's avatar
    10 months ago

    Hi dbeavon3,

     

    You’re not imagining it - the /synfs path you get back from mssparkutils.fs.getMountPath(...) is an eventually-consistent projection of OneLake into the notebook’s file system. When you add or rename files outside the running Spark session (e.g., via the Lakehouse UI, another job, or upload), it can take a while before the mount’s directory listing catches up. That’s why your open("/synfs/notebook/.../Partition.xml") failed for several minutes and then “magically” started working.

     

    Two workarounds:

    1. Refresh the mounts before you read
      import mssparkutils
      mssparkutils.fs.refreshMounts()
      This forces the workspace/job mount metadata to resync so new files show up faster. See: Microsoft Spark Utilities docs and the refreshMounts reference notes here: Synapse mount API (same APIs).
    2. (Better) Skip /synfs for reads and use an ABFSS path
      Read the file directly from OneLake instead of the mounted filesystem. With Python, use fsspec so you can call open() on ABFSS:
      import fsspec
      
      abfss_path = "abfss://<workspaceId>@onelake.dfs.fabric.microsoft.com/<LakehouseName>/Files/InventoryManagement/InventoryAgings/Partition.xml"
      with fsspec.open(abfss_path, "rb") as f:
          full_doc = f.read()
      This avoids the /synfs cache entirely. Nice walkthrough: Using fsspec with OneLake.

    If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.