Skip to content

Do not list the directories of an Azure account with a hierarchical namespace as files - #125500

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/azure-list-skip-hns-directory-entries
Nov 13, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/azure-list-skip-hns-directory-entries

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #125462
Related: #125329

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Azure Blob Storage listings now skip the directory entries of an account with a hierarchical namespace (ADLS Gen2), so ALTER TABLE ... EXECUTE remove_orphan_files on Iceberg tables there only deletes files and no longer reports a failed deletion for every directory. Closes #125462.

Description

On an account with a hierarchical namespace, List Blobs returns each directory under the prefix as an empty blob with hdi_isfolder=true metadata. AzureObjectStorage::listObjects and iterate passed those entries through as objects, so remove_orphan_files took <table>/data, <table>/metadata and partition directories for orphan files, tried to delete them, and reported a 409 failure for each non-empty one on every run. Globs listed them too.

Both listings now request blob metadata and skip entries that are empty and carry hdi_isfolder=true, the marker the Azure SDK's DataLakePathClient::GetProperties uses to set IsDirectory. A blob with content is never skipped, and a real empty file has no such metadata, so it is still listed and still deleted as an orphan. Iceberg code is unchanged.

Improvement, not Bug Fix: the reported misbehavior is in the experimental remove_orphan_files, and I could not observe one through a documented surface on a real account with a hierarchical namespace.

Validation: Azurite has no hierarchical namespace, so the two new tests create the directory entries by hand with the same marker. Both fail on master (the dry run counts 4 data files instead of 2, and the server log lists <table>/data and <table>/metadata as orphans; the glob returns cont/<prefix>/sub) and pass with the fix. test_remove_orphan_files.py, test_storage_azure_blob_storage/test.py and test_azure_blob_storage_listobjects_prefix pass. A full listing makes the same List Blobs requests, and on Azurite a 1000-blob page is byte-identical with and without metadata, since ClickHouse writes none. With a hierarchical namespace, an existence check (max_keys = 1) now pages past the directory entries that sort before the first file.

@zlareb1, I had no real account with a hierarchical namespace; could you confirm it on yours?

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125500]

Version info

  • Merged into: 26.11.1.2169-master (included in 26.11 and later)

groeneai and others added 2 commits October 12, 2026 19:58
…amespace as files

On an account with a hierarchical namespace (ADLS Gen2), List Blobs returns
each directory under the prefix as a zero-length blob with metadata
hdi_isfolder=true. AzureObjectStorage::listObjects and AzureIteratorAsync
never requested metadata and emitted every item, so every caller saw
directories as objects. ALTER TABLE ... EXECUTE remove_orphan_files then took
<table>/data, <table>/metadata and partition directories for orphan files,
called Delete on them and counted a 409 failure for every non-empty one on
every run (ClickHouse#125462).

Both listings now request blob metadata and skip empty blobs that carry
hdi_isfolder=true, the marker DataLakePathClient::GetProperties uses to set
IsDirectory (key matched case-insensitively, value compared exactly, as the
SDK does). A blob with content is never skipped, and a real empty file has no
such metadata, so it is still listed. This makes an HNS listing look like the
flat listing every caller is built for, as the Local and HDFS listings already
do; the fix is in the listing rather than in the Iceberg command so that the
glob iterator, AzureQueue and the plain metadata storages get it too.

Azurite has no hierarchical namespace, so the tests create the directory
entries by hand with the same marker. Measured on Azurite, a 1000-blob page is
byte-identical with and without include=metadata, and the request count does
not change.

Closes ClickHouse#125462

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…test

Add a non-empty blob that carries hdi_isfolder=true to
test_glob_skips_directory_entries and expect it in the listing. Only an
empty blob with the marker is a directory entry, so a blob with content
must still be listed whatever its metadata. Without the BlobSize check the
test now fails with marked.csv missing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds, 3 findings, 0 in round 2) plus my own review (nits only).

