yuqi1129 commented on code in PR #14894:
URL: https://github.com/apache/gravitino/pull/14894#discussion_r4537625602


##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -599,6 +634,103 @@ private SchemaRefreshMode schemaRefreshMode() {
         .orElse(SchemaRefreshMode.DECLARED_AND_EMPTY);
   }
 
+  /**
+   * Rejects a location that equals, contains or is inside the location of 
another table in the same
+   * catalog. Dropping a table deletes its whole location, so a table at a 
parent directory could
+   * delete the datasets of other tables, and a table at another table's 
location could change that
+   * table's dataset.
+   *
+   * <p>This compares stored metadata only. It does not see other catalogs, 
symbolic links or tables
+   * created concurrently. The other table is not named, because the caller 
may not be allowed to
+   * see it.
+   *
+   * @param ident the table being created; an existing table with this name is 
ignored, because an
+   *     overwrite replaces it
+   * @param location the requested table location
+   */
+  private void rejectOverlappingLocation(NameIdentifier ident, String 
location) {
+    Namespace schemaNamespace = ident.namespace();
+    if (schemaNamespace.length() < 3) {
+      // Only a metalake.catalog.schema namespace identifies the catalog to 
compare against.
+      return;
+    }
+    List<String> requested = locationSegments(location);
+    Namespace catalogNamespace = Namespace.of(schemaNamespace.level(0), 
schemaNamespace.level(1));
+    try {
+      for (SchemaEntity schema :
+          store().list(catalogNamespace, SchemaEntity.class, 
Entity.EntityType.SCHEMA)) {
+        Namespace tableNamespace =
+            Namespace.of(catalogNamespace.level(0), catalogNamespace.level(1), 
schema.name());
+        for (TableEntity table :
+            store().list(tableNamespace, TableEntity.class, 
Entity.EntityType.TABLE)) {
+          if (table.nameIdentifier().equals(ident) || table.properties() == 
null) {
+            continue;
+          }
+          String other = table.properties().get(Table.PROPERTY_LOCATION);
+          if (StringUtils.isNotBlank(other) && isPrefixOrSame(requested, 
locationSegments(other))) {
+            throw new IllegalArgumentException(
+                String.format(
+                    "Location %s of Lance table %s overlaps the location of 
another table in"
+                        + " this catalog",
+                    location, ident));
+          }
+        }
+      }
+    } catch (IOException e) {
+      throw ExceptionMessages.wrap("Failed to check the table locations for " 
+ ident, e);
+    }
+  }
+
+  /**
+   * Splits a location into scheme, authority and normalized path segments. A 
path without a scheme
+   * is a local file path. Segments are compared whole, so {@code s3://b/v1} 
does not contain {@code
+   * s3://b/v10}.
+   */
+  static List<String> locationSegments(String location) {

Review Comment:
   The current head normalizes the aliases supported by Lance, including local 
file forms, s3+ddb, ignored S3 userinfo/ports, and Azure az/abfss spellings. 
s3a/s3n/gcs are not enabled by the Lance runtime, so treating them as supported 
aliases here would invent storage semantics. We also cannot blindly decode 
remote keys: escaped and decoded spellings can name different objects. The 
native S3 probe and regression tests cover these distinctions. I have now made 
these limits explicit in the table documentation; endpoint routing remains in 
#14788.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -234,22 +237,36 @@ public Table createTable(
       }
     }
 
-    if (register) {
-      if (mode == CreationMode.CREATE) {
-        // Check metadata before accessing storage so an existing name 
consistently reports a
-        // conflict. The final strict insert still detects a concurrent 
registration.
-        try {
-          if (store().exists(ident, Entity.EntityType.TABLE)) {
-            throw new TableAlreadyExistsException("Table %s already exists", 
ident);
-          }
-        } catch (IOException e) {
-          throw ExceptionMessages.wrap("Failed to check existence of table " + 
ident, e);
+    if (mode == CreationMode.CREATE) {
+      // Check metadata before accessing storage so an existing name reports a 
conflict without
+      // writing a dataset. The final strict insert still detects a concurrent 
creation.
+      try {
+        if (store().exists(ident, Entity.EntityType.TABLE)) {
+          throw new TableAlreadyExistsException("Table %s already exists", 
ident);
         }
+      } catch (IOException e) {
+        throw ExceptionMessages.wrap("Failed to check existence of table " + 
ident, e);
       }
+    }
+
+    // Before any storage access, so a location that holds another table's 
data is never written,
+    // adopted or later deleted through this table.
+    rejectOverlappingLocation(ident, location);

Review Comment:
   Documented the cost explicitly: each create/register/declare processes 
O(schemas + tables) metadata entries without opening the other datasets. The 
scan has no cap, because truncating it could miss an overlap; rejecting all 
catalogs over a threshold would disable valid operations. A location index 
together with atomic conflict detection is follow-up work in #14788, rather 
than expanding the store interfaces in this safety fix.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -292,6 +309,14 @@ public Table alterTable(NameIdentifier ident, 
TableChange... changes)
               + ident
               + " because its dataset schema is not initialized or could not 
be loaded");
     }
+    if (isAdoptedDataset(loadedTable.properties()) && 
!externalDatasetModificationAllowed()) {

Review Comment:
   Documented the legacy limitation. A still-declared table gains the reserved 
adopted marker when its schema is refreshed. Once an older declaration has 
already lost its declared flag, the remaining metadata cannot distinguish it 
from a dataset Gravitino created, so this patch does not guess or retroactively 
mark it. Legacy registrations remain identifiable through lance.register and 
are guarded even when their stored external flag is missing/false.



##########
docs/lakehouse-generic-catalog.md:
##########
@@ -50,7 +50,7 @@ For detailed information on available operations, see [Manage 
Relational Metadat
 | `location`                  | Root storage path for all schemas and tables   
                                                                                
                                                                                
                                                                                
                           | `s3://bucket/lakehouse` | No       |
 | `table-location-provider`   | Name of the [table location 
provider](#pluggable-table-location-provider) that provisions and unprovisions 
the locations of this catalog's tables. Defaults to `default`, which resolves 
the location from the table, schema and catalog `location` properties as 
described below. Immutable once the catalog is created. | `default`             
  | No       |
 | `lance.schema-refresh-mode` | Lance table schema refresh mode. 
`DECLARED_AND_EMPTY` (default) refreshes declared tables and tables with empty 
stored columns. `VERSION_CHECK` additionally refreshes when the Lance dataset 
version changes.                                                                
                                            | `DECLARED_AND_EMPTY`    | No      
 |
-| `lance.allow-external-table-purge` | Allow physical deletion of external or 
registered Lance tables, including Lance REST `DropTable` and create 
`OVERWRITE`. Catalog-only; table properties cannot enable it. Does not validate 
ownership of storage locations. | `false` | No |
+| `lance.allow-external-dataset-modification` | Allow physical deletion of 
external or registered Lance tables, including Lance REST `DropTable` and 
create `OVERWRITE`. Also allow column and index changes to the datasets of 
registered or declared tables. Catalog-only; table properties cannot enable it. 
Does not validate ownership of storage locations. Renamed from 
`lance.allow-external-table-purge`. | `false` | No |

Review Comment:
   The old name was introduced by #14870 (8985ffad65, 2026-11-11) and has not 
been released. Added an explicit migration note for users of unreleased builds: 
remove lance.allow-external-table-purge and deliberately set 
lance.allow-external-dataset-modification only when both external deletion and 
adopted-dataset schema/index writes are intended. No automatic alias is added, 
because mapping the old purge-only permission would silently grant broader 
modification permission.



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