Repository navigation
[FIX,TEST] Five more Parquet writers left a partial file behind - #9862
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughFive 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. ChangesParquet output cleanup
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (7)
src/tests/class_tests/openms/source/ConsensusMapArrowIO_test.cpp (1)
963-993: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest logic is correct; temp-directory setup deviates from
NEW_TMP_FILEconvention.The failure-path assertions are correct: the first export succeeds, removing
consensus_features.parquetand re-exporting withrow_group_size = 0deterministically fails, and the file is confirmed absent afterward.This test builds its temp directory manually with
File::getTempDirectory() + "/" + File::getUniqueName() + "_cmio"andFile::makeDir(dir), instead of theNEW_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 toFeatureMapArrowIO_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 liftCleanup logic is correct; duplicated across five writers.
The
abandonlambda 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 inFeatureMapArrowIO.cpp,ProteinIdentificationArrowIO.cpp, andMSExperimentArrowExport.cpp, and in throw-based form inParquetFile.cpp. The CHANGELOG for this PR also statesArrowIOHelpers::writeTableToParquetalready 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 liftCleanup logic correct; part of the cross-file duplication noted for
ConsensusMapArrowIO.cpp.Same
abandoncleanup lambda asConsensusMapArrowIO.cpp,ProteinIdentificationArrowIO.cpp, andMSExperimentArrowExport.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 liftCleanup logic correct; same duplicated pattern, adapted to the throw-based API.
abandonalways throws, so execution never continues past either call site — correct. This mirrors the cleanup logic in the fourwriteArrowTableToParquet_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 liftCleanup logic correct; part of the cross-file duplication noted for
ConsensusMapArrowIO.cpp.Same
abandoncleanup 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 winTest logic is correct; temp-directory setup deviates from
NEW_TMP_FILEconvention.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 toConsensusMapArrowIO_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 liftCleanup logic correct; part of the cross-file duplication noted for
ConsensusMapArrowIO.cpp.Same
abandoncleanup 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
📒 Files selected for processing (11)
CHANGELOGsrc/openms/source/FORMAT/ConsensusMapArrowIO.cppsrc/openms/source/FORMAT/FeatureMapArrowIO.cppsrc/openms/source/FORMAT/MSExperimentArrowExport.cppsrc/openms/source/FORMAT/ParquetFile.cppsrc/openms/source/FORMAT/ProteinIdentificationArrowIO.cppsrc/tests/class_tests/openms/source/ConsensusMapArrowIO_test.cppsrc/tests/class_tests/openms/source/FeatureMapArrowIO_test.cppsrc/tests/class_tests/openms/source/MSExperimentArrowExport_test.cppsrc/tests/class_tests/openms/source/ParquetFile_test.cppsrc/tests/class_tests/openms/source/ProteinIdentificationArrowIO_test.cpp
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
Completes the class of fix already applied to
ConsensusMapArrowExport,QPXFileandArrowIOHelpers::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::Opencreates 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::removecall:OpenFile::removeClose()ProteinIdentificationArrowIOFeatureMapArrowIOConsensusMapArrowIOParquetFileMSExperimentArrowExportAll 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.
MSExperimentArrowExportalready checked itsClose; only the removal was missing there.ParquetFile::writeTableis 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: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
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-.partialvs. write-to-temp-and-rename — is a design decision, not a bug fix, and wants an owner.QPXCollectionExport::Transactionsolves it for-out_qpx;.featureparquet/.consensusparquet/ ProSE's-out_qpxhave no equivalent.🤖 Generated with Claude Code
https://claude.ai/code/session_01VcFtJVe1PcMsBzMnnnpWBJ
Summary by CodeRabbit
Bug Fixes
Tests