Copilot commented on code in PR #11901: URL: https://github.com/apache/gravitino/pull/11901#discussion_r3526120921
########## iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ClosableJdbcCatalog.java: ########## @@ -0,0 +1,163 @@ +/* + * 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.iceberg.common; + +import com.google.common.base.Preconditions; +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.security.PrivilegedExceptionAction; +import java.util.Map; +import java.util.function.Function; +import org.apache.gravitino.catalog.hadoop.auth.KerberosAuthUtils; +import org.apache.gravitino.catalog.hadoop.auth.KerberosClient; +import org.apache.gravitino.iceberg.common.authentication.AuthenticationConfig; +import org.apache.gravitino.iceberg.common.authentication.SupportsKerberos; +import org.apache.gravitino.iceberg.common.authentication.kerberos.KerberosConfig; +import org.apache.gravitino.utils.PrincipalUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.jdbc.JdbcCatalog; +import org.apache.iceberg.jdbc.JdbcClientPool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ClosableJdbcCatalog is a wrapper class to wrap Iceberg JdbcCatalog to do some clean-up work like + * closing resources and supporting Kerberos authentication for HDFS access. + */ +public class ClosableJdbcCatalog extends JdbcCatalog implements Closeable, SupportsKerberos { + + private static final Logger LOGGER = LoggerFactory.getLogger(ClosableJdbcCatalog.class); + + private KerberosClient kerberosClient; + + private Configuration hadoopConf; + + public ClosableJdbcCatalog() { + super(); + } + + public ClosableJdbcCatalog( + Function<Map<String, String>, FileIO> ioBuilder, + Function<Map<String, String>, JdbcClientPool> clientPoolBuilder, + boolean initializeCatalogTables) { + super(ioBuilder, clientPoolBuilder, initializeCatalogTables); + } + + /** + * Initialize the ClosableJdbcCatalog with the given input name and properties. + * + * <p>Note: This method can only be called once as it will create new client pools. + * + * @param inputName name of the catalog + * @param properties properties for the catalog + */ + @Override + public void initialize(String inputName, Map<String, String> properties) { + super.initialize(inputName, properties); + + AuthenticationConfig authenticationConfig = new AuthenticationConfig(properties); + if (authenticationConfig.isKerberosAuth()) { + this.kerberosClient = initKerberosClient(); + } + } + + /** Returns the Hadoop configuration used for Kerberos login and HDFS access. */ + public Configuration getHadoopConf() { + return hadoopConf; + } + + /** Sets the Hadoop configuration used for Kerberos login and HDFS access. */ + public void setHadoopConf(Configuration hadoopConf) { + this.hadoopConf = hadoopConf; + } + + @Override + public void close() { + if (kerberosClient != null) { + try { + kerberosClient.close(); + } catch (Exception e) { + LOGGER.warn("Failed to close KerberosClient", e); + } + } + } Review Comment: ClosableJdbcCatalog.close() only closes the KerberosClient but does not close the underlying Iceberg JdbcCatalog resources (e.g., the JdbcClientPool). IcebergCatalogWrapper relies on JdbcCatalog being AutoCloseable for cleanup; overriding close without calling super.close() can leak JDBC connections/threads. ########## docs/lakehouse-iceberg-catalog.md: ########## @@ -228,11 +228,11 @@ Please set the `warehouse` parameter to `{storage_prefix}://{bucket_name}/${pref #### Catalog Backend Security -Users can use the following properties to configure the security of the catalog backend if needed. For example, if you are using a Kerberos Hive catalog backend, you must set `authentication.type` to `Kerberos` and provide `authentication.kerberos.principal` and `authentication.kerberos.keytab-uri`. +Users can use the following properties to configure warehouse storage security when needed. For example, if you are using a Hive or JDBC catalog backend with a Kerberos-secured HDFS warehouse, set `authentication.type` to `Kerberos` and provide `authentication.kerberos.principal` and `authentication.kerberos.keytab-uri`. For JDBC backend, JDBC username/password authentication for the metadata store is configured separately via `jdbc-user` and `jdbc-password`. Review Comment: The docs mix `Kerberos` and `kerberos` as the expected value for `authentication.type`. The implementation is case-insensitive, but the table now documents `kerberos`/`simple`, so the example should use the same casing to avoid confusing users. -- 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]
