This is an automated email from the ASF dual-hosted git repository.
yuqi1129 pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new 5ce2608d2a [#14714] fix(core): preserve table registrations when a
drop reports no table on branch-1.3 (#14716)
5ce2608d2a is described below
commit 5ce2608d2a6a4c62ba821fa5a13c8522fc43e20e
Author: Qi Yu <[email protected]>
AuthorDate: Fri Nov 6 16:54:43 2026 +0800
[#14714] fix(core): preserve table registrations when a drop reports no
table on branch-1.3 (#14716)
### What changes were proposed in this pull request?
Port the table part of #12235 to branch-1.3:
`TableOperationDispatcher.dropTable` and `purgeTable` delete the table
registration of an external table only when the catalog reports that it
dropped the table. Orphaned-schema cleanup still runs.
### Why are the changes needed?
A `false` result does not prove that the table is gone. The catalog user
may be unable to see it (for example a PostgreSQL schema without USAGE,
or an Oracle table whose SELECT privilege was revoked), or it may have
been renamed concurrently. Deleting the registration then removed the
table's tags and privileges, including DENY privileges, while the table
still existed. Main already behaves this way.
Fixes #14714
### Does this PR introduce _any_ user-facing change?
Yes. After a table is dropped outside Gravitino, a Gravitino drop of it
returns `false` and keeps the stale registration. Before this change,
that drop also removed the registration, which some users relied on
before recreating a table with the same name.
### How was this patch tested?
- `TestTableOperationDispatcher` (39 cases) passes; the drop and purge
cases of a table missing from the catalog now also assert that the table
entity is kept.
- `TestManagedTableOperations`, `TestTableNormalizeDispatcher` and
`TestTableEvent` pass.
- With the dispatcher change reverted, the 2 updated cases fail.
---
.../catalog/TableOperationDispatcher.java | 56 +++++++++++-----------
.../catalog/TestTableOperationDispatcher.java | 13 +++--
2 files changed, 35 insertions(+), 34 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
b/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
index d3544e560d..786550ff1f 100644
---
a/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
+++
b/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
@@ -426,20 +426,19 @@ public class TableOperationDispatcher extends
OperationDispatcher implements Tab
return droppedFromCatalog;
}
- // For unmanaged table, it could happen that the table:
- // 1. Is not found in the catalog (dropped directly from underlying
sources)
- // 2. Is found in the catalog but not in the store (not managed by
Gravitino)
- // 3. Is found in the catalog and the store (managed by Gravitino)
- // 4. Neither found in the catalog nor in the store.
- // In all situations, we try to delete the table from the store, but
we don't take the
- // return value of the store operation into account. We only take
the return value of the
- // catalog into account.
- try {
- store.delete(ident, TABLE);
- } catch (NoSuchEntityException e) {
- LOG.warn("The table to be dropped does not exist in the store:
{}", ident, e);
- } catch (Exception e) {
- throw new RuntimeException(e);
+ // A false result is ambiguous: the external table may have been
renamed or dropped out of
+ // band, or the catalog user may be unable to see it. Preserve the
registration, because
+ // deleting it would lose Gravitino-only metadata such as tags and
privileges, including
+ // DENY privileges, of a table that may still exist. A true
out-of-band drop can therefore
+ // leave a stale registration that requires separate cleanup.
+ if (droppedFromCatalog) {
+ try {
+ store.delete(ident, TABLE);
+ } catch (NoSuchEntityException e) {
+ LOG.warn("The table to be dropped does not exist in the store:
{}", ident, e);
+ } 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.
@@ -482,21 +481,20 @@ public class TableOperationDispatcher extends
OperationDispatcher implements Tab
return droppedFromCatalog;
}
- // For unmanaged table, it could happen that the table:
- // 1. Is not found in the catalog (dropped directly from underlying
sources)
- // 2. Is found in the catalog but not in the store (not managed by
Gravitino)
- // 3. Is found in the catalog and the store (managed by Gravitino)
- // 4. Neither found in the catalog nor in the store.
- // In all situations, we try to delete the table from the store, but
we don't take the
- // return value of the store operation into account. We only take
the return value of the
- // catalog into account.
- try {
- store.delete(ident, TABLE);
- } catch (NoSuchEntityException e) {
- LOG.warn("The table to be purged does not exist in the store: {}",
ident, e);
- return false;
- } catch (Exception e) {
- throw new RuntimeException(e);
+ // A false result is ambiguous: the external table may have been
renamed or dropped out of
+ // band, or the catalog user may be unable to see it. Preserve the
registration, because
+ // deleting it would lose Gravitino-only metadata such as tags and
privileges, including
+ // DENY privileges, of a table that may still exist. A true
out-of-band drop can therefore
+ // leave a stale registration that requires separate cleanup.
+ if (droppedFromCatalog) {
+ try {
+ store.delete(ident, TABLE);
+ } catch (NoSuchEntityException e) {
+ LOG.warn("The table to be purged does not exist in the store:
{}", ident, e);
+ return false;
+ } 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.
diff --git
a/core/src/test/java/org/apache/gravitino/catalog/TestTableOperationDispatcher.java
b/core/src/test/java/org/apache/gravitino/catalog/TestTableOperationDispatcher.java
index 39cb752649..fec1538e2d 100644
---
a/core/src/test/java/org/apache/gravitino/catalog/TestTableOperationDispatcher.java
+++
b/core/src/test/java/org/apache/gravitino/catalog/TestTableOperationDispatcher.java
@@ -1090,9 +1090,11 @@ public class TestTableOperationDispatcher extends
TestOperationDispatcher {
Assertions.assertFalse(testCatalogOperations.schemaExists(schemaIdent));
Assertions.assertFalse(testCatalogOperations.schemaExists(ancestorIdent));
- // dropTable returns false because the table is already gone from the
catalog, but the
- // orphaned schema entities must still be cleaned up.
+ // dropTable returns false because the table is already gone from the
catalog. Preserve the
+ // table entity because the same result can be caused by a concurrent
rename or by a catalog
+ // user that cannot see the table, while still cleaning up orphaned schema
entities.
Assertions.assertFalse(tableOperationDispatcher.dropTable(tableIdent));
+ Assertions.assertTrue(entityStore.exists(tableIdent, TABLE));
Assertions.assertFalse(entityStore.exists(schemaIdent, SCHEMA));
Assertions.assertFalse(entityStore.exists(ancestorIdent, SCHEMA));
}
@@ -1133,10 +1135,11 @@ public class TestTableOperationDispatcher extends
TestOperationDispatcher {
Assertions.assertFalse(testCatalogOperations.schemaExists(schemaIdent));
Assertions.assertFalse(testCatalogOperations.schemaExists(ancestorIdent));
- // purgeTable returns false because the table is already gone from the
catalog, but the
- // orphaned schema entities must still be cleaned up. A regression that
re-guards the cleanup
- // behind the catalog drop result would leave the stale schema entities
behind.
+ // purgeTable returns false because the table is already gone from the
catalog. Preserve the
+ // table entity because the same result can be caused by a concurrent
rename or by a catalog
+ // user that cannot see the table, while still cleaning up orphaned schema
entities.
Assertions.assertFalse(tableOperationDispatcher.purgeTable(tableIdent));
+ Assertions.assertTrue(entityStore.exists(tableIdent, TABLE));
Assertions.assertFalse(entityStore.exists(schemaIdent, SCHEMA));
Assertions.assertFalse(entityStore.exists(ancestorIdent, SCHEMA));
}