jackye1995 commented on code in PR #4695:
URL: https://github.com/apache/iceberg/pull/4695#discussion_r865459576


##########
aws/src/main/java/org/apache/iceberg/aws/lakeformation/LakeFormationAwsClientFactory.java:
##########
@@ -135,24 +141,57 @@ private LakeFormationClient lakeFormation() {
   static class LakeFormationCredentialsProvider implements 
AwsCredentialsProvider {
     private LakeFormationClient client;
     private String tableArn;
+    private final long expiryLeadTimeForRefreshInMins;
+
+    private LakeFormationTemporaryCredentials cachedCredentials;
+    private final Cache<String, LakeFormationTemporaryCredentials> cache;
 
     LakeFormationCredentialsProvider(LakeFormationClient lakeFormationClient, 
String tableArn) {
       this.client = lakeFormationClient;
       this.tableArn = tableArn;
+      this.expiryLeadTimeForRefreshInMins = 1;
+      this.cache = Caffeine.newBuilder()
+          .initialCapacity(1)
+          .recordStats()
+          .build();
     }
 
     @Override
     public AwsCredentials resolveCredentials() {
-      GetTemporaryGlueTableCredentialsRequest 
getTemporaryGlueTableCredentialsRequest =
-          GetTemporaryGlueTableCredentialsRequest.builder()
-              .tableArn(tableArn)
-              // Now only two permission types (COLUMN_PERMISSION and 
CELL_FILTER_PERMISSION) are supported
-              // and Iceberg only supports COLUMN_PERMISSION at this time
-              .supportedPermissionTypes(PermissionType.COLUMN_PERMISSION)
-              .build();
-      GetTemporaryGlueTableCredentialsResponse response =
-          
client.getTemporaryGlueTableCredentials(getTemporaryGlueTableCredentialsRequest);
-      return AwsSessionCredentials.create(response.accessKeyId(), 
response.secretAccessKey(), response.sessionToken());
+      LakeFormationTemporaryCredentials credentials = 
cache.getIfPresent(tableArn);
+      if (credentials != null && shouldRefresh(credentials)) {
+        cache.invalidate(tableArn);
+      }
+
+      credentials = cache.get(tableArn, key -> {
+        GetTemporaryGlueTableCredentialsRequest 
getTemporaryGlueTableCredentialsRequest =
+            GetTemporaryGlueTableCredentialsRequest.builder()
+                .tableArn(key)
+                // Now only two permission types (COLUMN_PERMISSION and 
CELL_FILTER_PERMISSION) are supported
+                // and Iceberg only supports COLUMN_PERMISSION at this time
+                .supportedPermissionTypes(PermissionType.COLUMN_PERMISSION)
+                .build();
+        GetTemporaryGlueTableCredentialsResponse response =
+            
client.getTemporaryGlueTableCredentials(getTemporaryGlueTableCredentialsRequest);
+
+        AwsSessionCredentials awsSessionCredentials = 
AwsSessionCredentials.create(response.accessKeyId(),

Review Comment:
   nit: newline after `create(`



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