Skip to content

Commit

Permalink
Integrations: Fix FileIO client initialization thread safety (apache#…
Browse files Browse the repository at this point in the history
…4461)

Co-authored-by: Prashant Singh <[email protected]>
  • Loading branch information
singhpk234 and Prashant Singh authored Apr 3, 2022
1 parent 7ac5061 commit c34c505
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class OSSFileIO implements FileIO {

private SerializableSupplier<OSS> oss;
private AliyunProperties aliyunProperties;
private transient OSS client;
private transient volatile OSS client;
private MetricsContext metrics = MetricsContext.nullMetrics();
private final AtomicBoolean isResourceClosed = new AtomicBoolean(false);

Expand Down Expand Up @@ -89,7 +89,11 @@ public void deleteFile(String path) {

private OSS client() {
if (client == null) {
client = oss.get();
synchronized (this) {
if (client == null) {
client = oss.get();
}
}
}
return client;
}
Expand Down
8 changes: 6 additions & 2 deletions dell/src/main/java/org/apache/iceberg/dell/ecs/EcsFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class EcsFileIO implements FileIO {
private SerializableSupplier<S3Client> s3;
private DellProperties dellProperties;
private DellClientFactory dellClientFactory;
private transient S3Client client;
private transient volatile S3Client client;
private final AtomicBoolean isResourceClosed = new AtomicBoolean(false);

@Override
Expand All @@ -64,7 +64,11 @@ public void deleteFile(String path) {

private S3Client client() {
if (client == null) {
client = s3.get();
synchronized (this) {
if (client == null) {
client = s3.get();
}
}
}
return client;
}
Expand Down
8 changes: 6 additions & 2 deletions gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class GCSFileIO implements FileIO {

private SerializableSupplier<Storage> storageSupplier;
private GCPProperties gcpProperties;
private transient Storage storage;
private transient volatile Storage storage;
private MetricsContext metrics = MetricsContext.nullMetrics();
private final AtomicBoolean isResourceClosed = new AtomicBoolean(false);

Expand Down Expand Up @@ -96,7 +96,11 @@ public void deleteFile(String path) {

private Storage client() {
if (storage == null) {
storage = storageSupplier.get();
synchronized (this) {
if (storage == null) {
storage = storageSupplier.get();
}
}
}
return storage;
}
Expand Down

0 comments on commit c34c505

Please sign in to comment.