Repository navigation
fix(io): treat ADLS Gen2 / OneLake directory blobs as directories in blobfs WalkDir - #2180
Conversation
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zeroshade
left a comment
There was a problem hiding this comment.
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.
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.WalkDirwalked gocloud'sfs.FS, which treats a key as a file whenever an object with that exact key exists. So:readdir: not implementedAs a result,
PlanOrphanFiles/clean-orphan-filesreported the table location itself as the only orphan (0 bytes).Fix
WalkDirnow walks a small adapter over the bucket (walkFS), which implementsfs.StatFSandfs.ReadDirFS:Stattreats any key with objects under it as a directory, checked with a 1-keyListPageReadDirlists one level and hides a 0-byte object named after a child directoryTrailing-slash markers on flat stores (S3/GCS) walk exactly as before. The walk also makes fewer requests: one listing per directory, instead of an
Existscheck plus a listing.Caveats
hdi_isfoldermetadata. So on S3 or GCS, a real empty file named exactly like a sibling directory (objectxnext to keys underx/) is no longer reported. Iceberg doesn't write such files.hdi_isfolder, which costs anAttributescall 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
TestBlobFileIOWalkDirHierarchicalNamespace(in-memory bucket). It fails before this change and passes after.go test ./io/... ./catalog/hadoop/... ./table/maintenance/... ./cmd/iceberg/...passes.🤖 Generated with Claude Code