Skip to content

Commit 0eb9728

Browse files
AWS, GCP: Fix double-checked-locking pattern in S3FileIO, GCSFileIO. (#13276)
1 parent 68651a3 commit 0eb9728

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ private Map<String, PrefixedS3Client> clientByPrefix() {
434434
if (null == clientByPrefix) {
435435
synchronized (this) {
436436
if (null == clientByPrefix) {
437-
this.clientByPrefix = Maps.newHashMap();
437+
Map<String, PrefixedS3Client> localClientByPrefix = Maps.newHashMap();
438438

439-
clientByPrefix.put(
439+
localClientByPrefix.put(
440440
ROOT_PREFIX, new PrefixedS3Client(ROOT_PREFIX, properties, s3, s3Async));
441441
storageCredentials.stream()
442442
.filter(c -> c.prefix().startsWith(ROOT_PREFIX))
@@ -449,11 +449,12 @@ private Map<String, PrefixedS3Client> clientByPrefix() {
449449
.putAll(storageCredential.config())
450450
.buildKeepingLast();
451451

452-
clientByPrefix.put(
452+
localClientByPrefix.put(
453453
storageCredential.prefix(),
454454
new PrefixedS3Client(
455455
storageCredential.prefix(), propertiesWithCredentials, s3, s3Async));
456456
});
457+
this.clientByPrefix = localClientByPrefix;
457458
}
458459
}
459460
}

gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ private Map<String, PrefixedStorage> storageByPrefix() {
193193
if (null == storageByPrefix) {
194194
synchronized (this) {
195195
if (null == storageByPrefix) {
196-
this.storageByPrefix = Maps.newHashMap();
196+
Map<String, PrefixedStorage> localStorageByPrefix = Maps.newHashMap();
197197

198-
storageByPrefix.put(
198+
localStorageByPrefix.put(
199199
ROOT_STORAGE_PREFIX,
200200
new PrefixedStorage(ROOT_STORAGE_PREFIX, properties, storageSupplier));
201201
storageCredentials.stream()
@@ -209,13 +209,14 @@ private Map<String, PrefixedStorage> storageByPrefix() {
209209
.putAll(storageCredential.config())
210210
.buildKeepingLast();
211211

212-
storageByPrefix.put(
212+
localStorageByPrefix.put(
213213
storageCredential.prefix(),
214214
new PrefixedStorage(
215215
storageCredential.prefix(),
216216
propertiesWithCredentials,
217217
storageSupplier));
218218
});
219+
this.storageByPrefix = localStorageByPrefix;
219220
}
220221
}
221222
}

0 commit comments

Comments
 (0)