roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395320978
##########
docs/apache-hive-catalog.md:
##########
@@ -29,19 +29,19 @@ The Hive catalog supports creating, updating, and deleting
databases and tables
Besides the [common catalog
properties](./gravitino-server-config.md#catalog-properties-configuration), the
Hive catalog has the following properties:
-| Property Name | Description
| Default Value | Required
| Since Version |
-|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|------------------------------|---------------|
-| `metastore.uris` | The Hive metastore service URIs,
separate multiple addresses with commas. Such as `thrift://127.0.0.1:9083`
| (none) | Yes
| 0.2.0 |
-| `client.pool-size` | The maximum number of Hive
metastore clients in the pool for Gravitino.
| 1 | No
| 0.2.0 |
-| `gravitino.bypass.` | Property name with this prefix
passed down to the underlying HMS client for use. Such as
`gravitino.bypass.hive.metastore.failure.retries = 3` indicate 3 times of
retries upon failure of Thrift metastore calls
| (none) | No | 0.2.0 |
-| `client.pool-cache.eviction-interval-ms` | The cache pool eviction interval.
| 300000 | No
| 0.4.0 |
-| `impersonation-enable` | Enable user impersonation for
Hive catalog.
| false | No
| 0.4.0 |
-| `kerberos.principal` | The Kerberos principal for the
catalog. You should configure
`gravitino.bypass.hadoop.security.authentication`,
`gravitino.bypass.hive.metastore.kerberos.principal` and
`gravitino.bypass.hive.metastore.sasl.enabled`if you want to use Kerberos. |
(none) | required if you use kerberos | 0.4.0 |
-| `kerberos.keytab-uri` | The uri of key tab for the
catalog. Now supported protocols are `https`, `http`, `ftp`, `file`.
| (none) |
required if you use kerberos | 0.4.0 |
-| `kerberos.check-interval-sec` | The interval to check validness
of the principal
| 60 | No
| 0.4.0 |
-| `kerberos.keytab-fetch-timeout-sec` | The timeout to fetch key tab
| 60 | No
| 0.4.0 |
-| `list-all-tables` | Whether to list all tables in a
database, including non-Hive tables such as Iceberg, Paimon, and Hudi. When
false, non-Hive tables are filtered out on a best-effort basis; see the note
below for known limitations. | false | No
| 0.5.1 |
-| `default.catalog` | The default catalog name for the
Hive3 metastore backend; this configuration is ignored when using a Hive2
metastore.
| hive | No
| 1.1.0 |
+| Property Name | Description
| Default Value | Required
| Since Version |
Review Comment:
Do we need to change this document?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code
file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single
shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg,
Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code
common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never
use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code
null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be
blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
Review Comment:
Is this test only?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code
file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single
shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg,
Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code
common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never
use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code
null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be
blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to
remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration}
instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI
is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
We can add a parameter `blockUnsafeAddress`?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code
file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single
shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg,
Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code
common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never
use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code
null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be
blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to
remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration}
instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI
is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object
hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
+
+ case "file":
+ linkLocalFile(uri, destFile);
+ break;
+
+ case "hdfs":
+ copyHdfsFileToLocal(uri, destFile, hadoopConf);
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ String.format("The scheme '%s' is not supported", scheme));
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (URISyntaxException ue) {
+ throw new IllegalArgumentException("The uri of file has the wrong
format", ue);
+ }
+ }
+
+ private static synchronized void linkLocalFile(URI uri, File destFile)
throws IOException {
+ Path srcPath = new File(uri.getPath()).toPath().normalize();
+ if (!Files.exists(srcPath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s",
srcPath.toAbsolutePath()));
+ }
+
+ Path destPath = destFile.toPath().toAbsolutePath().normalize();
+ // Skip if the symlink already points to the correct target.
+ if (Files.isSymbolicLink(destPath)
+ && Files.readSymbolicLink(destPath).normalize().equals(srcPath)) {
+ return;
+ }
+ // Replace via a temporary symlink + rename to minimize the window where
the destination path
+ // is absent (which could otherwise cause a concurrent reader, e.g.
loginUserFromKeytab, to
+ // fail). REPLACE_EXISTING is used here; on common local filesystems
(ext4, xfs, APFS) a
+ // same-directory rename is effectively atomic at the OS level.
+ Path tmpPath = destPath.resolveSibling(destPath.getFileName() +
".symlink.tmp");
+ Files.deleteIfExists(tmpPath);
+ Files.createSymbolicLink(tmpPath, srcPath);
+ Files.move(tmpPath, destPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ /**
+ * Copies an {@code hdfs} file to the local destination reflectively, so
that this class does not
+ * require a compile-time dependency on Hadoop.
+ */
+ private static void copyHdfsFileToLocal(URI uri, File destFile, @Nullable
Object hadoopConf)
Review Comment:
Should we use `Optional` here?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code
file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single
shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg,
Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code
common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never
use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code
null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be
blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to
remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration}
instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI
is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
Do we need to consider thread safety?
--
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]