This is an automated email from the ASF dual-hosted git repository.

jerryshao 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 c4c69a7785 [Cherry-pick to branch-1.3] [#14835] fix(core): Keep a 
disabled catalog not in use after a refused drop (#14836) (#14851)
c4c69a7785 is described below

commit c4c69a7785d31c8d293319f174592f5786824496
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Nov 11 11:16:41 2026 +0800

    [Cherry-pick to branch-1.3] [#14835] fix(core): Keep a disabled catalog not 
in use after a refused drop (#14836) (#14851)
    
    **Cherry-pick Information:**
    - Original commit: 411c1d4e1cb772e6f53596c36fcf07162c5f2bed
    - Target branch: `branch-1.3`
    - Status: ✅ Conflicts resolved
    - Note: The test uses the three-argument `CatalogManager` constructor
    because `SecretManager` does not exist on this branch.
    
    ---------
    
    Co-authored-by: Yuhui <[email protected]>
    Co-authored-by: diqiu50 <[email protected]>
---
 .../apache/gravitino/catalog/CatalogManager.java   |  6 +-
 .../gravitino/catalog/TestCatalogManager.java      | 66 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java 
b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
index 8eb9fc1737..5c59d7d274 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
@@ -1358,7 +1358,6 @@ public class CatalogManager implements CatalogDispatcher, 
Closeable {
                 LOG.warn("Failed to clean up resources for dropped catalog 
{}", ident, e);
               }
             }
-            catalogCache.invalidate(ident);
             return deleted;
 
           } catch (NoSuchMetalakeException | NoSuchCatalogException ignored) {
@@ -1367,6 +1366,11 @@ public class CatalogManager implements 
CatalogDispatcher, Closeable {
             throw e;
           } catch (Exception e) {
             throw new RuntimeException(e);
+          } finally {
+            // Discard the wrapper on every outcome. Operations initialized 
during the drop skip the
+            // catalog in-use check, so a refused or failed drop must not 
leave them cached for
+            // later calls on a disabled catalog.
+            catalogCache.invalidate(ident);
           }
         });
   }
diff --git 
a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java 
b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
index 3ec95226e0..a98eb4d989 100644
--- a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
+++ b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
@@ -79,6 +79,7 @@ import org.apache.gravitino.exceptions.NoSuchCatalogException;
 import org.apache.gravitino.exceptions.NoSuchEntityException;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
 import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NonEmptyCatalogException;
 import org.apache.gravitino.lock.LockManager;
 import org.apache.gravitino.lock.LockType;
 import org.apache.gravitino.lock.TreeLockUtils;
@@ -1611,6 +1612,52 @@ public class TestCatalogManager {
     Assertions.assertTrue(entityStore.exists(ident, EntityType.CATALOG));
   }
 
+  @Test
+  void testRefusedDropKeepsDisabledCatalogNotInUse() throws Exception {
+    InMemoryEntityStore store = new InMemoryEntityStore();
+    store.initialize(config);
+    store.put(metalakeEntity, true);
+    CatalogManager manager = new CatalogManager(config, store, new 
RandomIdGenerator());
+
+    NameIdentifier ident = NameIdentifier.of("metalake", "refused_drop");
+    Map<String, String> props =
+        ImmutableMap.of(
+            "provider",
+            "test",
+            PROPERTY_KEY1,
+            "value1",
+            PROPERTY_KEY2,
+            "value2",
+            PROPERTY_KEY5_PREFIX + "1",
+            "value3",
+            BaseCatalog.CATALOG_OPERATION_IMPL,
+            SingleSchemaCatalogOperations.class.getName());
+    manager.createCatalog(ident, Catalog.Type.RELATIONAL, provider, "comment", 
props);
+    store.put(
+        SchemaEntity.builder()
+            .withId(RandomIdGenerator.INSTANCE.nextId())
+            .withName(SingleSchemaCatalogOperations.SCHEMA_NAME)
+            .withNamespace(Namespace.of("metalake", "refused_drop"))
+            .withAuditInfo(
+                AuditInfo.builder()
+                    
.withCreator(PrincipalUtils.getCurrentPrincipal().getName())
+                    .withCreateTime(Instant.now())
+                    .build())
+            .build());
+
+    manager.disableCatalog(ident);
+    Assertions.assertThrows(
+        NonEmptyCatalogException.class, () -> manager.dropCatalog(ident, 
false));
+
+    // The operations built while checking schemas for the refused drop must 
not be reused by
+    // later calls on the disabled catalog.
+    Namespace schemaNs = Namespace.of("metalake", "refused_drop");
+    Assertions.assertThrows(
+        CatalogNotInUseException.class,
+        () -> manager.loadCatalogAndWrap(ident).doWithSchemaOps(ops -> 
ops.listSchemas(schemaNs)));
+    manager.close();
+  }
+
   @Test
   public void testForceDropCatalog() throws Exception {
     NameIdentifier ident = NameIdentifier.of("metalake", "test41");
@@ -2126,4 +2173,23 @@ public class TestCatalogManager {
         PROPERTY_KEY5_PREFIX + "1",
         "value3");
   }
+
+  /** Catalog operations whose backend always holds one user-created schema. */
+  public static class SingleSchemaCatalogOperations extends 
TestCatalogOperations {
+    static final String SCHEMA_NAME = "existing_schema";
+
+    public SingleSchemaCatalogOperations() {
+      super(ImmutableMap.of());
+    }
+
+    @Override
+    public NameIdentifier[] listSchemas(Namespace namespace) {
+      return new NameIdentifier[] {NameIdentifier.of(namespace, SCHEMA_NAME)};
+    }
+
+    @Override
+    public Schema loadSchema(NameIdentifier ident) {
+      return Mockito.mock(Schema.class);
+    }
+  }
 }

Reply via email to