diqiu50 commented on code in PR #9416: URL: https://github.com/apache/gravitino/pull/9416#discussion_r2602734530
########## catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/client/HiveClientFactory.java: ########## @@ -0,0 +1,192 @@ +/* + * 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.gravitino.hive.client; + +import static org.apache.gravitino.catalog.hive.HiveConstants.HIVE_METASTORE_URIS; +import static org.apache.gravitino.hive.client.HiveClientClassLoader.HiveVersion.HIVE2; +import static org.apache.gravitino.hive.client.HiveClientClassLoader.HiveVersion.HIVE3; +import static org.apache.gravitino.hive.client.Util.buildConfigurationFromProperties; + +import com.google.common.base.Preconditions; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Properties; +import org.apache.gravitino.exceptions.GravitinoRuntimeException; +import org.apache.gravitino.utils.PrincipalUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class HiveClientFactory { + private static final Logger LOG = LoggerFactory.getLogger(HiveClientFactory.class); + + // Remember which Hive backend version worked successfully for this factory. + private volatile HiveClientClassLoader.HiveVersion backendVersion; + private volatile HiveClientClassLoader backendClassLoader; + + @SuppressWarnings("UnusedVariable") + private final Configuration hadoopConf; + + private final Properties properties; + + /** + * Creates a {@link HiveClientFactory} bound to the given configuration properties. + * + * @param properties Hive client configuration, must not be null. + * @param id An identifier for this factory instance. + */ + public HiveClientFactory(Properties properties, String id) { + Preconditions.checkArgument(properties != null, "Properties cannot be null"); + this.properties = properties; + + try { + this.hadoopConf = buildConfigurationFromProperties(properties); + } catch (Exception e) { + throw new RuntimeException("Failed to initialize HiveClientFactory", e); + } + } + + public HiveClient createHiveClient() { + HiveClient client = null; + try { + if (backendVersion != null) { + HiveClientClassLoader classLoader = getOrCreateClassLoader(backendVersion); Review Comment: No, the life cycle is belong to HiveCatalogFactory, close the class loader on the HiveCatalogFactory closed -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
