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

Add a public ReachableFileUtil mirroring Java's ReachableFileUtil for
metadata and statistics file locations, plus manifest helpers that read
manifest lists and manifests to find the manifests and live content files
of snapshots. ExpireSnapshots' reachable file cleanup uses them.
Previous metadata files are not read, which the API documents.

Behavior changes beyond the refactor:

  • Reachable cleanup resolves only the manifest's partition spec when
    reading live files, instead of building a map of all specs. Expired manifests are
    resolved against the pre-expiration metadata, which may still hold their
    specs, and retained manifests against the committed metadata.
  • ReachableFileUtil reports reader exceptions, such as an avro::Exception
    from a corrupt file, as InvalidManifestList or InvalidManifest errors
    that name the file, instead of letting them escape.
  • Both cleanup paths skip expired manifests that are missing, as before.
    An IOError counts as missing only if checking the file's size reports
    NotFound. InputFile::Size() documents that contract, and
    ArrowFileSystemFileIO now follows it for ENOENT and ENOTDIR. On Windows
    only a missing file or path counts, not other errors that Arrow maps to
    ENOENT, such as an unavailable drive or network share.
    They stop before deleting any file if a manifest exists but cannot be
    read, fails to decode, or has an unknown partition spec, or if a
    retained manifest or manifest list cannot be read or is missing, or if
    an expired manifest list exists but cannot be read, since the data files
    to delete are then unknown. Previously the reachable path stopped only
    when a reader threw, and the incremental path treated every failure as
    an empty manifest. Incremental cleanup reads only the file paths of
    manifests to scan, so partition values it does not use, such as fixed
    values the reader cannot decode, do not stop it, and it keeps paths that
    are live again in a retained snapshot. It reads retained manifests only
    while some candidate is not yet known to be live, and a retained
    manifest that cannot be read stops it only if some candidate is not.
  • AvroReader reports a read error from the input stream instead of
    treating it as the end of the file, which returned the records read
    before it as if they were complete. Cleanup could then miss files that
    a retained manifest still references. Failures outside a split, before
    it, past its end, or in the start of the next block that Avro reads to
    find its end, are still ignored, since the split does not need those
    bytes, including the first block, which Avro reads when opening the
    file, and a split of no bytes. A read error that makes Avro throw, for example inside
    the header or a block, is reported as such, not as a malformed file,
    so a missing file that only fails on its first read, as on S3 with a
    known length, is still found missing.
  • RunTasksParallel converts exceptions thrown by Executor::Submit, by a
    task itself, and broken promises from a dropped task into errors, and
    waits for all accepted tasks on every exit path, since tasks may
    reference the caller's state.

Testing: all 20 test binaries pass (ctest). New tests cover each behavior change and fail when it is reverted. The Windows-specific error classification is not exercised on non-Windows CI.

🤖 Generated with Claude Code

@WZhuo
WZhuo force-pushed the refactor/reachable-file-util branch 29 times, most recently from f1ff624 to 6757856 Compare December 5, 2026 22:31
Add a public ReachableFileUtil mirroring Java's ReachableFileUtil for
metadata and statistics file locations, plus manifest helpers that read
manifest lists and manifests to find the manifests and live content files
of snapshots. ExpireSnapshots' reachable file cleanup uses them.
Previous metadata files are not read, which the API documents.

Behavior changes beyond the refactor:
- Reachable cleanup resolves only the manifest's partition spec when
  reading live files, instead of building a map of all specs. Expired manifests are
  resolved against the pre-expiration metadata, which may still hold their
  specs, and retained manifests against the committed metadata.
- ReachableFileUtil reports reader exceptions, such as an avro::Exception
  from a corrupt file, as InvalidManifestList or InvalidManifest errors
  that name the file, instead of letting them escape.
- Both cleanup paths skip expired manifests that are missing, as before.
  An IOError counts as missing only if checking the file's size reports
  NotFound. InputFile::Size() documents that contract, and
  ArrowFileSystemFileIO now follows it for ENOENT and ENOTDIR. On Windows
  only a missing file or path counts, not other errors that Arrow maps to
  ENOENT, such as an unavailable drive or network share.
  They stop before deleting any file if a manifest exists but cannot be
  read, fails to decode, or has an unknown partition spec, or if a
  retained manifest or manifest list cannot be read or is missing, or if
  an expired manifest list exists but cannot be read, since the data files
  to delete are then unknown. Previously the reachable path stopped only
  when a reader threw, and the incremental path treated every failure as
  an empty manifest. Incremental cleanup reads only the file paths of
  manifests to scan, so partition values it does not use, such as fixed
  values the reader cannot decode, do not stop it, and it keeps paths that
  are live again in a retained snapshot. It reads retained manifests only
  while some candidate is not yet known to be live, and a retained
  manifest that cannot be read stops it only if some candidate is not.
- AvroReader reports a read error from the input stream instead of
  treating it as the end of the file, which returned the records read
  before it as if they were complete. Cleanup could then miss files that
  a retained manifest still references. Failures outside a split, before
  it, past its end, or in the start of the next block that Avro reads to
  find its end, are still ignored, since the split does not need those
  bytes, including the first block, which Avro reads when opening the
  file, and a split of no bytes. A read error that makes Avro throw, for example inside
  the header or a block, is reported as such, not as a malformed file,
  so a missing file that only fails on its first read, as on S3 with a
  known length, is still found missing.
- RunTasksParallel converts exceptions thrown by Executor::Submit, by a
  task itself, and broken promises from a dropped task into errors, and
  waits for all accepted tasks on every exit path, since tasks may
  reference the caller's state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@WZhuo
WZhuo force-pushed the refactor/reachable-file-util branch from 6757856 to 8dc88ee Compare December 5, 2026 22:52

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