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


##########
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:
   Every create lists all schemas and loads every table entity in the catalog, 
which will be slow for large catalogs and runs on the create path. Consider a 
location-indexed lookup or at least a note on the expected scale.



##########
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:
   The old catalog property for allowing external purge is replaced with no 
alias, so admins who already set it silently lose purge ability after upgrade. 
Keep the old key as a deprecated alias (or document the migration explicitly) 
and add a test.



##########
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:
   One existing table with an unparseable stored location makes every later 
create or register in the whole catalog fail. Skip and warn for that entry, or 
fail only when the requested location cannot be proven disjoint, so one bad row 
cannot block the catalog.



##########
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:
   This now blocks all alters on registered and declared tables unless the 
catalog admin opts in, including previously allowed schema changes. Is this 
behavior change intended for existing users, and is it covered by release notes?



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