You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by dw...@apache.org on 2023/04/06 18:30:33 UTC
[iceberg] branch 1.2.x updated: AWS: Make AuthSession cache static (#7289)
This is an automated email from the ASF dual-hosted git repository.
dweeks pushed a commit to branch 1.2.x
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/1.2.x by this push:
new 4e2cdccd74 AWS: Make AuthSession cache static (#7289)
4e2cdccd74 is described below
commit 4e2cdccd7453603af42a090fc5530f2bd20cf1be
Author: Eduard Tudenhoefner <et...@gmail.com>
AuthorDate: Thu Apr 6 20:20:26 2023 +0200
AWS: Make AuthSession cache static (#7289)
Signer instances can be fairly short-lived, meaning that the
`AuthSession` cache doesn't get a chance to remove an `AuthSession` from
the cache and thus call `AuthSession#stopRefreshing()`.
---
.../aws/s3/signer/S3V4RestSignerClient.java | 48 ++++++++++++++--------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3V4RestSignerClient.java b/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3V4RestSignerClient.java
index a0920774af..6904492f03 100644
--- a/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3V4RestSignerClient.java
+++ b/aws/src/main/java/org/apache/iceberg/aws/s3/signer/S3V4RestSignerClient.java
@@ -80,6 +80,9 @@ public abstract class S3V4RestSignerClient
@SuppressWarnings("immutables:incompat")
private static volatile RESTClient httpClient;
+ @SuppressWarnings("immutables:incompat")
+ private static volatile Cache<String, AuthSession> authSessionCache;
+
public abstract Map<String, String> properties();
@Value.Default
@@ -135,24 +138,33 @@ public abstract class S3V4RestSignerClient
return tokenRefreshExecutor;
}
- @Value.Lazy
- Cache<String, AuthSession> authSessionCache() {
- long expirationIntervalMs =
- PropertyUtil.propertyAsLong(
- properties(),
- CatalogProperties.AUTH_SESSION_TIMEOUT_MS,
- CatalogProperties.AUTH_SESSION_TIMEOUT_MS_DEFAULT);
-
- return Caffeine.newBuilder()
- .expireAfterAccess(Duration.ofMillis(expirationIntervalMs))
- .removalListener(
- (RemovalListener<String, AuthSession>)
- (id, auth, cause) -> {
- if (null != auth) {
- auth.stopRefreshing();
- }
- })
- .build();
+ private Cache<String, AuthSession> authSessionCache() {
+ if (null == authSessionCache) {
+ synchronized (S3V4RestSignerClient.class) {
+ if (null == authSessionCache) {
+ long expirationIntervalMs =
+ PropertyUtil.propertyAsLong(
+ properties(),
+ CatalogProperties.AUTH_SESSION_TIMEOUT_MS,
+ CatalogProperties.AUTH_SESSION_TIMEOUT_MS_DEFAULT);
+
+ authSessionCache =
+ Caffeine.newBuilder()
+ .expireAfterAccess(Duration.ofMillis(expirationIntervalMs))
+ .removalListener(
+ (RemovalListener<String, AuthSession>)
+ (id, auth, cause) -> {
+ if (null != auth) {
+ LOG.trace("Stopping refresh for AuthSession");
+ auth.stopRefreshing();
+ }
+ })
+ .build();
+ }
+ }
+ }
+
+ return authSessionCache;
}
private RESTClient httpClient() {