Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6667]fix(core):can force delete invalid catalog #6679

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public boolean dropCatalog(NameIdentifier ident, boolean force)
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,10 +41,12 @@
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;
Expand Down Expand Up @@ -472,6 +475,34 @@ public void testDropCatalog() {
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");
Expand Down