Skip to content

[python] Clean up normal files when composite writer metadata creation fails - #9917

Merged
JingsongLi merged 1 commit into
apache:masterfrom
wangzhigang1999:fix/python-composite-writer-file-cleanup
Sep 17, 2026
Merged

JingsongLi merged 1 commit into
apache:masterfrom
wangzhigang1999:fix/python-composite-writer-file-cleanup

Conversation

@wangzhigang1999

Copy link
Copy Markdown
Contributor

Purpose

Fixes #9916

DataVectorWriter and DedicatedFormatWriter can leave a normal data file behind if writing succeeds but a later step, such as reading the file size, fails before returning its metadata.

Wrap normal-file output and metadata creation in try/except. On failure, call delete_quietly for the current file and re-raise the original exception.

Tests

Add one regression test covering both writers: write a real Parquet file, fail while reading its size, and assert that no Parquet file remains. Both cases fail on the base revision and pass with the fix.

The new regression and existing composite flush/shared-shredding tests passed (10 test methods). Flake8 and whitespace checks passed with Python 3.12.6 / PyArrow 19.0.1.

Copilot AI lite review requested due to automatic review settings September 17, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation directly addresses the reported leak and includes focused regression coverage.

Pull request overview

Adds cleanup for normal data files when composite writer metadata creation fails.

Changes:

  • Wraps normal-file writing and metadata creation in cleanup handlers.
  • Adds regression coverage for both composite writers.
File summaries
File Description
dedicated_format_writer.py Deletes failed normal-file output and re-raises errors.
data_vector_writer.py Adds equivalent cleanup handling.
writer_file_cleanup_test.py Verifies failed metadata creation leaves no Parquet file.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the normal-file cleanup path. Deleting the completed data file when subsequent metadata creation fails prevents orphan files while preserving the original exception; the regression coverage exercises both composite writers. No additional blocking issues found.

@JingsongLi
JingsongLi merged commit cfa3612 into apache:master Sep 17, 2026
14 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.

[Bug] PyPaimon composite writers leave normal files behind when metadata creation fails

3 participants