ajayvembu commented on code in PR #15869:
URL: https://github.com/apache/iceberg/pull/15869#discussion_r3164881738


##########
azure/src/main/java/org/apache/iceberg/azure/adlsv2/ADLSFileIO.java:
##########
@@ -259,11 +281,93 @@ public void deletePrefix(String prefix) {
   }
 
   @Override
-  public void close() {
-    if (vendedAdlsCredentialProvider != null) {
-      vendedAdlsCredentialProvider.close();
+  public void setCredentials(List<StorageCredential> credentials) {
+    Preconditions.checkArgument(credentials != null, "Invalid storage 
credentials: null");
+    // stop any refresh that might be scheduled
+    if (refreshFuture != null) {
+      refreshFuture.cancel(true);
+    }
+
+    // copy credentials into a modifiable collection for Kryo serde
+    this.storageCredentials = Lists.newArrayList(credentials);
+
+    // if the clients are already initialized, we need to allow them to be 
recreated
+    synchronized (this) {
+      if (clientCache != null) {
+        this.clientCache = null;
+      }
+    }
+  }
+
+  @Override
+  public List<StorageCredential> credentials() {
+    return ImmutableList.copyOf(storageCredentials);
+  }
+
+  private void scheduleCredentialRefresh() {
+    storageCredentials.stream()
+        .flatMap(cred -> cred.config().entrySet().stream())

Review Comment:
   Using flatMap and .startsWith() works, but it relies on a fuzzy match. If a 
future update introduces another configuration property that shares the same 
prefix (for example something like 
adls.sas-token-expires-at-ms-buffer.accountname), this filter can obtain more 
than 1 result. We could use credential prefix instead. 
   ```
     private void scheduleCredentialRefresh() {
       if (storageCredentials == null || storageCredentials.isEmpty()) {
         return;
       }
   
       storageCredentials.stream()
               .map(
                       cred ->
                               
cred.config().get(AzureProperties.ADLS_SAS_TOKEN_EXPIRES_AT_MS_PREFIX + 
cred.prefix()))
               .filter(Objects::nonNull)
               .map(expiresAtString -> 
java.time.Instant.ofEpochMilli(Long.parseLong(expiresAtString)))
               .min(Comparator.naturalOrder())
               .ifPresent(
                       expiresAt -> {
                         Instant prefetchAt = expiresAt.minus(5, 
java.time.temporal.ChronoUnit.MINUTES);
                         long delay = Duration.between(Instant.now(), 
prefetchAt).toMillis();
                         this.refreshFuture =
                                 
executorService().schedule(this::refreshStorageCredentials, delay, 
TimeUnit.MILLISECONDS);
                       });
     }
   ```
   



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