# Sev Finding Verdict Evidence / action
1 ⚠️ The size guard of isDirectoryEntry had no fixture AGREE, fixed the glob test lists a non-empty blob with hdi_isfolder=true; a build without the guard fails it (marked.csv missing)
2 ⚠️ The orphan test uses a fixed time.sleep(2) before older_than = now DISAGREE older_than is taken at least 2 s after the uploads at second resolution, so last_modified < older_than holds strictly; same pattern as the CI-green test_remove_orphan_files_azure; 5/5 repeats
3 💡 Category should be Bug Fix DISAGREE the reported misbehavior is in the experimental remove_orphan_files; none observed through a documented surface on a real account with a hierarchical namespace
4 💡 existsOrHasAnyChild (max_keys = 1) pages past leading directory entries on a hierarchical namespace noted, not blocking one more List Blobs per directory entry before the first file; flat accounts unaffected; stated in the description

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261012-203000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Both new integration tests fail on master on every run (Azurite, directory entries emulated with hdi_isfolder=true): the dry run counts 4 data files instead of 2, and the glob returns cont/<prefix>/sub.
b Root cause explained? On a hierarchical namespace List Blobs returns each directory as an empty blob with hdi_isfolder=true. AzureObjectStorage never requested metadata and emitted every item, so remove_orphan_files took directories for orphan files and its Delete on a non-empty one returns 409 on every run.
c Fix matches root cause? Yes. Both Azure listings request metadata and skip empty blobs with the marker, at the layer that returned directories as objects; Local and HDFS listings already skip directories. No change in Iceberg code.
d Test intent preserved / new tests added? Two new tests, one per listing site (listObjects through remove_orphan_files, iterate through an azureBlobStorage glob). Existing tests unchanged.
e Both directions demonstrated? Yes, on Build-ID-verified binaries: both new tests fail on master and pass with the fix; each repeated 5/5 green with the fix.
f Fix is general across code paths? Both Azure listing sites use one helper; existsOrHasAnyChild goes through listObjects. Delete paths are unchanged and no longer receive directory paths.
g Fix generalizes across inputs (params/datatypes/wrappers)? A blob with content is never skipped (asserted: a non-empty blob with the marker is still listed); an empty blob without the marker is kept (asserted: a real empty orphan is still deleted). Key matched case-insensitively and value exactly, as the SDK does. A page made only of directory entries keeps paging.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or on-disk change; only directory entries stop appearing as files.
i Invariants and contracts preserved? Listings return objects only, as on Local and HDFS; max_keys and paging unchanged; the helper is a pure predicate with no new error paths.

Session id: cron:clickhouse-impl-slot-41:20261012-193200

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8454357]

Summary: ✅


AI Review

Summary

Reviewed #125500 at 8454357570ebb844bd09dee35d13124cde7e87d7, including all prior discussion. The change excludes empty Azure directory entries marked hdi_isfolder=true from both listing paths, preventing remove_orphan_files from treating directories as orphan files while retaining genuine empty files and non-empty blobs. No actionable findings.

Missing context / blind spots
  • ⚠️ No local build or integration tests were run in this review. Current CI has not published integration test results. The author reports repeated before/after Azurite regression runs; a real ADLS Gen2 account has not been validated with this patch. Completed integration CI and a live account run would close these validation gaps.
Final Verdict

Status: ✅ Approve. No code changes requested.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f96308f

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore flaky, not from this PR (it only changes the Azure blob listing): UNKNOWN_TABLE (code 60) for the reused MATERIALIZED CTE _materialized_cte_c_* on a parallel replicas read; 120 of 120 reruns with the same settings passed. 182 other PRs and 31 master runs show it since 2026-10-08 #123121 (mine, open)
Upgrade check (amd_release) / Error message in clickhouse-server.log (see upgrade_error_messages.txt) not from this PR: after the upgrade restart a background mutation keeps retrying on the empty part all_1_1_1_2 that DETACH PART leaves in 04653_mutation_rewrite_stale_part_column_type, and logs MutatePlainMergeTreeTask: Code: 47 ... Unknown expression identifier 'b' (UNKNOWN_IDENTIFIER). The same line failed this check on 76 PRs in 30 days and on no master run #125293 (external, open)
Mergeable Check, PR praktika rollups of the two rows above #123121 (mine, open); #125293 (external, open)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261013-070008

@PedroTadim PedroTadim self-assigned this Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 845435757 with master 0d3338be0 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.61, programs/clickhouse-keeper ×0.63 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 9.7 s +6.2 s (+177%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.3 s +5.2 s (+259%)
Compile time of recompiled translation units

9 translation units recompiled, 21 s compile time in total, 9 of them have a recent master baseline.

Job report

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 458eb63 Nov 13, 2026
203 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg remove_orphan_files on Azure with a hierarchical namespace takes directories for orphan files and fails to delete them on every run

3 participants