Skip to content

[FIX,TEST] Five more Parquet writers left a partial file behind - #9862

Merged
timosachsenberg merged 2 commits into
developfrom
fix/parquet-writers-partial-file
Aug 5, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
fix/parquet-writers-partial-file

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Completes the class of fix already applied to ConsensusMapArrowExport, QPXFile and ArrowIOHelpers::writeTableToParquet (#9849, #9854). Found by the audit that produced #9853 / #9859; I re-verified every claim in the sources before touching them rather than taking the audit's word.

The defect

arrow::io::FileOutputStream::Open creates and truncates the file before the table is written, so any failure afterwards leaves a fragment carrying little more than the Parquet magic bytes — no footer, so a reader reports it as corrupt rather than as the smaller table it looks like.

None of these five removed it. A grep confirms not one contained a File::remove call:

writer Open File::remove Close()
ProteinIdentificationArrowIO 1 0 0
FeatureMapArrowIO 1 0 0
ConsensusMapArrowIO 1 0 0
ParquetFile 1 0 0
MSExperimentArrowExport 1 0 1

All five now close the stream and remove the file on any failure after the open.

Four of the five also never closed the stream explicitly on success, leaving it to the destructor, which discards the error — so a failed final flush, which is where a full disk surfaces, was reported as success with a truncated file on disk. They now close and check. MSExperimentArrowExport already checked its Close; only the removal was missing there.

ParquetFile::writeTable is the highest-value one: it is the shared helper behind the OpenSwath and library exporters, and it throws rather than returning, so a caller writing several tables into a directory left the earlier ones plus one truncated file.

Tests

Each fix ships with a class-test section confirmed to fail without it — all five fail at the TEST_FALSE(File::exists(...)) assertion when the sources are reverted and the library rebuilt:

MSExperimentArrowExport_test ........***Failed
ParquetFile_test ....................***Failed
ProteinIdentificationArrowIO_test ...***Failed
FeatureMapArrowIO_test ..............***Failed
ConsensusMapArrowIO_test ............***Failed

A row group size of 0 is refused by Parquet for a non-empty table, which reaches a post-open write failure deterministically on every platform without having to simulate an I/O error.

29 Arrow/Parquet/QPX tests pass with the fixes in place.

Deliberately out of scope

  • The three streaming consumers (XIPMParquetConsumer, MobilogramParquetConsumer, MSChromatogramParquetConsumer) have the same gap, but they flush incrementally, so "close and remove" would discard work a caller may prefer to keep. The right contract there — remove vs. rename-to-.partial vs. write-to-temp-and-rename — is a design decision, not a bug fix, and wants an owner.
  • Collection-level atomicity. For the two directory-based writers the test targets the first file of the collection, so nothing else has been written when it fails. Earlier files of a multi-file export surviving a later failure is a different granularity — QPXCollectionExport::Transaction solves it for -out_qpx; .featureparquet / .consensusparquet / ProSE's -out_qpx have no equivalent.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ

Summary by CodeRabbit

  • Bug Fixes

    • Improved Parquet export reliability by detecting write, close, and final flush failures.
    • Failed exports now clean up incomplete output files instead of leaving partial results behind.
    • Successful exports explicitly finalize and validate output streams, surfacing previously hidden errors.
    • Added clearer reporting when output cleanup cannot be completed.
  • Tests

    • Added regression coverage across supported Parquet export workflows to verify failed writes return errors and leave no partial files.

Completes the class of fix already applied to ConsensusMapArrowExport, QPXFile
and ArrowIOHelpers::writeTableToParquet.

arrow::io::FileOutputStream::Open creates and truncates the file before the table
is written, so any failure afterwards leaves a fragment carrying little more than
the Parquet magic bytes -- no footer, so a reader reports it as corrupt rather
than as the smaller table it looks like. None of these five removed it; a grep
confirms not one contained a File::remove call.

  - ProteinIdentificationArrowIO  (proteins / protein_groups / search_params)
  - FeatureMapArrowIO             (.featureparquet)
  - ConsensusMapArrowIO           (.consensusparquet)
  - ParquetFile::writeTable       (shared helper: OpenSwath + library exporters)
  - MSExperimentArrowExport       (spectra / chromatograms)

All five now close the stream and remove the file on any failure after the open.

Four of the five also never closed the stream explicitly on success, leaving it
to the destructor, which discards the error -- so a failed final flush, which is
where a full disk surfaces, was reported as success with a truncated file on
disk. They now close and check. MSExperimentArrowExport already checked its
Close; only the removal was missing there.

ParquetFile::writeTable is the highest-value one: it is a shared helper and it
THROWS rather than returning, so a caller writing several tables into a directory
left the earlier ones plus one truncated file.

Each fix ships with a class-test section confirmed to fail without it -- all five
fail at the TEST_FALSE(File::exists(...)) assertion when the sources are reverted.
A row group size of 0 is refused by Parquet for a non-empty table, which reaches
a post-open write failure deterministically on every platform without needing to
simulate an I/O error.

For the two directory-based writers the test targets the FIRST file of the
collection, so nothing else has been written when it fails. Collection-level
atomicity -- earlier files of a multi-file export surviving a later failure -- is
a separate concern and is not addressed here.

Not included: the three streaming consumers (XIPM, Mobilogram, MSChromatogram)
have the same gap, but they flush incrementally, so "close and remove" would
discard work a caller may prefer to keep. The right contract there (remove vs.
rename-to-.partial vs. write-to-temp-and-rename) is a design decision rather than
a bug fix.

29 Arrow/Parquet/QPX tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e0c5516f-0d5d-4470-b59d-6e6d7bd69ba2

📥 Commits

Reviewing files that changed from the base of the PR and between 324ef3f and c94ba08.

📒 Files selected for processing (1)
  • CHANGELOG
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG

📝 Walkthrough

Walkthrough

Five Parquet writers now close streams explicitly, remove incomplete files after write or close failures, and report cleanup errors. Regression tests verify that failed writes remove partial files.

Changes

Parquet output cleanup

Layer / File(s) Summary
Writer failure handling
src/openms/source/FORMAT/*ArrowIO.cpp, src/openms/source/FORMAT/MSExperimentArrowExport.cpp, src/openms/source/FORMAT/ParquetFile.cpp, CHANGELOG
Five Parquet writers now close streams, remove incomplete files, report cleanup failures, and detect final flush or close errors.
Failure-path regression coverage
src/tests/class_tests/openms/source/*ArrowIO_test.cpp, src/tests/class_tests/openms/source/MSExperimentArrowExport_test.cpp, src/tests/class_tests/openms/source/ParquetFile_test.cpp
Tests force write failures and verify failed results or exceptions and the absence of partial output files.

Possibly related PRs

  • OpenMS/OpenMS#9849: Both PRs address partial Parquet output cleanup and write or flush failure handling.

Poem

A rabbit checks each Parquet stream,
Partial files vanish from the scene.
Close errors now appear in sight,
Failed writes leave no file in flight.
Five writers finish clean and bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix and tests for partial files left by five Parquet writers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/parquet-writers-partial-file

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (7)
src/tests/class_tests/openms/source/ConsensusMapArrowIO_test.cpp (1)

963-993: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test logic is correct; temp-directory setup deviates from NEW_TMP_FILE convention.

The failure-path assertions are correct: the first export succeeds, removing consensus_features.parquet and re-exporting with row_group_size = 0 deterministically fails, and the file is confirmed absent afterward.

This test builds its temp directory manually with File::getTempDirectory() + "/" + File::getUniqueName() + "_cmio" and File::makeDir(dir), instead of the NEW_TMP_FILE(tmp_dir); tmp_dir += ".cmd"; pattern that every other directory-based test in this file uses (for example lines 529-533, 843-846). See the consolidated comment for the fix, which also applies to FeatureMapArrowIO_test.cpp.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/class_tests/openms/source/ConsensusMapArrowIO_test.cpp` around
lines 963 - 993, Update the test’s temporary-directory setup to use the file’s
established NEW_TMP_FILE(tmp_dir) convention, then append the “.cmd” suffix
before creating or using the directory. Remove the manual
File::getTempDirectory(), File::getUniqueName(), and File::makeDir setup while
preserving the existing failure-path assertions and cleanup.

Source: Path instructions

src/openms/source/FORMAT/ConsensusMapArrowIO.cpp (1)

765-793: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Cleanup logic is correct; duplicated across five writers.

The abandon lambda correctly closes the stream before removing the file (avoids the Windows open-handle issue) and covers both the write-failure and close-failure paths. Logic is sound.

This exact pattern (log, Close(), File::remove(), return failure) is now duplicated nearly verbatim in FeatureMapArrowIO.cpp, ProteinIdentificationArrowIO.cpp, and MSExperimentArrowExport.cpp, and in throw-based form in ParquetFile.cpp. The CHANGELOG for this PR also states ArrowIOHelpers::writeTableToParquet already implements the identical pattern. See the consolidated comment for a proposed extraction.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/ConsensusMapArrowIO.cpp` around lines 765 - 793,
Extract the duplicated incomplete-output cleanup from the local abandon lambda
and the corresponding writer implementations into the shared
ArrowIOHelpers::writeTableToParquet cleanup path. Reuse that helper for write
and close failures so it logs the error, closes the stream before removing the
file, reports removal failures, and preserves each caller’s existing failure
behavior.
src/openms/source/FORMAT/FeatureMapArrowIO.cpp (1)

689-717: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Cleanup logic correct; part of the cross-file duplication noted for ConsensusMapArrowIO.cpp.

Same abandon cleanup lambda as ConsensusMapArrowIO.cpp, ProteinIdentificationArrowIO.cpp, and MSExperimentArrowExport.cpp. See the consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/FeatureMapArrowIO.cpp` around lines 689 - 717,
Refactor the duplicated abandon cleanup logic in the FeatureMapArrowIO
write/close error path to use the shared cleanup mechanism established for
ConsensusMapArrowIO, ProteinIdentificationArrowIO, and MSExperimentArrowExport.
Preserve the existing error messages, explicit Close-before-remove behavior, and
false return semantics while removing the local abandon lambda.
src/openms/source/FORMAT/ParquetFile.cpp (1)

61-90: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Cleanup logic correct; same duplicated pattern, adapted to the throw-based API.

abandon always throws, so execution never continues past either call site — correct. This mirrors the cleanup logic in the four writeArrowTableToParquet_ functions, adapted to this class's exception-based contract instead of a bool return. See the consolidated comment for the cross-file duplication note.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/ParquetFile.cpp` around lines 61 - 90, The cleanup
logic in the parquet write failure paths is correct; retain the `abandon` lambda
and its use after failed write or close operations. No changes are required for
this review comment.
src/openms/source/FORMAT/ProteinIdentificationArrowIO.cpp (1)

181-208: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Cleanup logic correct; part of the cross-file duplication noted for ConsensusMapArrowIO.cpp.

Same abandon cleanup lambda as the other writers. See the consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/ProteinIdentificationArrowIO.cpp` around lines 181 -
208, Deduplicate the repeated abandon cleanup logic shared by
ProteinIdentificationArrowIO and ConsensusMapArrowIO by extracting or reusing a
common helper. Preserve the existing behavior: log the failure, close outfile
before removing filename, report removal failures, and return false; update both
writers to use the shared implementation.
src/tests/class_tests/openms/source/FeatureMapArrowIO_test.cpp (1)

1469-1499: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test logic is correct; temp-directory setup deviates from NEW_TMP_FILE convention.

The failure-path assertions are correct and mirror the pattern used in the other four writers' tests.

This test builds its temp directory manually instead of using NEW_TMP_FILE(tmp_dir); tmp_dir += ".fmd";, which every other directory-based test in this file uses (for example lines 821-823, 1341-1343). See the consolidated comment for the fix, which also applies to ConsensusMapArrowIO_test.cpp.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/class_tests/openms/source/FeatureMapArrowIO_test.cpp` around lines
1469 - 1499, Update the failed-write test around
FeatureMapArrowIO::exportToParquet to use the file’s established
NEW_TMP_FILE(tmp_dir) convention, then append the “.fmd” suffix for the
directory path instead of manually combining File::getTempDirectory(),
File::getUniqueName(), and makeDir. Preserve the existing failure-path
assertions and cleanup behavior.

Source: Path instructions

src/openms/source/FORMAT/MSExperimentArrowExport.cpp (1)

1263-1289: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Cleanup logic correct; part of the cross-file duplication noted for ConsensusMapArrowIO.cpp.

Same abandon cleanup lambda pattern as the other four writers. See the consolidated comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/MSExperimentArrowExport.cpp` around lines 1263 -
1289, The Parquet export defines cleanup logic duplicated across the Arrow
writers. Extract the shared `abandon` behavior into the common utility used by
the other writers, then update the `abandon` calls in the Parquet export to
reuse it while preserving close-before-remove, error logging, and false-return
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/openms/source/FORMAT/ConsensusMapArrowIO.cpp`:
- Around line 765-793: Extract the duplicated incomplete-output cleanup from the
local abandon lambda and the corresponding writer implementations into the
shared ArrowIOHelpers::writeTableToParquet cleanup path. Reuse that helper for
write and close failures so it logs the error, closes the stream before removing
the file, reports removal failures, and preserves each caller’s existing failure
behavior.

In `@src/openms/source/FORMAT/FeatureMapArrowIO.cpp`:
- Around line 689-717: Refactor the duplicated abandon cleanup logic in the
FeatureMapArrowIO write/close error path to use the shared cleanup mechanism
established for ConsensusMapArrowIO, ProteinIdentificationArrowIO, and
MSExperimentArrowExport. Preserve the existing error messages, explicit
Close-before-remove behavior, and false return semantics while removing the
local abandon lambda.

In `@src/openms/source/FORMAT/MSExperimentArrowExport.cpp`:
- Around line 1263-1289: The Parquet export defines cleanup logic duplicated
across the Arrow writers. Extract the shared `abandon` behavior into the common
utility used by the other writers, then update the `abandon` calls in the
Parquet export to reuse it while preserving close-before-remove, error logging,
and false-return behavior.

In `@src/openms/source/FORMAT/ParquetFile.cpp`:
- Around line 61-90: The cleanup logic in the parquet write failure paths is
correct; retain the `abandon` lambda and its use after failed write or close
operations. No changes are required for this review comment.

In `@src/openms/source/FORMAT/ProteinIdentificationArrowIO.cpp`:
- Around line 181-208: Deduplicate the repeated abandon cleanup logic shared by
ProteinIdentificationArrowIO and ConsensusMapArrowIO by extracting or reusing a
common helper. Preserve the existing behavior: log the failure, close outfile
before removing filename, report removal failures, and return false; update both
writers to use the shared implementation.

In `@src/tests/class_tests/openms/source/ConsensusMapArrowIO_test.cpp`:
- Around line 963-993: Update the test’s temporary-directory setup to use the
file’s established NEW_TMP_FILE(tmp_dir) convention, then append the “.cmd”
suffix before creating or using the directory. Remove the manual
File::getTempDirectory(), File::getUniqueName(), and File::makeDir setup while
preserving the existing failure-path assertions and cleanup.

In `@src/tests/class_tests/openms/source/FeatureMapArrowIO_test.cpp`:
- Around line 1469-1499: Update the failed-write test around
FeatureMapArrowIO::exportToParquet to use the file’s established
NEW_TMP_FILE(tmp_dir) convention, then append the “.fmd” suffix for the
directory path instead of manually combining File::getTempDirectory(),
File::getUniqueName(), and makeDir. Preserve the existing failure-path
assertions and cleanup behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e562ca30-388c-431b-aa69-39862f7f3c4d

📥 Commits

Reviewing files that changed from the base of the PR and between 240cc58 and 324ef3f.

📒 Files selected for processing (11)
  • CHANGELOG
  • src/openms/source/FORMAT/ConsensusMapArrowIO.cpp
  • src/openms/source/FORMAT/FeatureMapArrowIO.cpp
  • src/openms/source/FORMAT/MSExperimentArrowExport.cpp
  • src/openms/source/FORMAT/ParquetFile.cpp
  • src/openms/source/FORMAT/ProteinIdentificationArrowIO.cpp
  • src/tests/class_tests/openms/source/ConsensusMapArrowIO_test.cpp
  • src/tests/class_tests/openms/source/FeatureMapArrowIO_test.cpp
  • src/tests/class_tests/openms/source/MSExperimentArrowExport_test.cpp
  • src/tests/class_tests/openms/source/ParquetFile_test.cpp
  • src/tests/class_tests/openms/source/ProteinIdentificationArrowIO_test.cpp

@timosachsenberg
timosachsenberg merged commit b3b0742 into develop Aug 5, 2026
34 checks passed
@timosachsenberg
timosachsenberg deleted the fix/parquet-writers-partial-file branch August 5, 2026 14:28
timosachsenberg pushed a commit that referenced this pull request Aug 7, 2026
Three CHANGELOG entries already document their change in full but were
missing the trailing PR citation: consensusXML protein-group quantity
round-tripping (#9844), the FuzzyStringComparator NaN-equality fix
(#9859, #9861), and the "five more Parquet writers left a partial file
behind" fix (#9862).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YAD9pD1nBputTVhzddmCj5
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