roryqi commented on code in PR #15004:
URL: https://github.com/apache/gravitino/pull/15004#discussion_r4610674230


##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/RegisterTableSourceResolver.java:
##########
@@ -98,47 +143,28 @@ private static void collectMatchingTables(
   private static boolean matchesSource(
       IcebergCatalogWrapper catalogWrapper,
       TableIdentifier identifier,
-      String uuid,
       String tableLocation,
-      String metadataLocation) {
+      @Nullable String metadataLocation) {
     Optional<String> currentMeta = 
catalogWrapper.getTableMetadataLocation(identifier);
-    if (currentMeta.isPresent() && 
normalizePath(currentMeta.get()).equals(metadataLocation)) {
-      return true;
+    if (currentMeta.isPresent()) {
+      return matchesPointer(currentMeta.get(), tableLocation, 
metadataLocation);
     }
     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()));
+      return IcebergTableLocationUtils.overlaps(tableLocation, 
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 false;
     }
   }
 
-  /** Normalizes path strings so {@code file:/} and {@code file:///} compare 
equal. */
-  public static String normalizePath(String path) {
-    if (path == null) {
-      return "";
-    }
-    String trimmed = path.trim();
-    if (trimmed.startsWith("file:")) {
-      String withoutScheme = trimmed.substring("file:".length());
-      while (withoutScheme.startsWith("//")) {
-        withoutScheme = withoutScheme.substring(1);
-      }
-      if (!withoutScheme.startsWith("/")) {
-        withoutScheme = "/" + withoutScheme;
-      }
-      return "file:" + withoutScheme;
-    }
-    if (trimmed.endsWith("/")) {
-      return trimmed.substring(0, trimmed.length() - 1);
+  private static boolean matchesPointer(
+      String pointer, String location, @Nullable String metadataLocation) {
+    if (metadataLocation != null
+        && normalizePath(pointer).equals(normalizePath(metadataLocation))) {
+      return true;
     }
-    return trimmed;
+    return IcebergTableLocationUtils.tableLocation(pointer)

Review Comment:
   To clarify, this is a deliberate performance and availability trade-off for 
this PR.
   
   Restoring the previous source check for arbitrary custom layouts means 
enumerating the catalog and reading live tables' metadata to discover their 
actual locations. On a cold catalog, this can require O(N) metadata-file reads 
for a single registration. With remote storage, those unrelated reads dominate 
latency; an unavailable metadata file belonging to an unrelated table can also 
block registration. For large catalogs, this can make registration effectively 
unusable. Eliminating that catalog-wide storage I/O is a central purpose of 
this change, so restoring the old scan would bring back the problem we are 
fixing.
   
   The chosen approach supports standard layouts through one JDBC candidate 
query, reads the requested metadata snapshot once, and retains exact 
current-pointer matching without opening other tables' metadata. A new cache 
would still leave the cold-start/miss problem; authoritative persisted table 
locations require a separate persistence/lifecycle design.
   
   We are deliberately retaining the known older-snapshot limitation for custom 
layouts within this scope. Rejecting unsupported registrations outright is 
another possible policy, but changes which registrations the API accepts. I am 
not claiming the custom-layout case is fixed or technically impossible to fix: 
it is the explicit limitation of the performance/availability trade-off chosen 
here.



-- 
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]

Reply via email to