nsivabalan commented on code in PR #13126:
URL: https://github.com/apache/hudi/pull/13126#discussion_r2040873485


##########
hudi-aws/src/main/java/org/apache/hudi/aws/transaction/lock/S3StorageLockClient.java:
##########
@@ -226,25 +229,43 @@ private static Functions.Function2<String, Properties, 
S3Client> createDefaultS3
         requiredFallbackRegion = true;
       }
 
-      S3Client s3Client = S3Client.builder().credentialsProvider(
-              
HoodieAWSCredentialsProviderFactory.getAwsCredentialsProvider(props)).region(region).build();
+      // Set all request timeouts to be 1/5 of the default validity.
+      // Each call to acquire a lock requires 2 requests.
+      // Each renewal requires 1 request.
+      long defaultValiditySeconds = VALIDITY_TIMEOUT_SECONDS.defaultValue();
+      if (props.contains(VALIDITY_TIMEOUT_SECONDS.key())) {
+        defaultValiditySeconds = (long) 
props.get(VALIDITY_TIMEOUT_SECONDS.key());
+      }
+      long configuredS3TimeoutSeconds = defaultValiditySeconds / 5;
+      S3Client s3Client = createS3Client(region, configuredS3TimeoutSeconds, 
props);
       if (requiredFallbackRegion) {
         GetBucketLocationResponse bucketLocationResponse = 
s3Client.getBucketLocation(
                 GetBucketLocationRequest.builder().bucket(bucketName).build());
+        // This is null when the region is US_EAST_1, so we do not need to 
worry about duplicate logic.
         String regionString = 
bucketLocationResponse.locationConstraintAsString();
         if (!StringUtils.isNullOrEmpty(regionString)) {
           // Close existing client and create another.
           s3Client.close();
-          return S3Client.builder().credentialsProvider(
-                          
HoodieAWSCredentialsProviderFactory.getAwsCredentialsProvider(props))
-                          .region(Region.of(regionString)).build();
+          return createS3Client(
+                  Region.of(regionString),
+                  configuredS3TimeoutSeconds,
+                  props);
         }
       }
 
       return s3Client;
     };
   }
 
+  private static S3Client createS3Client(Region region, long timeout, 
Properties props) {

Review Comment:
   timeout -> timeoutSecs



##########
hudi-aws/src/main/java/org/apache/hudi/aws/transaction/lock/S3StorageLockClient.java:
##########
@@ -226,25 +229,43 @@ private static Functions.Function2<String, Properties, 
S3Client> createDefaultS3
         requiredFallbackRegion = true;
       }
 
-      S3Client s3Client = S3Client.builder().credentialsProvider(
-              
HoodieAWSCredentialsProviderFactory.getAwsCredentialsProvider(props)).region(region).build();
+      // Set all request timeouts to be 1/5 of the default validity.
+      // Each call to acquire a lock requires 2 requests.
+      // Each renewal requires 1 request.
+      long defaultValiditySeconds = VALIDITY_TIMEOUT_SECONDS.defaultValue();
+      if (props.contains(VALIDITY_TIMEOUT_SECONDS.key())) {
+        defaultValiditySeconds = (long) 
props.get(VALIDITY_TIMEOUT_SECONDS.key());

Review Comment:
   why can't we use props.getOrDefault. we could fold the 4 lines (234-238) 
into just 1 line. 



##########
hudi-aws/src/main/java/org/apache/hudi/aws/transaction/lock/S3StorageLockClient.java:
##########
@@ -226,25 +229,43 @@ private static Functions.Function2<String, Properties, 
S3Client> createDefaultS3
         requiredFallbackRegion = true;
       }
 
-      S3Client s3Client = S3Client.builder().credentialsProvider(
-              
HoodieAWSCredentialsProviderFactory.getAwsCredentialsProvider(props)).region(region).build();
+      // Set all request timeouts to be 1/5 of the default validity.
+      // Each call to acquire a lock requires 2 requests.
+      // Each renewal requires 1 request.
+      long defaultValiditySeconds = VALIDITY_TIMEOUT_SECONDS.defaultValue();
+      if (props.contains(VALIDITY_TIMEOUT_SECONDS.key())) {
+        defaultValiditySeconds = (long) 
props.get(VALIDITY_TIMEOUT_SECONDS.key());
+      }
+      long configuredS3TimeoutSeconds = defaultValiditySeconds / 5;

Review Comment:
   minor. for longer variables, you can use "secs" as unit. 
   also, we can just name the var as "s3CallTimeoutSecs" 



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