-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-35519: [C++][Parquet] Fixing exception handling in parquet FileSerializer #35520
Conversation
@pitrou Would you mind take a look? Analyze is in #35519 (comment) |
|
I think we should instead prevent void Close() override {
if (!closed_) {
closed_ = true;
CheckRowsWritten();
auto column_writers = std::move(columns_writers_);
for (const auto writer : column_writers) {
if (writer) {
total_bytes_written_ += writer->Close();
total_compressed_bytes_written_ +=
writer->total_compressed_bytes_written();
}
}
// Ensures all columns have been written
metadata_->set_num_rows(num_rows_);
metadata_->Finish(total_bytes_written_, row_group_ordinal_);
}
} |
@pitrou Good Idea! Fix as your advice |
@@ -380,15 +382,15 @@ class FileSerializer : public ParquetFileWriter::Contents { | |||
void AddKeyValueMetadata( | |||
const std::shared_ptr<const KeyValueMetadata>& key_value_metadata) override { | |||
if (key_value_metadata_ == nullptr) { | |||
key_value_metadata_ = std::move(key_value_metadata); | |||
key_value_metadata_ = key_value_metadata; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
cpp/src/parquet/file_writer.cc
Outdated
// If ColumnWriter::Close thrown an exception, avoid | ||
// have bad states in column_writers_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If ColumnWriter::Close thrown an exception, avoid | |
// have bad states in column_writers_. | |
// Avoid invalid state if ColumnWriter::Close() throws internally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anything wrong happens here, should we let the FileSerializer know that it cannot accept any write any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's already closed, whether success or not, no any write can comes to RowGroupSerializer
. I guess it will cause FileSerializer
destruct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true if the exception happens when calling FileSerializer::Close()
. What if this happens when the user directly calls RowGroupWriter::Close()
to close the current row group and starts a new one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void Close() override {
if (!closed_) {
closed_ = true;
CheckRowsWritten();
// ...
// Ensures all columns have been written
metadata_->set_num_rows(num_rows_);
metadata_->Finish(total_bytes_written_, row_group_ordinal_);
}
}
I guess it will mark closed_
first and throw exception. During stack unwind, the RowGroupSerializer
will destruct. And during next time Close
is called, it will do nothing
Comment resolved. I tried to solve some CI problems here: #35527 Seems CI failed frequently these days... |
Unfortunately :-( Are there issues already open for these failures? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mapleFU . This looks ok now.
Hmm, the R CI failure may be related as it seems to succeed on git main: |
Yeah, I don't want to rebase this because there are still too much failed tests :-( |
We can't merge until we make sure the R CI failure is unrelated. |
Hmm, actually the segfault is already known: |
😭Hurt by so many failed |
I guess this is unrelated. https://ci.appveyor.com/project/ApacheSoftwareFoundation/arrow/builds/47021836 |
@pitrou Seems R failed is not related. Would you mind take a look? |
I'm restarting CI a last time but it looks like this is ready to go. |
…ileSerializer (apache#35520) ### Rationale for this change Mentioned in apache#35519 ### What changes are included in this PR? Exception handling in `CheckRowsWritten` ### Are these changes tested? No, I don't know how to mock it currently ### Are there any user-facing changes? no * Closes: apache#35519 Authored-by: mwish <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
Benchmark runs are scheduled for baseline = e2e3a9d and contender = 2d76d9a. 2d76d9a is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
…ileSerializer (apache#35520) ### Rationale for this change Mentioned in apache#35519 ### What changes are included in this PR? Exception handling in `CheckRowsWritten` ### Are these changes tested? No, I don't know how to mock it currently ### Are there any user-facing changes? no * Closes: apache#35519 Authored-by: mwish <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
…ializer (#35520) ### Rationale for this change Mentioned in #35519 ### What changes are included in this PR? Exception handling in `CheckRowsWritten` ### Are these changes tested? No, I don't know how to mock it currently ### Are there any user-facing changes? no * Closes: #35519 Authored-by: mwish <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
Fixes #23606, where memory leaks are introduced by `_chunk_writer->release()` The modification on Arrow is to make sure `RowGroupSerializer::column_writers_` is cleaned up even if exception throws. You may refer apache/arrow#35520 for more details. Signed-off-by: Letian Jiang <[email protected]>
Rationale for this change
Mentioned in #35519
What changes are included in this PR?
Exception handling in
CheckRowsWritten
Are these changes tested?
No, I don't know how to mock it currently
Are there any user-facing changes?
no