Skip to content

fix(io): treat ADLS Gen2 / OneLake directory blobs as directories in blobfs WalkDir - #2180

Merged
zeroshade merged 2 commits into
apache:mainfrom
ajiteshsingh:fix-issue-2159
Oct 13, 2026
Merged

zeroshade merged 2 commits into
apache:mainfrom
ajiteshsingh:fix-issue-2159

Conversation

@ajiteshsingh

Copy link
Copy Markdown
Contributor

Fixes #2159

Problem

On ADLS Gen2 with a hierarchical namespace (OneLake), every directory is also stored as a 0-byte blob named after it, with no trailing slash. blobfs.FileIO.WalkDir walked gocloud's fs.FS, which treats a key as a file whenever an object with that exact key exists. So:

  • the walk root opened as a file, and the walk never descended
  • subdirectories appeared twice, once as a 0-byte file and once as a directory, and listing them failed with readdir: not implemented

As a result, PlanOrphanFiles / clean-orphan-files reported the table location itself as the only orphan (0 bytes).

Fix

WalkDir now walks a small adapter over the bucket (walkFS), which implements fs.StatFS and fs.ReadDirFS:

  • Stat treats any key with objects under it as a directory, checked with a 1-key ListPage
  • ReadDir lists one level and hides a 0-byte object named after a child directory

Trailing-slash markers on flat stores (S3/GCS) walk exactly as before. The walk also makes fewer requests: one listing per directory, instead of an Exists check plus a listing.

Caveats

  • Applies on every backend. The rule infers "directory blob" from size and name, because listings don't return Azure's hdi_isfolder metadata. So on S3 or GCS, a real empty file named exactly like a sibling directory (object x next to keys under x/) is no longer reported. Iceberg doesn't write such files.
  • Empty hierarchical-namespace directories are still reported as 0-byte files. With no children, they can only be identified through hdi_isfolder, which costs an Attributes call per 0-byte object. Table locations are never empty, and deleting an empty directory's blob is harmless. This is noted in a code comment.

Testing

  • New TestBlobFileIOWalkDirHierarchicalNamespace (in-memory bucket). It fails before this change and passes after.
  • go test ./io/... ./catalog/hadoop/... ./table/maintenance/... ./cmd/iceberg/... passes.
  • Not tested against a real OneLake account.

🤖 Generated with Claude Code

ajiteshsingh and others added 2 commits October 10, 2026 19:09
On ADLS Gen2 accounts with a hierarchical namespace (such as OneLake),
every directory is also stored as a 0-byte blob named after it, with no
trailing slash. gocloud's fs.FS treats any key with an exact object as a
file, so WalkDir stopped at the walk root and reported it as the only
file. Orphan cleanup then listed the table location as its only orphan.

WalkDir now walks a small adapter over the bucket. A key with objects
under it is a directory, and a 0-byte blob named after a child directory
is hidden from listings. Trailing-slash markers on flat stores behave as
before, and the walk makes one listing per directory instead of an
existence check plus a listing.

Fixes apache#2159

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ajiteshsingh ajiteshsingh changed the title fix(io): walk hierarchical namespace directories in blobfs WalkDir fix(io): treat ADLS Gen2 / OneLake directory blobs as directories in blobfs WalkDir Oct 12, 2026
@ajiteshsingh
ajiteshsingh marked this pull request as ready for review October 12, 2026 01:24

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is sound. I compared WalkDir output against main over five layouts: flat stores with and without trailing-slash markers are unchanged; a hierarchical-namespace root and directory now walk fully (main reports the root as a single file, or fails with readdir … not implemented on a child directory); a missing root still yields fs.ErrNotExist. File entries still carry *blob.ListObject in Sys(), so isDirectoryMarker and the orphan-cleanup ModTime cutoff behave as before. Vet and -race pass on ./io/..., ./table/maintenance/... and ./catalog/hadoop/... merged with current main; CI is 15/15. I removed the 0-byte hiding, the child check in Stat, the sort, and the walkFS switch, and each fails a test.

Follow-ups (merging now; these can land separately):

Pin the obj.Size == 0 guard in walkFS.ReadDir. Replacing it with if dirs[child] (hiding any same-named object regardless of size) leaves the suite green. That guard is what keeps a real non-empty object x next to keys under x/ visible on S3/GCS, which matters beyond orphan cleanup, since WalkDir callers such as the Hadoop catalog would otherwise silently lose a file. Adding a non-empty tbl/x alongside tbl/x/y to the new test, and asserting it's still reported, covers it (it is today: D tbl/x, F tbl/x/y, F tbl/x).

Nit: slices.SortFunc isn't stable, so when a directory and a non-empty file share a name, their relative order varies between runs. slices.SortStableFunc, or breaking ties with directories first, would make the walk deterministic.

Pre-existing and out of scope: on flat stores, a subdirectory marker like tbl/data/ walks as a file tbl/data/data (identical on main). Filed as #2185.

@zeroshade
zeroshade merged commit 5ab0389 into apache:main Oct 13, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clean-orphan-files: WalkDir never descends on ADLS hierarchical namespace (OneLake); returns the table location as the only orphan

2 participants