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

jshao pushed a commit to branch branch-0.8
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-0.8 by this push:
     new 3576c39fa3 [#6667]fix(core):can force delete invalid catalog (#6679)
3576c39fa3 is described below

commit 3576c39fa33c392943796035417a066d7889719a
Author: youze Liang <[email protected]>
AuthorDate: Wed Mar 12 14:28:18 2025 +0800

    [#6667]fix(core):can force delete invalid catalog (#6679)
    
    ### What changes were proposed in this pull request?
    
    #6667
    
    ### Why are the changes needed?
    
    Fix: #6667
    
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    add a new test testForceDropCatalog in TestCatalogManager
---
 .../apache/gravitino/catalog/CatalogManager.java   |  2 +-
 .../gravitino/catalog/TestCatalogManager.java      | 31 ++++++++++++++++++++++
 2 files changed, 32 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 a3d55d4a72..7349d5acee 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
@@ -674,7 +674,7 @@ public class CatalogManager implements CatalogDispatcher, 
Closeable {
           store.list(schemaNamespace, SchemaEntity.class, EntityType.SCHEMA);
       CatalogEntity catalogEntity = store.get(ident, EntityType.CATALOG, 
CatalogEntity.class);
 
-      if (containsUserCreatedSchemas(schemaEntities, catalogEntity, 
catalogWrapper) && !force) {
+      if (!force && containsUserCreatedSchemas(schemaEntities, catalogEntity, 
catalogWrapper)) {
         throw new NonEmptyCatalogException(
             "Catalog %s has schemas, please drop them first or use force 
option", 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 d11bff572f..8f268056b1 100644
--- a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
+++ b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
@@ -19,6 +19,7 @@
 package org.apache.gravitino.catalog;
 
 import static org.apache.gravitino.StringIdentifier.ID_KEY;
+import static org.mockito.ArgumentMatchers.any;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
@@ -40,10 +41,12 @@ import 
org.apache.gravitino.exceptions.NoSuchCatalogException;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
 import org.apache.gravitino.meta.AuditInfo;
 import org.apache.gravitino.meta.BaseMetalake;
+import org.apache.gravitino.meta.SchemaEntity;
 import org.apache.gravitino.meta.SchemaVersion;
 import org.apache.gravitino.storage.RandomIdGenerator;
 import org.apache.gravitino.storage.memory.TestMemoryEntityStore;
 import 
org.apache.gravitino.storage.memory.TestMemoryEntityStore.InMemoryEntityStore;
+import org.apache.gravitino.utils.PrincipalUtils;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
@@ -472,6 +475,34 @@ public class TestCatalogManager {
     Assertions.assertNull(catalogManager.catalogCache.getIfPresent(ident));
   }
 
+  @Test
+  public void testForceDropCatalog() throws Exception {
+    NameIdentifier ident = NameIdentifier.of("metalake", "test41");
+    Map<String, String> props =
+        ImmutableMap.of("provider", "test", "key1", "value1", "key2", 
"value2");
+    String comment = "comment";
+    catalogManager.createCatalog(ident, Catalog.Type.RELATIONAL, provider, 
comment, props);
+    SchemaEntity schemaEntity =
+        SchemaEntity.builder()
+            .withId(RandomIdGenerator.INSTANCE.nextId())
+            .withName("test_schema1")
+            .withNamespace(Namespace.of("metalake", "test41"))
+            .withAuditInfo(
+                AuditInfo.builder()
+                    
.withCreator(PrincipalUtils.getCurrentPrincipal().getName())
+                    .withCreateTime(Instant.now())
+                    .build())
+            .build();
+    entityStore.put(schemaEntity);
+    CatalogManager.CatalogWrapper catalogWrapper =
+        Mockito.mock(CatalogManager.CatalogWrapper.class);
+    
Mockito.doReturn(catalogWrapper).when(catalogManager).loadCatalogAndWrap(ident);
+    Mockito.doThrow(new RuntimeException("Failed connect"))
+        .when(catalogWrapper)
+        .doWithSchemaOps(any());
+    Assertions.assertTrue(catalogManager.dropCatalog(ident, true));
+  }
+
   @Test
   void testAlterMutableProperties() {
     NameIdentifier ident = NameIdentifier.of("metalake", "test41");

Reply via email to