gaborgsomogyi commented on code in PR #29890:
URL: https://github.com/apache/flink/pull/29890#discussion_r4678510504
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/writer/NativeS3RecoverableFsDataOutputStream.java:
##########
@@ -180,41 +209,153 @@ public void write(byte[] b, int off, int len) throws
IOException {
if (currentPartSize >= minPartSize) {
uploadCurrentPart();
- createNewTempFile();
+ startNewPart();
}
}
@Override
public void flush() throws IOException {
- if (closed) {
- throw new IOException("Stream is closed");
- }
+ checkUsable();
currentOutputStream.flush();
}
@Override
public void sync() throws IOException {
+ checkUsable();
+ persist();
+ }
+
+ private void checkUsable() throws IOException {
if (closed) {
throw new IOException("Stream is closed");
}
- persist();
+ final IOException failure = uploadFailure.get();
+ if (failure != null) {
+ // Rethrown as it is, so that the task handles a fatal error or an
OutOfMemoryError
+ // of an upload thread like one of its own thread, e.g. by
terminating the JVM.
+ ExceptionUtils.rethrowIfFatalErrorOrOOM(failure.getCause());
+ throw new IOException(
+ "A part upload of this stream failed. The stream cannot be
used anymore and "
+ + "must be recovered from the last checkpoint.",
+ failure);
+ }
}
private void uploadCurrentPart() throws IOException {
- currentOutputStream.close();
+ final PendingPartUpload upload;
+ lock();
+ try {
+ // close() may have run concurrently and released the buffer.
+ checkUsable();
+ currentOutputStream.close();
+
+ upload = new PendingPartUpload(nextPartNumber, currentTempFile,
currentPartSize);
+ pendingUploads.addLast(upload);
+ nextPartNumber++;
+ numBytesInParts += currentPartSize;
+ currentOutputStream = null;
+ currentFileStream = null;
+ currentTempFile = null;
+ currentPartSize = 0;
+ } finally {
+ unlock();
+ }
- // Do not delete the temp file if uploadPart fails: propagate the
original exception
- // unmasked and let the cleanup path (close() or the closeForCommit()
failure handler)
- // delete it. nextPartNumber is only advanced on success.
- NativeS3ObjectOperations.UploadPartResult result =
- s3AccessHelper.uploadPart(
- key, uploadId, nextPartNumber, currentTempFile,
currentPartSize);
+ // Blocks while the maximum number of uploads is in flight. Called
from write(), this does
+ // not hold the lock, so close() is not blocked by back-pressure.
+ try {
+ uploadExecutor.execute(() -> uploadPart(upload));
+ } catch (Throwable t) {
+ // E.g. a RejectedExecutionException once the file system is
closed, or an
+ // OutOfMemoryError if no thread can be created.
+ final IOException failure = failUpload(upload, t);
+ ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
+ throw failure;
+ }
+ completeFinishedUploads();
+ }
- nextPartNumber++;
- completedParts.add(new PartETag(result.getPartNumber(),
result.getETag()));
- numBytesInParts += currentPartSize;
+ private void startNewPart() throws IOException {
Review Comment:
If this fails after the part was handed over (interrupt, disk), the stream
has no buffer but still looks usable. The next `write`, `persist` or
`closeForCommit` throws an NPE instead of a clear `IOException`. Can we fail
the stream here, like for a failed upload?
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/writer/NativeS3RecoverableFsDataOutputStream.java:
##########
@@ -327,6 +476,15 @@ private void releaseLocalResources() throws IOException {
collected = ExceptionUtils.firstOrSuppressed(e, collected);
}
}
+ for (PendingPartUpload upload : pendingUploads) {
+ // join() is not interruptible, and handle() turns a failed upload
into a result.
+ upload.future.handle((ignored, error) -> null).join();
Review Comment:
`close()` waits for in-flight uploads and silently drops their errors. If S3
is failing and the task is cancelled while `persist()` waits, the S3 error is
never reported, only the interrupt. Can we log it here at WARN?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]