gaborgsomogyi commented on code in PR #28136:
URL: https://github.com/apache/flink/pull/28136#discussion_r3534545214


##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3ClientProvider.java:
##########
@@ -295,17 +365,21 @@ public CompletableFuture<Void> closeAsync() {
                             } catch (Exception e) {
                                 LOG.warn("Error closing S3 TransferManager", 
e);
                             }
+                            try {
+                                asyncClient.close();
+                            } catch (Exception e) {
+                                LOG.warn("Error closing S3 async client", e);
+                            }
                             try {
                                 s3Client.close();
                             } catch (Exception e) {
                                 LOG.warn("Error closing S3 sync client", e);
                             }
-                            if (getCredentialsProvider() instanceof 
SdkAutoCloseable) {
-                                try {
-                                    ((SdkAutoCloseable) 
getCredentialsProvider()).close();
-                                } catch (Exception e) {
-                                    LOG.warn("Error closing credentials 
provider", e);
-                                }
+                            closeCredentialsProviderQuietly(
+                                    credentialsProvider, "credentials 
provider");
+                            if (baseCredentialsProvider != 
credentialsProvider) {
+                                closeCredentialsProviderQuietly(
+                                        baseCredentialsProvider, "base 
credentials provider");

Review Comment:
   Not yet understand this construct. I was thinking why we need 2 pointers and 
thought maybe later I can find this out from code. All of a suddend it has 
turned out that the the 2 can hold the same value, why? Unless there is a 
pretty good reason we should have a single credentials proider.



##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3ClientProvider.java:
##########
@@ -329,6 +406,24 @@ private void checkNotClosed() {
         }
     }
 
+    private static void closeQuietly(@Nullable AutoCloseable closeable, String 
resourceName) {
+        if (closeable == null) {
+            return;
+        }
+        try {
+            closeable.close();
+        } catch (Exception closeError) {
+            LOG.warn("Error closing {}", resourceName, closeError);
+        }
+    }
+
+    private static void closeCredentialsProviderQuietly(
+            @Nullable AwsCredentialsProvider credentialsProvider, String 
resourceName) {
+        if (credentialsProvider instanceof SdkAutoCloseable) {

Review Comment:
   When I see `instanceof` I'm always questioning why. What is the lifecycle 
here?



##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/NativeS3FileIoUtilsTest.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.fs.s3native;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.io.ByteArrayInputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link NativeS3FileIoUtils}. */
+class NativeS3FileIoUtilsTest {
+
+    @ParameterizedTest
+    @CsvSource({"1", "7", "1024", "262144"})
+    void testCopyStreamPreservesContentAcrossBufferSizes(int bufferSize, 
@TempDir Path tempDir)
+            throws Exception {
+        byte[] data = new byte[100_000];

Review Comment:
   Do we need 100kB data or just claude random idea?



##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3ClientProvider.java:
##########
@@ -587,69 +903,66 @@ S3ClientProvider build() {
                                             
.connectionAcquisitionTimeout(connectionTimeout))
                             .overrideConfiguration(overrideConfig);
             if (endpointUri != null) {
-                asyncClientBuilder.endpointOverride(endpointUri);
+                asyncBuilder.endpointOverride(endpointUri);
             }
-            S3TransferManager transferManager =
-                    
S3TransferManager.builder().s3Client(asyncClientBuilder.build()).build();
-
-            return new S3ClientProvider(
-                    s3Client,
-                    transferManager,
-                    encryptionConfig,
-                    credentialsProvider,
-                    stsClient,
-                    clientCloseTimeout,
-                    connectionTimeout,
-                    socketTimeout,
-                    connectionMaxIdleTime,
-                    pathStyleAccess,
-                    chunkedEncoding,
-                    checksumValidation,
-                    maxConnections,
-                    maxRetries,
-                    retryBaseDelay,
-                    retryThrottleBaseDelay,
-                    retryMaxBackoff,
-                    region,
-                    endpoint,
-                    assumeRoleArn,
-                    assumeRoleExternalId,
-                    assumeRoleSessionName,
-                    assumeRoleSessionDurationSeconds);
+            return asyncBuilder.build();
+        }
+
+        private static boolean isCrtClasspathFailure(IllegalStateException e) {
+            String message = e.getMessage();
+            return message != null
+                    && (message.contains("AWS Common Runtime")
+                            || message.contains("software.amazon.awssdk.crt"));
+        }
+
+        @VisibleForTesting
+        static String crtMissingJarsMessage() {
+            return "CRT transport requested (s3.crt.enabled=true) but the 
aws-crt JAR "
+                    + "is not on the classpath. Place it in the Flink plugin 
directory "
+                    + "(e.g. $FLINK_HOME/plugins/s3-fs-native/) alongside 
flink-s3-fs-native.jar. "
+                    + "Run tools/download-crt-jars.sh to download the matching 
version. "
+                    + "See the module README for setup details.";
         }
 
         private AwsCredentialsProvider buildBaseCredentialsProvider() {

Review Comment:
   Why CRT requires any credential change?



##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3ClientProvider.java:
##########
@@ -329,6 +406,24 @@ private void checkNotClosed() {
         }
     }
 
+    private static void closeQuietly(@Nullable AutoCloseable closeable, String 
resourceName) {

Review Comment:
   `AutoCloseable` are normally closed with try-with-resources, is this 
something special?



-- 
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]

Reply via email to