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 2022/06/03 22:48:51 UTC

[iceberg] branch master updated: Use CatalogUtil classloader instead of context classloader for FileIO (#4957)

This is an automated email from the ASF dual-hosted git repository.

dweeks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 980b51587 Use CatalogUtil classloader instead of context classloader for FileIO (#4957)
980b51587 is described below

commit 980b515875679d5aa01a50802129fafa554340a4
Author: Daniel Weeks <dw...@apache.org>
AuthorDate: Fri Jun 3 15:48:47 2022 -0700

    Use CatalogUtil classloader instead of context classloader for FileIO (#4957)
    
    * Use CatalogUtil classloader instead of context classloader for FileIO
    
    * Use AwsClientFactories classloader for loading custom client factory
    
    * Set classloader for S3FileIO metrics dynamic loading
---
 aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java | 6 +++++-
 aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java        | 5 ++++-
 core/src/main/java/org/apache/iceberg/CatalogUtil.java           | 6 ++++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java b/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java
index 4dd543b22..f264dda41 100644
--- a/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java
+++ b/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java
@@ -60,7 +60,11 @@ public class AwsClientFactories {
   private static AwsClientFactory loadClientFactory(String impl, Map<String, String> properties) {
     DynConstructors.Ctor<AwsClientFactory> ctor;
     try {
-      ctor = DynConstructors.builder(AwsClientFactory.class).hiddenImpl(impl).buildChecked();
+      ctor =
+          DynConstructors.builder(AwsClientFactory.class)
+              .loader(AwsClientFactories.class.getClassLoader())
+              .hiddenImpl(impl)
+              .buildChecked();
     } catch (NoSuchMethodException e) {
       throw new IllegalArgumentException(String.format(
           "Cannot initialize AwsClientFactory, missing no-arg constructor: %s", impl), e);
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 3a92bf877..3f669a3b6 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
@@ -286,7 +286,10 @@ public class S3FileIO implements FileIO, SupportsBulkOperations, CredentialSuppl
     // Report Hadoop metrics if Hadoop is available
     try {
       DynConstructors.Ctor<MetricsContext> ctor =
-          DynConstructors.builder(MetricsContext.class).hiddenImpl(DEFAULT_METRICS_IMPL, String.class).buildChecked();
+          DynConstructors.builder(MetricsContext.class)
+              .loader(S3FileIO.class.getClassLoader())
+              .hiddenImpl(DEFAULT_METRICS_IMPL, String.class)
+              .buildChecked();
       MetricsContext context = ctor.newInstance("s3");
       context.initialize(properties);
       this.metrics = context;
diff --git a/core/src/main/java/org/apache/iceberg/CatalogUtil.java b/core/src/main/java/org/apache/iceberg/CatalogUtil.java
index 203da2992..b837b0cfb 100644
--- a/core/src/main/java/org/apache/iceberg/CatalogUtil.java
+++ b/core/src/main/java/org/apache/iceberg/CatalogUtil.java
@@ -245,11 +245,12 @@ public class CatalogUtil {
    * {@link FileIO#initialize(Map properties)} is called to complete the initialization.
    *
    * @param impl full class name of a custom FileIO implementation
+   * @param properties used to initialize the FileIO implementation
    * @param hadoopConf a hadoop Configuration
    * @return FileIO class
    * @throws IllegalArgumentException if class path not found or
    *  right constructor not found or
-   *  the loaded class cannot be casted to the given interface type
+   *  the loaded class cannot be cast to the given interface type
    */
   public static FileIO loadFileIO(
       String impl,
@@ -258,7 +259,8 @@ public class CatalogUtil {
     LOG.info("Loading custom FileIO implementation: {}", impl);
     DynConstructors.Ctor<FileIO> ctor;
     try {
-      ctor = DynConstructors.builder(FileIO.class).impl(impl).buildChecked();
+      ctor =
+          DynConstructors.builder(FileIO.class).loader(CatalogUtil.class.getClassLoader()).impl(impl).buildChecked();
     } catch (NoSuchMethodException e) {
       throw new IllegalArgumentException(String.format(
           "Cannot initialize FileIO, missing no-arg constructor: %s", impl), e);