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


##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/generic/GenericCatalogPropertiesMetadata.java:
##########
@@ -73,9 +73,10 @@ public class GenericCatalogPropertiesMetadata extends 
BaseCatalogPropertiesMetad
                 DefaultTableLocationProvider.NAME, /* defaultValue */
                 false /* hidden */),
             booleanPropertyEntry(
-                LANCE_ALLOW_EXTERNAL_TABLE_PURGE,
-                "Allow physical deletion of external and registered Lance 
datasets. Table"
-                    + " properties cannot enable this catalog-level policy.",
+                LANCE_ALLOW_EXTERNAL_DATASET_MODIFICATION,

Review Comment:
   Added the explicit migration note in docs/lakehouse-generic-catalog.md. The 
old key was introduced by #14870 on 2026-11-11 and is unreleased. It is no 
longer read; snapshot users must explicitly choose the new key, which 
authorizes schema/index modification as well as external deletion. Keeping a 
transparent alias would broaden their existing purge-only permission, so the 
migration is deliberately explicit.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -599,6 +641,282 @@ 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. Dataset deletion removes 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.isBlank(other)) {
+            continue;
+          }
+          final List<String> existing;
+          try {
+            existing = locationSegments(other);
+          } catch (IllegalArgumentException invalid) {

Review Comment:
   I kept the fail-closed behavior. An unparseable stored location does not 
provide enough information to prove that it is disjoint; skipping it would 
reopen the deletion/overwrite risk this guard is preventing. The error already 
tells the caller to ask a catalog administrator to repair the metadata, while 
the detailed table/location and original cause stay only in server logs. 
testInvalidStoredLocationFailsClosedWithoutExposingIt covers rejection before 
dataset access and checks the serialized response does not leak the other 
location. The availability tradeoff is disclosed in both the docs and PR 
description.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -599,6 +641,282 @@ 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. Dataset deletion removes 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)) {

Review Comment:
   Added an explicit O(schemas + tables) scale/latency note to the table 
documentation. This compares stored metadata only and opens no other datasets. 
We retain the complete scan to avoid missing conflicts; an 
indexed/transactional location registry is tracked as follow-up scope in #14788.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -292,6 +316,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:
   Yes, intentional: a registered/declared dataset was not created by 
Gravitino, so implicit schema/index mutation can alter another table's data. 
The user-facing change, default denial, catalog opt-in and legacy limits are 
documented in the PR and Lance docs. Created datasets remain alterable; 
registered/declared datasets require the catalog setting, and metadata-only 
drop/deregister still retains their data. Added a migration note that 
explicitly calls out the new setting's broader permission.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -599,6 +641,282 @@ 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. Dataset deletion removes 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.isBlank(other)) {
+            continue;
+          }
+          final List<String> existing;
+          try {
+            existing = locationSegments(other);
+          } catch (IllegalArgumentException invalid) {
+            // Fail closed without exposing the other table's name or location 
to its peers.
+            LOG.warn("Invalid stored Lance location for table {}", 
table.nameIdentifier(), invalid);
+            // Main REST can serialize exception causes by default. Keep the 
private URI in server
+            // logs only, not in the throwable returned to a caller of another 
table.
+            throw new IllegalStateException(
+                "Cannot check table locations in this catalog; ask a catalog 
administrator to"

Review Comment:
   There is already a regression test for this path: 
testInvalidStoredLocationFailsClosedWithoutExposingIt verifies that creation 
stops before dataset I/O, includes the administrator repair instruction, and 
keeps the other table's location out of serialized errors. I am retaining 
rejection rather than skip-and-log: an unparseable location cannot be proven 
disjoint, so allowing creation could delete the very dataset we failed to 
inspect. This availability tradeoff is explicitly documented, with actionable 
diagnostics restricted to server logs.



##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -599,6 +641,282 @@ 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. Dataset deletion removes 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)) {

Review Comment:
   The docs now explicitly state the O(schemas + tables) metadata cost per 
create/register/declare and the extra latency for large catalogs. They also 
state that the check is not atomic with concurrent creates. A cap would either 
miss conflicts or disable valid large catalogs; an indexed and transactional 
location registry remains follow-up work in #14788.



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