danielcweeks commented on code in PR #15678:
URL: https://github.com/apache/iceberg/pull/15678#discussion_r2961353185


##########
aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java:
##########
@@ -419,22 +426,65 @@ private Map<String, PrefixedS3Client> clientByPrefix() {
                         new PrefixedS3Client(
                             storageCredential.prefix(), 
propertiesWithCredentials, s3, s3Async));
                   });
+
           this.clientByPrefix = localClientByPrefix;
+          // Note: the s3 clients separately refresh via the 
VendedCredentialsProvider but are
+          //       not directly referencable from the FileIO
+          scheduleCredentialRefresh();
         }
       }
     }
 
     return clientByPrefix;
   }
 
-  private ExecutorService executorService() {
+  private void scheduleCredentialRefresh() {
+    storageCredentials.stream()
+        .map(
+            storageCredential ->
+                
storageCredential.config().get(S3FileIOProperties.SESSION_TOKEN_EXPIRES_AT_MS))
+        .filter(Objects::nonNull)
+        .map(expiresAtString -> 
Instant.ofEpochMilli(Long.parseLong(expiresAtString)))
+        .min(Comparator.naturalOrder())
+        .ifPresent(
+            expiresAt -> {
+              Instant prefetchAt = expiresAt.minus(5, ChronoUnit.MINUTES);
+              long delay = Duration.between(Instant.now(), 
prefetchAt).toMillis();
+              this.refreshFuture =
+                  executorService()
+                      .schedule(this::refreshStorageCredentials, delay, 
TimeUnit.MILLISECONDS);
+            });
+  }

Review Comment:
   The updates based on Eduard's suggestion allows us to reuse the same code 
path.  Relying on the AwsCredential refresh isn't sufficient because it both 
has a different representation (`AwsCredentials` vs `StorageCredential`) and it 
only contains one of the credentials if there are multiple.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to