MartijnVisser commented on code in PR #29890:
URL: https://github.com/apache/flink/pull/29890#discussion_r4666375689
##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/writer/NativeS3RecoverableWriterTest.java:
##########
@@ -182,6 +196,72 @@ void upgradeFromRelease23Checkpoint() throws Exception {
assertThat(s3.committedObjects.get(KEY)).isEqualTo(ascii("AAAAABBBC"));
}
+ @Test
+ void maxConcurrentUploadsAppliesPerStream() throws Exception {
+ s3.uploadPartGate = new CountDownLatch(1);
+ final NativeS3RecoverableWriter writer =
+ NativeS3RecoverableWriter.writer(
+ s3, UPLOAD_POOL.getExecutor(), tmp.toString(),
MIN_PART_SIZE, 2);
+ final RecoverableFsDataOutputStream first =
writer.open(targetPath("dir/first"));
+ final RecoverableFsDataOutputStream second =
writer.open(targetPath("dir/second"));
+
+ for (RecoverableFsDataOutputStream stream :
+ new RecoverableFsDataOutputStream[] {first, second}) {
+ stream.write(ascii("AAAAAAAAAA"), 0, 10);
+ stream.write(ascii("BBBBBBBBBB"), 0, 10);
+ }
+ waitUntilCondition(() -> s3.inFlightUploads.get() == 4);
Review Comment:
This also passes when `limitedExecutor()` returns the pool itself, so no
test covers the per-stream limit from the ticket. A third part per stream that
has to wait would.
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystem.java:
##########
@@ -543,7 +552,37 @@ public RecoverableWriter createRecoverableWriter() throws
IOException {
throw new UnsupportedOperationException("Recoverable writer not
available");
}
return NativeS3RecoverableWriter.writer(
- s3AccessHelper, localTmpDir, s3uploadPartSize,
maxConcurrentUploadsPerStream);
+ s3AccessHelper,
+ uploadThreadPool,
+ localTmpDir,
+ s3uploadPartSize,
+ maxConcurrentUploadsPerStream);
+ }
+
+ /**
+ * Creates the pool for the part uploads of the recoverable writer. Its
threads are started by
+ * the task threads that write to the streams and would inherit their
context class loader,
+ * which is the user code class loader of the job. The pool lives as long
as the file system,
+ * which outlives the job, so its threads use the class loader of the file
system instead.
+ * Otherwise they would keep the class loader of a finished job reachable.
+ */
+ @VisibleForTesting
+ static ExecutorService createUploadThreadPool() {
+ final ThreadFactory threadFactory =
+ new ExecutorThreadFactory(
+ "s3-native-part-upload",
+ (thread, error) ->
+ LOG.error(
+ "Uncaught exception in S3 part upload
thread {}",
+ thread.getName(),
+ error));
+ final ClassLoader classLoader =
NativeS3FileSystem.class.getClassLoader();
+ return Executors.newCachedThreadPool(
Review Comment:
I think this pool needs a bound below `s3.connection.max`: with 8 streams x
8 uploads on 2 connections, parts waited in the SDK pool and failed with
`ConnectionPoolTimeoutException`. A fixed pool queued them instead.
--
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]