Skip to content

refactor: extract ReachableFileUtil from ExpireSnapshots - #1214

Draft
WZhuo wants to merge 1 commit into
apache:mainfrom
WZhuo:refactor/reachable-file-util
Draft

WZhuo wants to merge 1 commit into
apache:mainfrom
WZhuo:refactor/reachable-file-util

Conversation

@WZhuo

@WZhuo WZhuo commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Table maintenance work such as orphan file removal, purging a table, and rewriting table paths needs to find every file that table metadata references. Iceberg Java keeps this logic in ReachableFileUtil. In C++ the equivalent code is private to ExpireSnapshots, so it cannot be reused. This PR moves it into a public ReachableFileUtil, which those follow-up actions can build on.

Approach:

  • ReachableFileUtil (util/reachable_file_util.{h,cc}) provides the same location helpers as Java: VersionHintLocation, MetadataFileLocations (optionally recursive), ManifestListLocations, and StatisticsFilesLocations(ForSnapshots).
  • It also provides manifest helpers that have no counterpart in Java's class: ReachableManifests, ManifestsForSnapshots, LiveFileLocations, and LiveFileLocationsForManifests. They take an optional Executor, like the rest of the code base.
  • ReachableFileCleanup in ExpireSnapshots now calls these helpers instead of its private copies. Error handling and executor use are unchanged. IncrementalFileCleanup is not touched.
  • Differences from Java's metadataFileLocations:
    • A visited set stops the recursive walk when metadata logs reference each other in a cycle.
    • The walk is a loop, not recursion, so each previous metadata file is freed before the next one is read.
    • When a previous metadata file can't be read, the log message gives only its position in the metadata log. The location and the IO error are left out because they may contain credentials.
    • Like Java, each step follows only the first metadata file in the log that can be read.

Verification:

  • Built table_update_test locally with Arrow 25.0.0 and AppleClang. All 1050 tests pass, and the remaining 33 are the format-version variants that were already skipped. This includes the new ReachableFileUtilTest cases and every existing ExpireSnapshots* test.
  • pre-commit passes, including the regenerated cpp20_compatibility_internal.h.
  • Not verified locally: GCC, MSVC, the ICEBERG_CXX20_COMPAT build, and the other test executables. CI covers these.

Known limitations, out of scope here:

  • TableMetadataUtil::Read rejects v1 metadata that lists manifests inline without a manifest-list. The recursive walk skips such files.
  • RunTasksParallel does not wait for tasks the executor already accepted if a later Executor::Submit throws. That code is shared with the existing callers and is unchanged by this PR.

AI disclosure: Claude Code (Claude Opus) wrote the code, tests, and this description. It was reviewed by a Claude subagent and by OpenAI Codex (codex review) over several rounds, and their findings were addressed. The human contributor will state what they reviewed.

Add a public ReachableFileUtil mirroring Java's ReachableFileUtil, and
make ExpireSnapshots' reachable file cleanup use it for reading snapshot
manifests and live file paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant