yabola commented on code in PR #14150: URL: https://github.com/apache/iceberg/pull/14150#discussion_r2368449117
########## core/src/main/java/org/apache/iceberg/util/IsolatedClassLoader.java: ########## @@ -0,0 +1,305 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.util; + +import java.io.Closeable; +import java.io.File; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.commons.io.IOUtils; +import org.apache.iceberg.relocated.com.google.common.base.Splitter; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * IsolatedClassLoader provides a mechanism for creating an isolated class loader that allows + * controlled loading of classes from specified jars and shared classes from the base class loader. + */ +public class IsolatedClassLoader implements Closeable { Review Comment: The approach is the same: when executing a Hive-related class (etc. `Hivecatalog` , `HiveClientPool`), the thread class loader is set to the `URLClassLoader` (containing the Hive library). After execution, the class loader is set back to the original class loader. For the code, refer to [Gravitino IsolatedClientLoader.scala](https://github.com/apache/gravitino/blob/4e802751e670a715be88c3a0e2173bb0d4ec31d8/core/src/main/java/org/apache/gravitino/utils/IsolatedClassLoader.java#L180-L208) . Gravitino also uses a similar approach to Spark, but with some abstraction. refer to [spark isolateclassloader](https://github.com/apache/spark/blob/ed2692fe885c7f160feacfd7ffed7ffa806359d0/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/IsolatedClientLoader.scala#L252-L276) Here are two key methods below: `isBarrierClass`: In Iceberg, all classes that reference the Hive (`org.apache.hadoop.hive.*`, for example `HiveCatalog`, `HiveTableOperations` ) must be loaded by an isolate class loader (instead of the app classloader). This requirement is due to the way JVM selects the classloader for creating objects, which is determined by the classloader of the current class. Iceberg encapsulates this such that all places referencing the Hive package are contained within the `hive-metastore` package (class all start with `org.apache.iceberg.hive.*`). These classes are loaded from bytes[] in JVM resource (Hive lib package doesn't contain these classes). `isSharedClass` (mainly based on Spark configuration): Other classes referenced by iceberg when performing other operations are loaded using the app class loader (same as all other classes. When possible, try not to use an isolate class loader for loading these classes). Other Classes: These are generally Hive related processing classes and will load by the isolate classloader. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org