Skip to content

Conversation

@rdblue
Copy link
Contributor

@rdblue rdblue commented Aug 31, 2022

This is an alternative fix for the Flink double close problem, #4168 and #5310.

The original solution modified S3OutputStream so that every call to close after a failure would re-throw the original exception. That violates the contract for close, which states:

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

The original fix also did not address the underlying problem that the stream was closed twice and still emitting data files. This PR fixes double close cases in BaseTaskWriter by ensuring the writer that is closed is always set to null.

This PR also attempts to fix the problem of duplicate data in Flink by throwing an IllegalStateException if a call to close fails but complete is still called on the BaseTaskWriter. The write result from complete is the only way to emit data files, so this ensures that no data files will be emitted from a writer that failed while closing a file. This is a precaution because it isn't clear why failed Flink writers were still emitting data files.

if (!closed) {
flushDeletes();
this.closed = true;
flushDeletes();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes double close here as well.

public List<DeleteFile> complete() throws IOException {
close();

Preconditions.checkState(failure != null, "Cannot return results from failed writer", failure);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implements the same logic as in BaseTaskWriter: if there was an exception while writing the file, don't allow complete to succeed.

@danielcweeks danielcweeks merged commit 9f946a1 into apache:master Sep 1, 2022
rdblue added a commit to rdblue/iceberg that referenced this pull request Sep 2, 2022
* Core: Fix exception handling in BaseTaskWriter.

* Fix state check.
rdblue added a commit to rdblue/iceberg that referenced this pull request Sep 2, 2022
* Core: Fix exception handling in BaseTaskWriter.

* Fix state check.
rdblue added a commit to rdblue/iceberg that referenced this pull request Sep 2, 2022
* Core: Fix exception handling in BaseTaskWriter.

* Fix state check.
rdblue added a commit that referenced this pull request Sep 3, 2022
* Core: Fix exception handling in BaseTaskWriter.

* Fix state check.
sunchao pushed a commit to sunchao/iceberg that referenced this pull request May 10, 2023
* Core: Fix exception handling in BaseTaskWriter.

* Fix state check.
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.

2 participants