Skip to content
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

Merged
merged 8 commits into from
May 15, 2023

Conversation

mapleFU
Copy link
Member

@mapleFU mapleFU commented May 9, 2023

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

@mapleFU mapleFU requested a review from wjones127 as a code owner May 9, 2023 16:47
@github-actions
Copy link

github-actions bot commented May 9, 2023

@mapleFU
Copy link
Member Author

mapleFU commented May 9, 2023

@pitrou Would you mind take a look? Analyze is in #35519 (comment)

@github-actions
Copy link

github-actions bot commented May 9, 2023

⚠️ GitHub issue #35519 has been automatically assigned in GitHub to PR creator.

@pitrou
Copy link
Member

pitrou commented May 9, 2023

I think we should instead prevent RowGroupSerializer::Close from creating an invalid internal state. For example:

  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_);
    }
  }

@mapleFU
Copy link
Member Author

mapleFU commented May 9, 2023

@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;
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels May 9, 2023
Comment on lines 222 to 223
// If ColumnWriter::Close thrown an exception, avoid
// have bad states in column_writers_.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If ColumnWriter::Close thrown an exception, avoid
// have bad states in column_writers_.
// Avoid invalid state if ColumnWriter::Close() throws internally.

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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

@mapleFU
Copy link
Member Author

mapleFU commented May 10, 2023

Comment resolved. I tried to solve some CI problems here: #35527

Seems CI failed frequently these days...

@pitrou
Copy link
Member

pitrou commented May 10, 2023

Seems CI failed frequently these days...

Unfortunately :-( Are there issues already open for these failures?

Copy link
Member

@pitrou pitrou left a 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.

@pitrou
Copy link
Member

pitrou commented May 10, 2023

Hmm, the R CI failure may be related as it seems to succeed on git main:
https://github.com/apache/arrow/actions/runs/4937417890/jobs/8826087049

@mapleFU
Copy link
Member Author

mapleFU commented May 10, 2023

Yeah, I don't want to rebase this because there are still too much failed tests :-(
Just wait others idea on this patch or merge if you think it's ok

@pitrou
Copy link
Member

pitrou commented May 10, 2023

We can't merge until we make sure the R CI failure is unrelated.

@pitrou
Copy link
Member

pitrou commented May 10, 2023

Hmm, actually the segfault is already known:
#35391

@mapleFU
Copy link
Member Author

mapleFU commented May 10, 2023

😭Hurt by so many failed

@mapleFU
Copy link
Member Author

mapleFU commented May 11, 2023

[ RUN      ] TestScan/TestCsvFileFormatScan.ScanBatchSize/0Threaded16b1024r
unknown file: error: SEH exception with code 0xc00000fd thrown in the test body.
[  FAILED  ] TestScan/TestCsvFileFormatScan.ScanBatchSize/0Threaded16b1024r, where GetParam() = Threaded16b1024r (314 ms)

I guess this is unrelated. https://ci.appveyor.com/project/ApacheSoftwareFoundation/arrow/builds/47021836

@mapleFU
Copy link
Member Author

mapleFU commented May 11, 2023

@pitrou Seems R failed is not related. Would you mind take a look?

@mapleFU mapleFU requested a review from pitrou May 15, 2023 14:11
@pitrou
Copy link
Member

pitrou commented May 15, 2023

I'm restarting CI a last time but it looks like this is ready to go.

@pitrou pitrou merged commit 2d76d9a into apache:main May 15, 2023
ArgusLi pushed a commit to Bit-Quill/arrow that referenced this pull request May 15, 2023
…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]>
@mapleFU mapleFU deleted the parquet/fixing-npe branch May 16, 2023 02:46
@ursabot
Copy link

ursabot commented May 16, 2023

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.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.26% ⬆️0.0%] test-mac-arm
[Finished ⬇️0.51% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.42% ⬆️0.03%] ursa-thinkcentre-m75q
Buildkite builds:
[Finished] 2d76d9a5 ec2-t3-xlarge-us-east-2
[Finished] 2d76d9a5 test-mac-arm
[Finished] 2d76d9a5 ursa-i9-9960x
[Finished] 2d76d9a5 ursa-thinkcentre-m75q
[Finished] e2e3a9df ec2-t3-xlarge-us-east-2
[Finished] e2e3a9df test-mac-arm
[Finished] e2e3a9df ursa-i9-9960x
[Finished] e2e3a9df ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

rtpsw pushed a commit to rtpsw/arrow that referenced this pull request May 16, 2023
…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]>
raulcd pushed a commit that referenced this pull request May 30, 2023
…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]>
dirtysalt pushed a commit to StarRocks/starrocks that referenced this pull request Jun 20, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C++][Parquet] Segfault when exception handling and closing RowGroupSerializer
4 participants