This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 20718cff26 [#6667]fix(core):can force delete invalid catalog (#6669)
20718cff26 is described below
commit 20718cff26a4467119aea2b2caa552544887d328
Author: youze Liang <[email protected]>
AuthorDate: Tue Mar 11 20:12:49 2025 +0800
[#6667]fix(core):can force delete invalid catalog (#6669)
### What changes were proposed in this pull request?
(Please outline the changes and how this PR fixes the issue.)
#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 | 4 +--
.../gravitino/catalog/TestCatalogManager.java | 31 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
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 8ff2e9f624..00397ad254 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
@@ -729,8 +729,8 @@ 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 009c797894..af4dee8654 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");