diff --git a/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java b/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java index e00356a94742..41d45db357f1 100644 --- a/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java +++ b/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java @@ -434,9 +434,9 @@ private Map clientByPrefix() { if (null == clientByPrefix) { synchronized (this) { if (null == clientByPrefix) { - this.clientByPrefix = Maps.newHashMap(); + Map localClientByPrefix = Maps.newHashMap(); - clientByPrefix.put( + localClientByPrefix.put( ROOT_PREFIX, new PrefixedS3Client(ROOT_PREFIX, properties, s3, s3Async)); storageCredentials.stream() .filter(c -> c.prefix().startsWith(ROOT_PREFIX)) @@ -449,11 +449,12 @@ private Map clientByPrefix() { .putAll(storageCredential.config()) .buildKeepingLast(); - clientByPrefix.put( + localClientByPrefix.put( storageCredential.prefix(), new PrefixedS3Client( storageCredential.prefix(), propertiesWithCredentials, s3, s3Async)); }); + this.clientByPrefix = localClientByPrefix; } } } diff --git a/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java b/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java index 0c76d1258c16..c77e17ad0894 100644 --- a/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java +++ b/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java @@ -193,9 +193,9 @@ private Map storageByPrefix() { if (null == storageByPrefix) { synchronized (this) { if (null == storageByPrefix) { - this.storageByPrefix = Maps.newHashMap(); + Map localStorageByPrefix = Maps.newHashMap(); - storageByPrefix.put( + localStorageByPrefix.put( ROOT_STORAGE_PREFIX, new PrefixedStorage(ROOT_STORAGE_PREFIX, properties, storageSupplier)); storageCredentials.stream() @@ -209,13 +209,14 @@ private Map storageByPrefix() { .putAll(storageCredential.config()) .buildKeepingLast(); - storageByPrefix.put( + localStorageByPrefix.put( storageCredential.prefix(), new PrefixedStorage( storageCredential.prefix(), propertiesWithCredentials, storageSupplier)); }); + this.storageByPrefix = localStorageByPrefix; } } }