Samrat002 commented on code in PR #29890:
URL: https://github.com/apache/flink/pull/29890#discussion_r4657254840
##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/writer/NativeS3RecoverableFsDataOutputStreamTest.java:
##########
@@ -216,10 +233,206 @@ protected void deleteTempFile(File file) throws
IOException {
assertThat(countLocalFilesIn(dir)).isZero();
}
+ @Test
+ void partUploadsRunConcurrentlyUpToTheLimit() throws Exception {
+ s3.uploadPartGate = new CountDownLatch(1);
+ NativeS3RecoverableFsDataOutputStream asyncStream =
+ newAsyncStream(tmp.resolve("concurrent"), 2);
+
+ asyncStream.write(bytes('A', 10), 0, 10);
+ asyncStream.write(bytes('B', 10), 0, 10);
+ // Both writes returned while their parts are still being uploaded.
+ waitUntilCondition(() -> s3.inFlightUploads.get() == 2);
+
+ CheckedThread thirdPart =
+ new CheckedThread() {
+ @Override
+ public void go() throws Exception {
+ asyncStream.write(bytes('C', 10), 0, 10);
+ }
+ };
+ thirdPart.start();
+ // The third part has to wait for a free upload slot.
+ waitUntilCondition(() -> thirdPart.getState() == Thread.State.WAITING);
+ assertThat(s3.inFlightUploads).hasValue(2);
+
+ s3.uploadPartGate.countDown();
+ thirdPart.sync();
+ asyncStream.closeForCommit().commit();
+
+ assertThat(s3.maxInFlightUploads).hasValue(2);
+ assertThat(s3.committedObjects.get(KEY))
+ .containsExactly(concat(bytes('A', 10), bytes('B', 10),
bytes('C', 10)));
+ }
+
+ @Test
+ void persistWaitsForInFlightPartUploads() throws Exception {
+ s3.uploadPartGate = new CountDownLatch(1);
+ NativeS3RecoverableFsDataOutputStream asyncStream =
+ newAsyncStream(tmp.resolve("persist"), 2);
+ asyncStream.write(bytes('A', 10), 0, 10);
+ asyncStream.write(bytes('B', 3), 0, 3);
+
+ NativeS3Recoverable[] recoverable = new NativeS3Recoverable[1];
+ CheckedThread persisting =
+ new CheckedThread() {
+ @Override
+ public void go() throws Exception {
+ recoverable[0] = (NativeS3Recoverable)
asyncStream.persist();
+ }
+ };
+ persisting.start();
+ waitUntilCondition(() -> persisting.getState() ==
Thread.State.WAITING);
+ assertThat(s3.objects).as("the tail is stored after the parts are
uploaded").isEmpty();
+
+ s3.uploadPartGate.countDown();
+ persisting.sync();
+
+ assertThat(recoverable[0].parts()).hasSize(1);
+ assertThat(recoverable[0].numBytesInParts()).isEqualTo(10L);
+ assertThat(recoverable[0].incompleteObjectLength()).isEqualTo(3L);
+ assertThat(asyncStream.getPos()).isEqualTo(13L);
+ asyncStream.close();
+ }
+
+ @Test
+ void asyncPartUploadFailureSurfacesOnPersistAndBreaksTheStream() throws
Exception {
+ s3.uploadPartGate = new CountDownLatch(1);
+ s3.failUploadPart = true;
+ Path dir = tmp.resolve("async-failure");
+ NativeS3RecoverableFsDataOutputStream asyncStream =
newAsyncStream(dir, 2);
+
+ // The write does not wait for the part upload, so it cannot see its
failure.
+ asyncStream.write(bytes('A', 10), 0, 10);
+ s3.uploadPartGate.countDown();
+
+ assertThatThrownBy(asyncStream::persist)
+ .isInstanceOf(IOException.class)
+ .hasStackTraceContaining("Failed to upload part 1")
+ .hasRootCauseMessage("injected uploadPart failure for
uploadId: U2");
+ assertThatThrownBy(() -> asyncStream.write(bytes('B', 1), 0, 1))
+ .isInstanceOf(IOException.class)
+ .hasMessageContaining("must be recovered from the last
checkpoint");
+ assertThatThrownBy(asyncStream::closeForCommit)
+ .isInstanceOf(IOException.class)
+ .hasMessageContaining("must be recovered from the last
checkpoint");
+
+ assertThat(s3.abortAttempts).isZero();
+ assertThat(countLocalFilesIn(dir)).as("the failed part's temp file is
deleted").isZero();
+ }
+
+ @Test
+ void partUploadFailureStopsWritesWhileEarlierPartsAreInFlight() throws
Exception {
+ s3.uploadPartGate = new CountDownLatch(1);
+ s3.failingPartNumber = 2;
+ Path dir = tmp.resolve("out-of-order-failure");
+ NativeS3RecoverableFsDataOutputStream asyncStream =
newAsyncStream(dir, 3);
+
+ asyncStream.write(bytes('A', 10), 0, 10);
+ asyncStream.write(bytes('B', 10), 0, 10);
Review Comment:
possible but a very rare flaky senerio
--
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]