yuqi1129 commented on code in PR #15004:
URL: https://github.com/apache/gravitino/pull/15004#discussion_r4596879237
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/RegisterTableSourceResolver.java:
##########
@@ -53,22 +56,47 @@ public static List<TableIdentifier> findSourceTables(
TableIdentifier target,
String metadataLocation,
TableMetadata metadata) {
+ return findOverlappingTables(catalogWrapper, target, metadata.location());
Review Comment:
[P1] Preserve source authorization for custom metadata locations
This removes the exact metadata-pointer match that previously protected
registration independently of the metadata layout. For a live table whose
`write.metadata.path` is outside its table location, registering that table's
current metadata now produces no source match: the JDBC candidate query
searches around `metadata.location()`, and the per-table fallback also only
infers roots from standard pointers. A user with destination CREATE_TABLE can
consequently skip the source load check and adopt the protected location.
Reproduced with a real SQLite catalog and local metadata files: create
`ns.secret` with a separate shared metadata directory, then resolve sources for
its actual current metadata when registering `ns.copy`. Expected `[ns.secret]`;
actual `[]`.
Please preserve exact-pointer identity matching and provide an authoritative
lookup or fail-closed behavior when the layout cannot establish the source
location. Documenting custom layouts as unsupported does not preserve the
existing authorization boundary; restoring exact-pointer matching alone would
also leave custom-layout create/set-location overlap checks incomplete.
##########
iceberg/iceberg-common/src/main/java/org/apache/iceberg/MetastoreRegisterTableUtils.java:
##########
@@ -96,5 +98,49 @@ public static Table registerTable(
catalog.metricsReporter());
}
+ /**
+ * Registers a metadata snapshot already read and authorized by the caller,
without reopening its
+ * file. Existing destination metadata is still read for an atomic overwrite.
+ *
+ * @param catalog destination catalog
+ * @param identifier destination table
+ * @param metadata snapshot read from the requested metadata file
+ * @param overwrite whether the destination can be replaced
+ * @param metadataLocationOverwrite atomic pointer replacement
+ * @return registered table
+ */
+ public static Table registerTable(
+ BaseMetastoreCatalog catalog,
+ TableIdentifier identifier,
+ TableMetadata metadata,
+ boolean overwrite,
+ MetadataLocationOverwrite metadataLocationOverwrite) {
+ Preconditions.checkArgument(
+ identifier != null && catalog.isValidIdentifier(identifier),
+ "Invalid identifier: %s",
+ identifier);
+ Preconditions.checkArgument(
+ metadata.metadataFileLocation() != null,
+ "Registered metadata must retain its file location");
+ TableOperations ops = catalog.newTableOps(identifier);
+ TableMetadata base = ops.current();
+ if (base == null) {
+ ops.commit(null, metadata);
+ } else {
+ if (!overwrite) {
+ throw new AlreadyExistsException("Table already exists: %s",
identifier);
+ }
+ Preconditions.checkArgument(
+ Objects.equals(base.uuid(), metadata.uuid()),
+ "Cannot overwrite a table with a different table UUID");
+ metadataLocationOverwrite.overwrite(
Review Comment:
[P2] Return a Table reflecting the overwritten metadata
`ops.current()` has already cached the destination metadata before this
callback changes the catalog pointer. Unlike the existing String overload, this
overload neither refreshes nor installs the registered snapshot before
returning `new BaseTable(ops, ...)`, so the returned Table still exposes the
pre-overwrite state.
Reproduced with SQLite: create snapshot A with `marker=old`, commit B with
`marker=new`, then call the new overload to register A with overwrite=true. A
fresh catalog load returns `old`, but the returned Table reports `new`.
Please make the returned operations reflect the successfully registered
snapshot while preserving the intended no-reopen behavior, or avoid exposing a
stale Table through this new API. The current REST wrapper ignores this return
value, so this finding concerns the public Java overload rather than the REST
response.
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/RegisterTableSourceResolver.java:
##########
@@ -82,63 +110,42 @@ private static void collectMatchingTables(
return;
}
for (Namespace child : children) {
- collectMatchingTables(
- catalogWrapper, child, target, uuid, tableLocation,
metadataLocation, matches);
+ collectMatchingTables(catalogWrapper, child, target, tableLocation,
matches);
}
for (TableIdentifier identifier : tables) {
if (identifier.equals(target)) {
continue;
}
- if (matchesSource(catalogWrapper, identifier, uuid, tableLocation,
metadataLocation)) {
+ if (matchesSource(catalogWrapper, identifier, tableLocation)) {
matches.add(identifier);
}
}
}
private static boolean matchesSource(
- IcebergCatalogWrapper catalogWrapper,
- TableIdentifier identifier,
- String uuid,
- String tableLocation,
- String metadataLocation) {
+ IcebergCatalogWrapper catalogWrapper, TableIdentifier identifier, String
tableLocation) {
Optional<String> currentMeta =
catalogWrapper.getTableMetadataLocation(identifier);
- if (currentMeta.isPresent() &&
normalizePath(currentMeta.get()).equals(metadataLocation)) {
- return true;
+ if (currentMeta.isPresent()) {
+ return matchesPointer(currentMeta.get(), tableLocation);
}
try {
TableMetadata existing = catalogWrapper.loadTableMetadata(identifier);
- if (uuid != null && uuid.equals(existing.uuid())) {
- return true;
- }
- return tableLocation != null
- && !tableLocation.isEmpty()
- && tableLocation.equals(normalizePath(existing.location()));
- } catch (NoSuchTableException e) {
- // Only a table that no longer exists is unrelated. Any other failure to
read its metadata
- // must not be mistaken for unrelated metadata, which would skip source
authorization.
+ return IcebergTableLocationUtils.overlaps(tableLocation,
existing.location());
+ } catch (RuntimeException e) {
Review Comment:
[P1] Do not treat unreadable source metadata as unrelated
When no metadata pointer is available and loading a live source table fails,
this catch converts an unknown authorization state into `false`. The caller
then omits that table's load-permission check and allows registration.
Previously, only NoSuchTableException was ignored; storage/service failures
blocked the operation. This also affects explicit create and set-location
through the shared resolver.
Reproduced through the actual authorization interceptor: allow destination
CREATE_TABLE, deny source SELECT_TABLE, return an empty pointer and throw a
storage failure when loading the source. The request reaches
`MethodInvocation.proceed()` instead of failing closed.
Please skip only a source proven to no longer exist, or use reliable
location/identity information to prove it unrelated. Logging the exception and
describing an availability trade-off does not make it safe to authorize the
operation.
##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergTableLocationUtils.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+/** Location comparisons and JDBC lookup patterns for Iceberg's standard
metadata layout. */
+public final class IcebergTableLocationUtils {
+ private static final String METADATA_DIRECTORY = "/metadata/";
+
+ private IcebergTableLocationUtils() {}
+
+ /**
+ * Normalizes trailing separators, local URI forms and equivalent S3 schemes.
+ *
+ * @param location storage location, possibly absent
+ * @return normalized location, or an empty string for an absent location
+ */
+ public static String normalize(@Nullable String location) {
+ if (location == null) {
+ return "";
+ }
+ String value = location.trim();
+ if (value.startsWith("s3a://") || value.startsWith("s3n://")) {
+ value = "s3://" + value.substring(6);
+ } else if (value.startsWith("file:")) {
+ String path = value.substring(5);
+ while (path.startsWith("//")) {
+ path = path.substring(1);
+ }
+ value = "file:" + (path.startsWith("/") ? path : "/" + path);
+ } else if (value.startsWith("/")) {
+ value = "file:" + value;
+ }
+ while (value.endsWith("/") && !value.endsWith(":/")) {
+ value = value.substring(0, value.length() - 1);
+ }
+ return value;
Review Comment:
Confirmed on 0302d507ed with a real SQLite catalog and local table files.
The regression first verifies that the requested `/./secret` path and the
existing `/secret` path normalize to the same filesystem location, then invokes
the production source resolver. It returns an empty source list instead of
`[ns.secret]`. This remains unresolved; the test does not simulate cloud or
HDFS path handling.
##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -245,6 +246,19 @@ public UpdateNamespacePropertiesResponse
updateNamespaceProperties(
public LoadTableResponse registerTable(Namespace namespace,
RegisterTableRequest request) {
validateTableLocation(request.metadataLocation());
+ Catalog loadedCatalog = getCatalog();
+ // Subclasses can enforce additional registration invariants through the
original API.
+ if (request instanceof RegisterTableRequestWithMetadata
+ && loadedCatalog.getClass() ==
JdbcCatalogWithMetadataLocationSupport.class) {
Review Comment:
Confirmed on 0302d507ed through the real wrapper with a mocked non-JDBC
catalog: a remote metadata URL plus an already-read snapshot containing
`file:/tmp/local-table` reaches the backend registration hook instead of
throwing BadRequestException. The snapshot validation needs to precede backend
selection. Please also check the symmetric registerView path, which currently
validates only the metadata-file URL; that view observation is from code
inspection, not an end-to-end reproduction.
--
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]