You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "roryqi (via GitHub)" <gi...@apache.org> on 2026/06/02 11:04:24 UTC
[PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
roryqi opened a new pull request, #11362:
URL: https://github.com/apache/gravitino/pull/11362
### What changes were proposed in this pull request?
This PR cleans up Gravitino schema entities that become orphaned when the underlying catalog automatically removes empty parent namespaces after dropping a table, view, or namespace.
The patch:
- shares orphan schema cleanup logic in the core operation dispatcher
- applies the cleanup from schema, table, and view drop paths
- adds Iceberg REST schema entity cleanup for namespace, table, and view drops
- aligns Iceberg REST table/view drop cleanup with the namespace hook branch lock
- adds regression tests for core dispatchers and Iceberg REST hook dispatchers
### Why are the changes needed?
Some catalogs, including Iceberg JdbcCatalog, may implicitly remove empty namespaces and their empty parent namespaces after the last table/view/sub-namespace is dropped. Gravitino could still keep the corresponding schema entities in its store, leaving stale metadata.
Fix: #11262
### Does this PR introduce _any_ user-facing change?
No new API, configuration, or user-facing behavior is introduced. This fixes stale internal metadata cleanup after drop operations.
### How was this patch tested?
- Skipping filesystem-fuse module since enableFuse is set to false
> Configure project :
------------------ Check Docker environment ---------------------
Docker server status ............................................ [running]
Run test cases without `gravitino-docker-test` tag .............. [embedded test]
-----------------------------------------------------------------
> Configure project :catalogs
Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
> Configure project :core
Kotlin DSL property assignment is an incubating feature.
> Task :spotlessInternalRegisterDependencies UP-TO-DATE
> Task :api:processResources UP-TO-DATE
> Task :catalogs:catalog-common:processResources NO-SOURCE
> Task :common:processResources
> Task :catalogs:catalog-common:spotlessJava UP-TO-DATE
> Task :catalogs:catalog-common:spotlessJavaCheck UP-TO-DATE
> Task :catalogs:catalog-common:spotlessKotlinGradle UP-TO-DATE
> Task :catalogs:catalog-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :catalogs:catalog-common:spotlessCheck UP-TO-DATE
> Task :integration-test-common:spotlessJava UP-TO-DATE
> Task :integration-test-common:spotlessJavaCheck UP-TO-DATE
> Task :common:spotlessJava UP-TO-DATE
> Task :common:spotlessJavaCheck UP-TO-DATE
> Task :integration-test-common:spotlessKotlinGradle UP-TO-DATE
> Task :integration-test-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :integration-test-common:spotlessCheck UP-TO-DATE
> Task :common:spotlessKotlinGradle UP-TO-DATE
> Task :common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :common:spotlessCheck UP-TO-DATE
> Task :api:spotlessJava UP-TO-DATE
> Task :integration-test-common:compileJava NO-SOURCE
> Task :integration-test-common:processResources NO-SOURCE
> Task :api:spotlessJavaCheck UP-TO-DATE
> Task :integration-test-common:classes UP-TO-DATE
> Task :api:spotlessKotlinGradle UP-TO-DATE
> Task :api:spotlessKotlinGradleCheck UP-TO-DATE
> Task :api:spotlessCheck UP-TO-DATE
> Task :lineage:spotlessJava UP-TO-DATE
> Task :lineage:spotlessJavaCheck UP-TO-DATE
> Task :lineage:spotlessKotlinGradle UP-TO-DATE
> Task :lineage:spotlessKotlinGradleCheck UP-TO-DATE
> Task :lineage:spotlessCheck UP-TO-DATE
> Task :lineage:processResources NO-SOURCE
> Task :server-common:spotlessJava UP-TO-DATE
> Task :server-common:spotlessJavaCheck UP-TO-DATE
> Task :server-common:spotlessKotlinGradle UP-TO-DATE
> Task :server-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :server-common:spotlessCheck UP-TO-DATE
> Task :server-common:processResources UP-TO-DATE
> Task :server:spotlessJava UP-TO-DATE
> Task :clients:client-java:spotlessJava UP-TO-DATE
> Task :server:spotlessJavaCheck UP-TO-DATE
> Task :clients:client-java:spotlessJavaCheck UP-TO-DATE
> Task :server:spotlessKotlinGradle UP-TO-DATE
> Task :clients:client-java:spotlessKotlinGradle UP-TO-DATE
> Task :server:spotlessKotlinGradleCheck UP-TO-DATE
> Task :server:spotlessCheck UP-TO-DATE
> Task :clients:client-java:spotlessKotlinGradleCheck UP-TO-DATE
> Task :clients:client-java:spotlessCheck UP-TO-DATE
> Task :server:processResources NO-SOURCE
> Task :clients:client-java:processResources NO-SOURCE
> Task :api:compileJava UP-TO-DATE
> Task :api:classes UP-TO-DATE
> Task :integration-test-common:processTestResources UP-TO-DATE
> Task :api:jar UP-TO-DATE
> Task :lance:lance-common:spotlessJava UP-TO-DATE
> Task :lance:lance-common:spotlessJavaCheck UP-TO-DATE
> Task :lance:lance-common:spotlessKotlinGradle UP-TO-DATE
> Task :lance:lance-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :lance:lance-common:spotlessCheck UP-TO-DATE
> Task :lance:lance-common:processResources NO-SOURCE
> Task :common:compileJava UP-TO-DATE
> Task :common:classes
> Task :core:spotlessJava UP-TO-DATE
> Task :core:spotlessJavaCheck UP-TO-DATE
> Task :core:spotlessKotlinGradle UP-TO-DATE
> Task :core:spotlessKotlinGradleCheck UP-TO-DATE
> Task :core:spotlessCheck UP-TO-DATE
> Task :core:processResources UP-TO-DATE
> Task :core:processTestResources UP-TO-DATE
> Task :common:jar
WARN: Unable to get Git commit id : /home/roryqi/code/gravitino/.claude/worktrees/fix-11262-drop-schema-hierarchical/home/roryqi/code/gravitino/.git/worktrees/fix-11262-drop-schema-hierarchical/HEAD (No such file or directory)
> Task :clients:client-java:compileJava UP-TO-DATE
> Task :clients:client-java:classes UP-TO-DATE
> Task :clients:client-java:jar UP-TO-DATE
> Task :catalogs:catalog-common:compileJava UP-TO-DATE
> Task :catalogs:catalog-common:classes UP-TO-DATE
> Task :catalogs:catalog-common:jar UP-TO-DATE
> Task :core:compileJava UP-TO-DATE
> Task :core:classes UP-TO-DATE
> Task :core:jar UP-TO-DATE
> Task :lance:lance-common:compileJava UP-TO-DATE
> Task :lance:lance-common:classes UP-TO-DATE
> Task :server-common:compileJava UP-TO-DATE
> Task :server-common:classes UP-TO-DATE
> Task :lance:lance-common:jar UP-TO-DATE
> Task :server-common:jar UP-TO-DATE
> Task :lineage:compileJava UP-TO-DATE
> Task :lineage:classes UP-TO-DATE
> Task :lineage:jar UP-TO-DATE
> Task :server:compileJava UP-TO-DATE
> Task :server:classes UP-TO-DATE
> Task :server:jar UP-TO-DATE
> Task :integration-test-common:compileTestJava UP-TO-DATE
> Task :integration-test-common:testClasses UP-TO-DATE
> Task :integration-test-common:testJar UP-TO-DATE
> Task :core:compileTestJava UP-TO-DATE
> Task :core:testClasses UP-TO-DATE
> Task :core:test
[TEST-TIMING] START module=:core task=:core:test at=1780398228093
[TEST-TIMING] END module=:core task=:core:test startMs=1780398228093 endMs=1780398238166 durationMs=10073
> Task :core:jacocoTestReport
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.2/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 22s
70 actionable tasks: 4 executed, 66 up-to-date
- Skipping filesystem-fuse module since enableFuse is set to false
> Configure project :
------------------ Check Docker environment ---------------------
Docker server status ............................................ [running]
Run test cases without `gravitino-docker-test` tag .............. [embedded test]
-----------------------------------------------------------------
Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
> Configure project :core
Kotlin DSL property assignment is an incubating feature.
> Task :catalogs:catalog-common:processResources NO-SOURCE
> Task :spotlessInternalRegisterDependencies UP-TO-DATE
> Task :api:processResources UP-TO-DATE
> Task :server-common:processResources UP-TO-DATE
> Task :common:processResources
> Task :catalogs:catalog-common:spotlessJava UP-TO-DATE
> Task :catalogs:catalog-common:spotlessJavaCheck UP-TO-DATE
> Task :catalogs:catalog-common:spotlessKotlinGradle UP-TO-DATE
> Task :catalogs:catalog-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :catalogs:catalog-common:spotlessCheck UP-TO-DATE
> Task :server-common:spotlessJava UP-TO-DATE
> Task :server-common:spotlessJavaCheck UP-TO-DATE
> Task :api:spotlessJava UP-TO-DATE
> Task :server-common:spotlessKotlinGradle UP-TO-DATE
> Task :server-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :server-common:spotlessCheck UP-TO-DATE
> Task :api:spotlessJavaCheck UP-TO-DATE
> Task :api:spotlessKotlinGradle UP-TO-DATE
> Task :api:spotlessKotlinGradleCheck UP-TO-DATE
> Task :api:spotlessCheck UP-TO-DATE
> Task :common:spotlessJava UP-TO-DATE
> Task :bundles:aliyun:spotlessJava UP-TO-DATE
> Task :common:spotlessJavaCheck UP-TO-DATE
> Task :bundles:aliyun:spotlessJavaCheck UP-TO-DATE
> Task :common:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:aliyun:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:aliyun:spotlessKotlinGradleCheck UP-TO-DATE
> Task :common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:aliyun:spotlessCheck UP-TO-DATE
> Task :common:spotlessCheck UP-TO-DATE
> Task :bundles:aliyun:processResources UP-TO-DATE
> Task :catalogs:hadoop-common:spotlessJava UP-TO-DATE
> Task :catalogs:hadoop-common:spotlessJavaCheck UP-TO-DATE
> Task :catalogs:hadoop-common:spotlessKotlinGradle UP-TO-DATE
> Task :catalogs:hadoop-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :catalogs:hadoop-common:spotlessCheck UP-TO-DATE
> Task :catalogs:hadoop-common:processResources UP-TO-DATE
> Task :bundles:aws:spotlessJava UP-TO-DATE
> Task :api:compileJava UP-TO-DATE
> Task :api:classes UP-TO-DATE
> Task :bundles:azure:spotlessJava UP-TO-DATE
> Task :bundles:azure:spotlessJavaCheck UP-TO-DATE
> Task :bundles:aws:spotlessJavaCheck UP-TO-DATE
> Task :bundles:aws:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:azure:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:azure:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:azure:spotlessCheck UP-TO-DATE
> Task :bundles:aws:spotlessKotlinGradleCheck UP-TO-DATE
> Task :api:jar UP-TO-DATE
> Task :bundles:aws:spotlessCheck UP-TO-DATE
> Task :bundles:azure:processResources UP-TO-DATE
> Task :bundles:aws:processResources UP-TO-DATE
> Task :bundles:gcp:spotlessJava UP-TO-DATE
> Task :bundles:gcp:spotlessJavaCheck UP-TO-DATE
> Task :clients:client-java:spotlessJava UP-TO-DATE
> Task :common:compileJava UP-TO-DATE
> Task :common:classes
> Task :clients:client-java:spotlessJavaCheck UP-TO-DATE
> Task :bundles:gcp:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:gcp:spotlessKotlinGradleCheck UP-TO-DATE
> Task :clients:client-java:spotlessKotlinGradle UP-TO-DATE
> Task :clients:client-java:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:gcp:spotlessCheck UP-TO-DATE
> Task :bundles:gcp:processResources UP-TO-DATE
> Task :clients:client-java:spotlessCheck UP-TO-DATE
> Task :clients:client-java:processResources NO-SOURCE
> Task :iceberg:iceberg-common:spotlessJava UP-TO-DATE
> Task :iceberg:iceberg-common:spotlessJavaCheck UP-TO-DATE
> Task :iceberg:iceberg-common:spotlessKotlinGradle UP-TO-DATE
> Task :iceberg:iceberg-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :iceberg:iceberg-common:spotlessCheck UP-TO-DATE
> Task :iceberg:iceberg-common:processResources NO-SOURCE
> Task :integration-test-common:spotlessJava UP-TO-DATE
> Task :iceberg:iceberg-rest-server:spotlessJava UP-TO-DATE
> Task :integration-test-common:spotlessJavaCheck UP-TO-DATE
> Task :iceberg:iceberg-rest-server:spotlessJavaCheck UP-TO-DATE
> Task :integration-test-common:spotlessKotlinGradle UP-TO-DATE
> Task :integration-test-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :integration-test-common:spotlessCheck UP-TO-DATE
> Task :integration-test-common:compileJava NO-SOURCE
> Task :integration-test-common:processResources NO-SOURCE
> Task :iceberg:iceberg-rest-server:spotlessKotlinGradle UP-TO-DATE
> Task :integration-test-common:classes UP-TO-DATE
> Task :iceberg:iceberg-rest-server:spotlessKotlinGradleCheck UP-TO-DATE
> Task :iceberg:iceberg-rest-server:spotlessCheck UP-TO-DATE
> Task :iceberg:iceberg-rest-server:processResources UP-TO-DATE
> Task :lineage:spotlessJava UP-TO-DATE
> Task :server:spotlessJava UP-TO-DATE
> Task :server:spotlessJavaCheck UP-TO-DATE
> Task :lineage:spotlessJavaCheck UP-TO-DATE
> Task :server:spotlessKotlinGradle UP-TO-DATE
> Task :lineage:spotlessKotlinGradle UP-TO-DATE
> Task :lineage:spotlessKotlinGradleCheck UP-TO-DATE
> Task :server:spotlessKotlinGradleCheck UP-TO-DATE
> Task :lineage:spotlessCheck UP-TO-DATE
> Task :server:spotlessCheck UP-TO-DATE
> Task :lineage:processResources NO-SOURCE
> Task :server:processResources NO-SOURCE
> Task :integration-test-common:processTestResources UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:spotlessJava UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:spotlessJavaCheck UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:spotlessKotlinGradle UP-TO-DATE
> Task :lance:lance-common:spotlessJava UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:spotlessCheck UP-TO-DATE
> Task :lance:lance-common:spotlessJavaCheck UP-TO-DATE
> Task :lance:lance-common:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:compileJava NO-SOURCE
> Task :bundles:iceberg-aliyun-bundle:processResources NO-SOURCE
> Task :bundles:iceberg-aliyun-bundle:classes UP-TO-DATE
> Task :lance:lance-common:spotlessKotlinGradleCheck UP-TO-DATE
> Task :lance:lance-common:spotlessCheck UP-TO-DATE
> Task :lance:lance-common:processResources NO-SOURCE
> Task :bundles:iceberg-aws-bundle:spotlessJava UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:spotlessJavaCheck UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:iceberg-aliyun-bundle:shadowJar UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:spotlessCheck UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:compileJava NO-SOURCE
> Task :bundles:iceberg-aliyun-bundle:jar UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:processResources NO-SOURCE
> Task :bundles:iceberg-aws-bundle:classes UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:spotlessJava UP-TO-DATE
> Task :common:jar
WARN: Unable to get Git commit id : /home/roryqi/code/gravitino/.claude/worktrees/fix-11262-drop-schema-hierarchical/home/roryqi/code/gravitino/.git/worktrees/fix-11262-drop-schema-hierarchical/HEAD (No such file or directory)
> Task :bundles:iceberg-aws-bundle:shadowJar UP-TO-DATE
> Task :core:spotlessJava UP-TO-DATE
> Task :core:spotlessJavaCheck UP-TO-DATE
> Task :core:spotlessKotlinGradle UP-TO-DATE
> Task :core:spotlessKotlinGradleCheck UP-TO-DATE
> Task :core:spotlessCheck UP-TO-DATE
> Task :core:processResources UP-TO-DATE
> Task :bundles:iceberg-aws-bundle:jar UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:spotlessJavaCheck UP-TO-DATE
> Task :catalogs:catalog-common:compileJava UP-TO-DATE
> Task :catalogs:catalog-common:classes UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:spotlessCheck UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:compileJava NO-SOURCE
> Task :clients:client-java:compileJava UP-TO-DATE
> Task :clients:client-java:classes UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:processResources NO-SOURCE
> Task :bundles:iceberg-azure-bundle:classes UP-TO-DATE
> Task :catalogs:catalog-common:jar UP-TO-DATE
> Task :clients:client-java:jar UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:shadowJar UP-TO-DATE
> Task :catalogs:hadoop-common:compileJava UP-TO-DATE
> Task :catalogs:hadoop-common:classes UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:spotlessJava UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:spotlessJavaCheck UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:spotlessKotlinGradle UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:spotlessKotlinGradleCheck UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:spotlessCheck UP-TO-DATE
> Task :bundles:iceberg-azure-bundle:jar UP-TO-DATE
> Task :catalogs:hadoop-common:jar UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:compileJava NO-SOURCE
> Task :iceberg:iceberg-rest-server:processTestResources UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:processResources NO-SOURCE
> Task :bundles:iceberg-gcp-bundle:classes UP-TO-DATE
> Task :catalogs:catalog-fileset:runtimeJars UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:shadowJar UP-TO-DATE
> Task :bundles:aliyun:compileJava UP-TO-DATE
> Task :bundles:aliyun:classes UP-TO-DATE
> Task :bundles:aws:compileJava UP-TO-DATE
> Task :bundles:aws:classes UP-TO-DATE
> Task :bundles:aliyun:jar UP-TO-DATE
> Task :bundles:aws:jar UP-TO-DATE
> Task :core:compileJava UP-TO-DATE
> Task :bundles:iceberg-gcp-bundle:jar UP-TO-DATE
> Task :core:classes UP-TO-DATE
> Task :bundles:azure:compileJava UP-TO-DATE
> Task :bundles:azure:classes UP-TO-DATE
> Task :bundles:gcp:compileJava UP-TO-DATE
> Task :bundles:gcp:classes UP-TO-DATE
> Task :bundles:azure:jar UP-TO-DATE
> Task :core:jar UP-TO-DATE
> Task :bundles:gcp:jar UP-TO-DATE
> Task :lance:lance-common:compileJava UP-TO-DATE
> Task :lance:lance-common:classes UP-TO-DATE
> Task :server-common:compileJava UP-TO-DATE
> Task :lance:lance-common:jar UP-TO-DATE
> Task :server-common:classes UP-TO-DATE
> Task :iceberg:iceberg-common:compileJava UP-TO-DATE
> Task :server-common:jar UP-TO-DATE
> Task :iceberg:iceberg-common:classes UP-TO-DATE
> Task :iceberg:iceberg-common:jar UP-TO-DATE
> Task :lineage:compileJava UP-TO-DATE
> Task :lineage:classes UP-TO-DATE
> Task :iceberg:iceberg-rest-server:compileJava UP-TO-DATE
> Task :lineage:jar UP-TO-DATE
> Task :iceberg:iceberg-rest-server:classes UP-TO-DATE
> Task :iceberg:iceberg-rest-server:jar UP-TO-DATE
> Task :server:compileJava UP-TO-DATE
> Task :server:classes UP-TO-DATE
> Task :server:jar UP-TO-DATE
> Task :integration-test-common:compileTestJava UP-TO-DATE
> Task :integration-test-common:testClasses UP-TO-DATE
> Task :integration-test-common:testJar UP-TO-DATE
> Task :iceberg:iceberg-rest-server:copyDepends
> Task :iceberg:iceberg-rest-server:compileTestJava UP-TO-DATE
> Task :iceberg:iceberg-rest-server:testClasses UP-TO-DATE
> Task :iceberg:iceberg-rest-server:test
[TEST-TIMING] START module=:iceberg:iceberg-rest-server task=:iceberg:iceberg-rest-server:test at=1780398251143
[TEST-TIMING] END module=:iceberg:iceberg-rest-server task=:iceberg:iceberg-rest-server:test startMs=1780398251143 endMs=1780398258494 durationMs=7351
> Task :iceberg:iceberg-rest-server:jacocoTestReport
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.2/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 16s
144 actionable tasks: 5 executed, 139 up-to-date
-
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3348298691
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,6 +432,17 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
Review Comment:
You can see the discussion https://lists.apache.org/thread/o6ojgqyzrpwxp1wb0onl7wxmrxrfgx46
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3355862696
##########
core/src/main/java/org/apache/gravitino/utils/SchemaEntityCleaner.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.utils;
+
+import static org.apache.gravitino.Entity.EntityType.SCHEMA;
+
+import java.util.ArrayList;
+import java.util.function.Predicate;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Utility for deleting schema entities whose backing catalog schemas no longer exist. */
+public final class SchemaEntityCleaner {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SchemaEntityCleaner.class);
+
+ private SchemaEntityCleaner() {}
+
+ /**
+ * Deletes the outermost orphaned schema entity and its descendants from the store.
+ *
+ * <p>Candidates are checked from the starting schema toward the outermost ancestor. The first
+ * candidate that still exists in the catalog stops the walk; every more-specific candidate
+ * checked before that point is stale. A single cascade delete on the outermost stale schema
+ * removes it and all descendant schema entities.
+ *
+ * <p>This is best-effort: callers invoke it after the primary drop has already succeeded, so any
+ * failure (a store error or a catalog existence probe failure) is logged and swallowed rather
+ * than propagated. The orphan, if any, is retried on a subsequent drop.
+ *
+ * @param store the Gravitino entity store; if {@code null}, this method is a no-op
+ * @param schemaIdent the schema identifier to start checking from
+ * @param includeSelf whether to check {@code schemaIdent} itself before checking ancestors
+ * @param schemaExists predicate reporting whether a schema still exists in the underlying catalog
+ */
+ public static void deleteOrphanedSchemaEntities(
+ EntityStore store,
+ NameIdentifier schemaIdent,
+ boolean includeSelf,
+ Predicate<NameIdentifier> schemaExists) {
+ if (store == null) {
+ return;
+ }
+
+ try {
+ String separator = HierarchicalSchemaUtil.schemaSeparator();
+ ArrayList<String> schemaNames =
+ new ArrayList<>(HierarchicalSchemaUtil.allScopes(schemaIdent.name(), separator));
+ if (!includeSelf && !schemaNames.isEmpty()) {
+ schemaNames.remove(0);
+ }
+
+ NameIdentifier outermostOrphan = null;
+ for (String schemaName : schemaNames) {
+ NameIdentifier candidate = NameIdentifier.of(schemaIdent.namespace(), schemaName);
+ if (schemaExists.test(candidate)) {
Review Comment:
Why don't you use the entity store to check the existence as you can access the entity store freely?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3353289180
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,6 +432,17 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
`purgeTable` has the same `if (droppedFromCatalog)` guard around orphaned-schema cleanup as `dropTable`. When the underlying purge returns false because the table is already gone, Gravitino may still have orphaned schema entities if the backend auto-dropped empty namespaces. Running `SchemaEntityCleaner` unconditionally here is safe (it stops as soon as a schema exists) and avoids leaving stale schema metadata.
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -366,6 +367,17 @@ public boolean dropTable(NameIdentifier ident) {
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
The orphaned-schema cleanup is only triggered when `droppedFromCatalog` is true. If a table is already missing in the underlying catalog (e.g., dropped out-of-band) and the backend auto-removed empty namespaces, this path will delete the table entity from the store but leave orphaned schema entities behind. Since `SchemaEntityCleaner` is best-effort and uses `schemaExists` checks, it can safely run even when `dropTable` returns false.
##########
core/src/main/java/org/apache/gravitino/catalog/ViewOperationDispatcher.java:
##########
@@ -292,6 +293,17 @@ public boolean dropView(NameIdentifier ident) {
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
The orphaned-schema cleanup is currently skipped when `dropView` returns false. If the view was dropped outside Gravitino and the catalog auto-removed empty namespaces, this will remove only the view entity while leaving orphaned schema entities in the store. Because `SchemaEntityCleaner` is best-effort and checks `schemaExists`, it should run regardless of `droppedFromCatalog`.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3348161679
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,6 +432,17 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
Review Comment:
Can we retrieve the results in a single call to `listSchemas` to avoid multiple invocations of the underlying catalog?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#issuecomment-4627925922
I have no comment, @yuqi1129 can you please take a final review?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi merged PR #11362:
URL: https://github.com/apache/gravitino/pull/11362
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3357164382
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,10 +424,33 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ // Run unconditionally: an out-of-band purge may have left orphaned schema entities. The
+ // cleanup is best-effort and stops as soon as a schema still exists.
+ cleanUpOrphanedSchemaEntities(catalogIdent, schemaIdentifier);
Review Comment:
Done. Added `testPurgeMissingTableCleansUpSchemas`, mirroring the `dropTable` out-of-band case: the catalog has already removed the table and auto-dropped the empty namespaces, so `purgeTable` returns false but the orphaned schema entities must still be cleaned up. It also guards against a future regression that re-guards the cleanup behind the catalog drop result. (Required adding a `purgeTable` override to `TestCatalogOperations`, since the default interface method throws `UnsupportedOperationException`.)
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceHookDispatcher.java:
##########
@@ -147,49 +144,26 @@ public void dropNamespace(IcebergRequestContext context, Namespace namespace) {
() -> {
dispatcher.dropNamespace(context, namespace);
- // Only the leaf namespace is dropped from the Iceberg catalog above. getAncestorNames
- // returns ancestors outermost-to-innermost, so we walk it in reverse (innermost outward),
- // advancing outermostStale past every ancestor whose Iceberg namespace no longer exists
- // and stopping at the first ancestor that still exists. outermostStale therefore ends up
- // as the outermost missing ancestor; everything from there down to the leaf is now stale
- // in Gravitino.
- //
- // An inner Iceberg namespace cannot exist unless all of its outer ancestors do, so an
- // ancestor missing from the catalog implies none of its descendants exist there
- // either. A single cascade delete of the outermost empty namespace therefore removes
- // it and every descendant Gravitino entity (the leaf plus the intermediate ancestors)
- // in one batched operation, rather than issuing one delete per target.
+ // Only the leaf namespace is dropped from the Iceberg catalog above. Dropping it may have
+ // also emptied its ancestors, so clean up every Gravitino schema entity whose Iceberg
+ // namespace no longer exists. An inner Iceberg namespace cannot exist unless all of its
+ // outer ancestors do, so the cleaner cascade-deletes the outermost stale namespace and
+ // every descendant entity in one batched operation.
//
// Ancestor entities are still only cleaned up when the underlying Iceberg catalog
// removes the empty parents on leaf-drop, which is catalog-implementation-dependent.
// For catalogs that keep empty parents, operators may need to drop them manually.
String separator = HierarchicalSchemaUtil.schemaSeparator();
- Namespace outermostStale = namespace;
- String namespaceName = String.join(separator, namespace.levels());
- List<String> ancestorNames =
- HierarchicalSchemaUtil.getAncestorNames(namespaceName, separator);
- for (int i = ancestorNames.size() - 1; i >= 0; i--) {
- Namespace ancestor = Namespace.of(ancestorNames.get(i).split(Pattern.quote(separator)));
- if (dispatcher.namespaceExists(context, ancestor)) {
- break;
- }
- outermostStale = ancestor;
- }
-
- EntityStore store = GravitinoEnv.getInstance().entityStore();
- if (store != null) {
- try {
- store.delete(
- IcebergIdentifierUtils.toGravitinoSchemaIdentifier(
- metalake, catalogName, outermostStale, separator),
- Entity.EntityType.SCHEMA,
- true);
- } catch (NoSuchEntityException ignore) {
- // Already gone.
- } catch (IOException ioe) {
- throw new RuntimeException("io exception when deleting schema entity", ioe);
- }
- }
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
Review Comment:
Fixed. `dropNamespace` now routes through `IcebergOrphanSchemaCleanup.bestEffortCleanUp`, the same guarded entry point as the table and view paths, so all three Iceberg hook drop paths share one implementation and the cleanup can never surface an error after the backend drop has already succeeded.
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergOrphanSchemaCleanup.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.service.dispatcher;
+
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.iceberg.common.utils.IcebergIdentifierUtils;
+import org.apache.gravitino.listener.api.event.IcebergRequestContext;
+import org.apache.gravitino.utils.HierarchicalSchemaUtil;
+import org.apache.gravitino.utils.SchemaEntityCleaner;
+import org.apache.iceberg.catalog.Namespace;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Shared best-effort cleanup of Gravitino schema entities that become orphaned when an Iceberg
+ * table or view drop empties their backing namespaces.
+ */
+final class IcebergOrphanSchemaCleanup {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IcebergOrphanSchemaCleanup.class);
+
+ private IcebergOrphanSchemaCleanup() {}
+
+ /**
+ * Removes Gravitino schema entities whose backing Iceberg namespace no longer exists after a
+ * table or view drop.
+ *
+ * <p>Best-effort: the primary drop has already succeeded, so any failure here is logged and
+ * swallowed rather than propagated to the caller.
+ *
+ * @param metalake the metalake the catalog belongs to
+ * @param namespaceDispatcher dispatcher used to probe whether a namespace still exists in the
+ * catalog
+ * @param context the Iceberg request context carrying the catalog name
+ * @param namespace the namespace of the dropped table or view
+ */
+ static void bestEffortCleanUp(
+ String metalake,
+ IcebergNamespaceOperationDispatcher namespaceDispatcher,
+ IcebergRequestContext context,
+ Namespace namespace) {
+ try {
+ String separator = HierarchicalSchemaUtil.schemaSeparator();
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ GravitinoEnv.getInstance().entityStore(),
+ IcebergIdentifierUtils.toGravitinoSchemaIdentifier(
+ metalake, context.catalogName(), namespace, separator),
+ true,
+ schemaIdent ->
+ namespaceDispatcher.namespaceExists(
+ context,
+ Namespace.of(
+ HierarchicalSchemaUtil.splitSchemaName(schemaIdent.name(), separator))));
+ } catch (RuntimeException e) {
Review Comment:
Addressed by unifying instead of removing: `dropNamespace` now also goes through `bestEffortCleanUp`, so all three Iceberg hook paths share this single helper rather than each inlining the setup + cleanup. That gives the wrapper a clear reason to exist (one guarded place that builds the identifier and swallows the unlikely setup-call failures) and removes the inconsistency in the namespace path.
##########
core/src/main/java/org/apache/gravitino/catalog/ViewOperationDispatcher.java:
##########
@@ -292,10 +293,33 @@ public boolean dropView(NameIdentifier ident) {
} catch (Exception e) {
throw new RuntimeException(e);
}
+ // Run unconditionally: an out-of-band drop may have left orphaned schema entities. The
+ // cleanup is best-effort and stops as soon as a schema still exists.
+ cleanUpOrphanedSchemaEntities(catalogIdent, schemaIdentifier);
return droppedFromCatalog;
});
}
+ /**
+ * Removes Gravitino schema entities whose backing catalog schema no longer exists, starting from
+ * {@code schemaIdentifier} and walking toward its outermost ancestor.
+ *
+ * @param catalogIdent the identifier of the catalog owning the schema
+ * @param schemaIdentifier the schema identifier to start the orphan check from
+ */
+ private void cleanUpOrphanedSchemaEntities(
Review Comment:
Done. Extracted the duplicated logic into a shared package-private helper `OrphanedSchemaCleanup` in the `catalog` package; both dispatchers now call `OrphanedSchemaCleanup.cleanUp(this, ...)`. I kept it out of `OperationDispatcher` itself, but the helper reuses the dispatcher's `protected` `store` and `doWithCatalog`, so there's now a single implementation.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3354188651
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -366,6 +367,17 @@ public boolean dropTable(NameIdentifier ident) {
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
Good catch. Moved the cleanup out of the `if (droppedFromCatalog)` guard so it now runs unconditionally in `dropTable`, and added a regression test (`testDropTableCleansUpOrphanSchemasWhenTableAlreadyGone`) for the out-of-band case where `dropTable` returns false but the orphaned schema entities must still be removed. This also aligns the core dispatchers with the Iceberg REST hook path, which already cleans up unconditionally.
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,6 +432,17 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
Fixed: `purgeTable` now runs the cleanup unconditionally as well. I also removed the early `return false` in the `NoSuchEntityException` branch, which previously short-circuited before cleanup even when the catalog purge succeeded; it now logs and falls through, returning the catalog result consistently with `dropTable`.
##########
core/src/main/java/org/apache/gravitino/catalog/ViewOperationDispatcher.java:
##########
@@ -292,6 +293,17 @@ public boolean dropView(NameIdentifier ident) {
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
Fixed: `dropView` now runs the cleanup unconditionally, covered by a regression test (`testDropViewCleansUpOrphanSchemasWhenViewAlreadyGone`) for the out-of-band case. The shared cleanup invocation is extracted into a `cleanUpOrphanedSchemaEntities` helper.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#issuecomment-4610363754
@mchades Could u help me take a look?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#issuecomment-4602562641
<!-- coverage-report -->
### Code Coverage Report
|Overall Project|66.8% **`+0.14%`**|:green_circle:|
|:-|:-|:-:|
|Files changed|76.37%|:green_circle:|
<br>
|Module|Coverage||
|:-|:-|:-:|
|aliyun|1.72%|:red_circle:|
|api|46.82%|:green_circle:|
|authorization-common|85.96%|:green_circle:|
|aws|3.66%|:red_circle:|
|azure|2.47%|:red_circle:|
|catalog-common|10.04%|:red_circle:|
|catalog-fileset|80.33%|:green_circle:|
|catalog-glue|66.08%|:green_circle:|
|catalog-hive|79.55%|:green_circle:|
|catalog-jdbc-clickhouse|80.02%|:green_circle:|
|catalog-jdbc-common|45.31%|:green_circle:|
|catalog-jdbc-doris|80.28%|:green_circle:|
|catalog-jdbc-hologres|54.03%|:green_circle:|
|catalog-jdbc-mysql|79.23%|:green_circle:|
|catalog-jdbc-oceanbase|78.38%|:green_circle:|
|catalog-jdbc-postgresql|82.29%|:green_circle:|
|catalog-jdbc-starrocks|78.51%|:green_circle:|
|catalog-kafka|77.01%|:green_circle:|
|catalog-lakehouse-generic|44.89%|:green_circle:|
|catalog-lakehouse-hudi|79.1%|:green_circle:|
|catalog-lakehouse-iceberg|85.66%|:green_circle:|
|catalog-lakehouse-paimon|79.29%|:green_circle:|
|catalog-model|77.72%|:green_circle:|
|cli|44.51%|:green_circle:|
|client-java|77.91%|:green_circle:|
|common|49.99%|:green_circle:|
|core|82.48% **`-0.03%`**|:green_circle:|
|filesystem-hadoop3|76.97%|:green_circle:|
|flink|0.0%|:red_circle:|
|flink-common|41.2%|:green_circle:|
|flink-runtime|0.0%|:red_circle:|
|gcp|14.12%|:red_circle:|
|hadoop-common|10.39%|:red_circle:|
|hive-metastore-common|53.26%|:green_circle:|
|iceberg-common|56.75%|:green_circle:|
|iceberg-rest-server|72.46% **`-0.92%`**|:green_circle:|
|idp-basic|85.99%|:green_circle:|
|integration-test-common|0.0%|:red_circle:|
|jobs|66.17%|:green_circle:|
|lance-common|20.83%|:red_circle:|
|lance-rest-server|60.27%|:green_circle:|
|lineage|53.02%|:green_circle:|
|optimizer|82.87%|:green_circle:|
|optimizer-api|21.95%|:red_circle:|
|server|85.73%|:green_circle:|
|server-common|73.13%|:green_circle:|
|spark|32.79%|:red_circle:|
|spark-common|39.75%|:red_circle:|
|trino-connector|39.44%|:red_circle:|
<details>
<summary>Files</summary>
|Module|File|Coverage||
|:-|:-|:-|:-:|
|core|[ViewOperationDispatcher.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/core/src/main/java/org/apache/gravitino/catalog/ViewOperationDispatcher.java)|83.27%|:green_circle:|
||[SchemaOperationDispatcher.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java)|82.29%|:green_circle:|
||[TableOperationDispatcher.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java)|80.49%|:green_circle:|
||[SchemaEntityCleaner.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/core/src/main/java/org/apache/gravitino/utils/SchemaEntityCleaner.java)|79.17%|:green_circle:|
|iceberg-rest-server|[IcebergNamespaceHookDispatcher.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceHookDispatcher.java)|92.42%|:green_circle:|
||[IcebergViewHookDispatcher.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewHookDispatcher.java)|86.49%|:green_circle:|
||[IcebergTableHookDispatcher.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableHookDispatcher.java)|80.37%|:green_circle:|
||[RESTService.java](https://github.com/qqqttt123/gravitino/blob/f278cd9b42dd015731e0509b035f0b536a7a70c2/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/RESTService.java)|0.0%|:red_circle:|
</details>
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3356571351
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceHookDispatcher.java:
##########
@@ -147,49 +144,26 @@ public void dropNamespace(IcebergRequestContext context, Namespace namespace) {
() -> {
dispatcher.dropNamespace(context, namespace);
- // Only the leaf namespace is dropped from the Iceberg catalog above. getAncestorNames
- // returns ancestors outermost-to-innermost, so we walk it in reverse (innermost outward),
- // advancing outermostStale past every ancestor whose Iceberg namespace no longer exists
- // and stopping at the first ancestor that still exists. outermostStale therefore ends up
- // as the outermost missing ancestor; everything from there down to the leaf is now stale
- // in Gravitino.
- //
- // An inner Iceberg namespace cannot exist unless all of its outer ancestors do, so an
- // ancestor missing from the catalog implies none of its descendants exist there
- // either. A single cascade delete of the outermost empty namespace therefore removes
- // it and every descendant Gravitino entity (the leaf plus the intermediate ancestors)
- // in one batched operation, rather than issuing one delete per target.
+ // Only the leaf namespace is dropped from the Iceberg catalog above. Dropping it may have
+ // also emptied its ancestors, so clean up every Gravitino schema entity whose Iceberg
+ // namespace no longer exists. An inner Iceberg namespace cannot exist unless all of its
+ // outer ancestors do, so the cleaner cascade-deletes the outermost stale namespace and
+ // every descendant entity in one batched operation.
//
// Ancestor entities are still only cleaned up when the underlying Iceberg catalog
// removes the empty parents on leaf-drop, which is catalog-implementation-dependent.
// For catalogs that keep empty parents, operators may need to drop them manually.
String separator = HierarchicalSchemaUtil.schemaSeparator();
- Namespace outermostStale = namespace;
- String namespaceName = String.join(separator, namespace.levels());
- List<String> ancestorNames =
- HierarchicalSchemaUtil.getAncestorNames(namespaceName, separator);
- for (int i = ancestorNames.size() - 1; i >= 0; i--) {
- Namespace ancestor = Namespace.of(ancestorNames.get(i).split(Pattern.quote(separator)));
- if (dispatcher.namespaceExists(context, ancestor)) {
- break;
- }
- outermostStale = ancestor;
- }
-
- EntityStore store = GravitinoEnv.getInstance().entityStore();
- if (store != null) {
- try {
- store.delete(
- IcebergIdentifierUtils.toGravitinoSchemaIdentifier(
- metalake, catalogName, outermostStale, separator),
- Entity.EntityType.SCHEMA,
- true);
- } catch (NoSuchEntityException ignore) {
- // Already gone.
- } catch (IOException ioe) {
- throw new RuntimeException("io exception when deleting schema entity", ioe);
- }
- }
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
Review Comment:
The table and view drop paths wrap their orphan-cleanup call in `IcebergOrphanSchemaCleanup.bestEffortCleanUp`, which adds a `try/catch(RuntimeException)` so any failure in the two setup calls (`schemaSeparator()`, `toGravitinoSchemaIdentifier()`) does not propagate back to the caller.
Here in `dropNamespace`, `SchemaEntityCleaner.deleteOrphanedSchemaEntities` is called directly inside the `doWithTreeLock` lambda without that guard. Those setup calls are unlikely to throw in a running server, but for consistency — and to ensure `dropNamespace` never returns an error when the actual drop already succeeded — consider wrapping in a try/catch or routing through `IcebergOrphanSchemaCleanup.bestEffortCleanUp` the same way the table and view paths do.
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,10 +424,33 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ // Run unconditionally: an out-of-band purge may have left orphaned schema entities. The
+ // cleanup is best-effort and stops as soon as a schema still exists.
+ cleanUpOrphanedSchemaEntities(catalogIdent, schemaIdentifier);
Review Comment:
`purgeTable` now runs the orphan-schema cleanup unconditionally (good), but the PR only adds regression tests for `dropTable`. Could you add a corresponding test for `purgeTable`? The cleanup path is structurally the same, but a separate test ensures a future regression (e.g. someone re-guarding `cleanUpOrphanedSchemaEntities` behind `if (droppedFromCatalog)`) would be caught.
##########
core/src/main/java/org/apache/gravitino/catalog/ViewOperationDispatcher.java:
##########
@@ -292,10 +293,33 @@ public boolean dropView(NameIdentifier ident) {
} catch (Exception e) {
throw new RuntimeException(e);
}
+ // Run unconditionally: an out-of-band drop may have left orphaned schema entities. The
+ // cleanup is best-effort and stops as soon as a schema still exists.
+ cleanUpOrphanedSchemaEntities(catalogIdent, schemaIdentifier);
return droppedFromCatalog;
});
}
+ /**
+ * Removes Gravitino schema entities whose backing catalog schema no longer exists, starting from
+ * {@code schemaIdentifier} and walking toward its outermost ancestor.
+ *
+ * @param catalogIdent the identifier of the catalog owning the schema
+ * @param schemaIdentifier the schema identifier to start the orphan check from
+ */
+ private void cleanUpOrphanedSchemaEntities(
Review Comment:
The private `cleanUpOrphanedSchemaEntities` here is identical to the one in `TableOperationDispatcher` (same parameters, same body, same semantics). Duplicated logic diverges silently — e.g. if a future PR adjusts `includeSelf` semantics or error handling in one class and misses the other.
Consider extracting it as a package-private static helper in `SchemaEntityCleaner` (or promoting the `doWithCatalog` pattern into a shared base) so both dispatchers share a single implementation.
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergOrphanSchemaCleanup.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.service.dispatcher;
+
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.iceberg.common.utils.IcebergIdentifierUtils;
+import org.apache.gravitino.listener.api.event.IcebergRequestContext;
+import org.apache.gravitino.utils.HierarchicalSchemaUtil;
+import org.apache.gravitino.utils.SchemaEntityCleaner;
+import org.apache.iceberg.catalog.Namespace;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Shared best-effort cleanup of Gravitino schema entities that become orphaned when an Iceberg
+ * table or view drop empties their backing namespaces.
+ */
+final class IcebergOrphanSchemaCleanup {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IcebergOrphanSchemaCleanup.class);
+
+ private IcebergOrphanSchemaCleanup() {}
+
+ /**
+ * Removes Gravitino schema entities whose backing Iceberg namespace no longer exists after a
+ * table or view drop.
+ *
+ * <p>Best-effort: the primary drop has already succeeded, so any failure here is logged and
+ * swallowed rather than propagated to the caller.
+ *
+ * @param metalake the metalake the catalog belongs to
+ * @param namespaceDispatcher dispatcher used to probe whether a namespace still exists in the
+ * catalog
+ * @param context the Iceberg request context carrying the catalog name
+ * @param namespace the namespace of the dropped table or view
+ */
+ static void bestEffortCleanUp(
+ String metalake,
+ IcebergNamespaceOperationDispatcher namespaceDispatcher,
+ IcebergRequestContext context,
+ Namespace namespace) {
+ try {
+ String separator = HierarchicalSchemaUtil.schemaSeparator();
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ GravitinoEnv.getInstance().entityStore(),
+ IcebergIdentifierUtils.toGravitinoSchemaIdentifier(
+ metalake, context.catalogName(), namespace, separator),
+ true,
+ schemaIdent ->
+ namespaceDispatcher.namespaceExists(
+ context,
+ Namespace.of(
+ HierarchicalSchemaUtil.splitSchemaName(schemaIdent.name(), separator))));
+ } catch (RuntimeException e) {
Review Comment:
`SchemaEntityCleaner.deleteOrphanedSchemaEntities` already wraps its entire body in `catch(Exception)` and swallows all failures, so nothing can escape it. The outer `catch(RuntimeException)` here can only be reached by the two setup lines above it (`schemaSeparator()` and `toGravitinoSchemaIdentifier()`), which are extremely unlikely to throw in a live server.
Given that, this class is mostly a thin wrapper that adds one extra log entry. Alternatively: move the try/catch directly around the two setup calls, then let both `IcebergTableHookDispatcher` and `IcebergViewHookDispatcher` call `SchemaEntityCleaner.deleteOrphanedSchemaEntities` directly — the same pattern `IcebergNamespaceHookDispatcher.dropNamespace` now uses — and remove this indirection entirely.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3356059508
##########
core/src/main/java/org/apache/gravitino/utils/SchemaEntityCleaner.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.utils;
+
+import static org.apache.gravitino.Entity.EntityType.SCHEMA;
+
+import java.util.ArrayList;
+import java.util.function.Predicate;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Utility for deleting schema entities whose backing catalog schemas no longer exist. */
+public final class SchemaEntityCleaner {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SchemaEntityCleaner.class);
+
+ private SchemaEntityCleaner() {}
+
+ /**
+ * Deletes the outermost orphaned schema entity and its descendants from the store.
+ *
+ * <p>Candidates are checked from the starting schema toward the outermost ancestor. The first
+ * candidate that still exists in the catalog stops the walk; every more-specific candidate
+ * checked before that point is stale. A single cascade delete on the outermost stale schema
+ * removes it and all descendant schema entities.
+ *
+ * <p>This is best-effort: callers invoke it after the primary drop has already succeeded, so any
+ * failure (a store error or a catalog existence probe failure) is logged and swallowed rather
+ * than propagated. The orphan, if any, is retried on a subsequent drop.
+ *
+ * @param store the Gravitino entity store; if {@code null}, this method is a no-op
+ * @param schemaIdent the schema identifier to start checking from
+ * @param includeSelf whether to check {@code schemaIdent} itself before checking ancestors
+ * @param schemaExists predicate reporting whether a schema still exists in the underlying catalog
+ */
+ public static void deleteOrphanedSchemaEntities(
+ EntityStore store,
+ NameIdentifier schemaIdent,
+ boolean includeSelf,
+ Predicate<NameIdentifier> schemaExists) {
+ if (store == null) {
+ return;
+ }
+
+ try {
+ String separator = HierarchicalSchemaUtil.schemaSeparator();
+ ArrayList<String> schemaNames =
+ new ArrayList<>(HierarchicalSchemaUtil.allScopes(schemaIdent.name(), separator));
+ if (!includeSelf && !schemaNames.isEmpty()) {
+ schemaNames.remove(0);
+ }
+
+ NameIdentifier outermostOrphan = null;
+ for (String schemaName : schemaNames) {
+ NameIdentifier candidate = NameIdentifier.of(schemaIdent.namespace(), schemaName);
+ if (schemaExists.test(candidate)) {
Review Comment:
Because the external will delete the namespace automatically after table or view drop.
We must rely on the underlying catalo behaviour.
For example,
we create a namspace `a.b.c`.
we create a table `a.b.table1`.
we drop a namespace `a.b.c`.
We drop a table `a.b.table1`.
Our entity store still has the namespace `a.b`, but underlying catalog doesn't have `a.b`.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3354188789
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,6 +432,17 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
+ }
Review Comment:
Updated: `purgeTable` now runs the cleanup unconditionally (the `if (droppedFromCatalog)` guard is removed), same as `dropTable`. The early `return false` in the `NoSuchEntityException` branch is kept, so when the store entity is already gone `purgeTable` still returns false as before.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11262] fix: Clean up orphaned schema entities after table or view drop [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11362:
URL: https://github.com/apache/gravitino/pull/11362#discussion_r3348195890
##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -420,6 +432,17 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep
} catch (Exception e) {
throw new RuntimeException(e);
}
+ if (droppedFromCatalog) {
+ SchemaEntityCleaner.deleteOrphanedSchemaEntities(
+ store,
+ schemaIdentifier,
+ true,
+ schemaIdent ->
+ doWithCatalog(
+ catalogIdent,
+ c -> c.doWithSchemaOps(s -> s.schemaExists(schemaIdent)),
+ RuntimeException.class));
Review Comment:
Iceberg doesn't support the similar operation now. But this improvement is discussing. Maybe we can optimize this point in the feature.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org