From f1b911b65dea01f2881a646144c9ab9354a2126a Mon Sep 17 00:00:00 2001 From: shidayang <530847445@qq.com> Date: Tue, 24 Oct 2023 19:13:06 +0800 Subject: [PATCH] [AMORO-2180]: Remove existed database/table check when delete external catalog (#2182) * Fix delete catalog bug * Fix delete catalog bug * Add catalog delete check --- .../controller/CatalogController.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/ams/server/src/main/java/com/netease/arctic/server/dashboard/controller/CatalogController.java b/ams/server/src/main/java/com/netease/arctic/server/dashboard/controller/CatalogController.java index 4781a2e993..45fc03417e 100644 --- a/ams/server/src/main/java/com/netease/arctic/server/dashboard/controller/CatalogController.java +++ b/ams/server/src/main/java/com/netease/arctic/server/dashboard/controller/CatalogController.java @@ -48,14 +48,12 @@ import static com.netease.arctic.ams.api.properties.CatalogMetaProperties.STORAGE_CONFIGS_VALUE_TYPE_S3; import static com.netease.arctic.ams.api.properties.CatalogMetaProperties.TABLE_FORMATS; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.netease.arctic.ams.api.CatalogMeta; import com.netease.arctic.ams.api.TableFormat; import com.netease.arctic.ams.api.properties.CatalogMetaProperties; import com.netease.arctic.server.ArcticManagementConf; +import com.netease.arctic.server.catalog.InternalCatalog; +import com.netease.arctic.server.catalog.ServerCatalog; import com.netease.arctic.server.dashboard.PlatformFileManager; import com.netease.arctic.server.dashboard.model.CatalogRegisterInfo; import com.netease.arctic.server.dashboard.model.CatalogSettingInfo; @@ -70,6 +68,10 @@ import org.apache.commons.lang.StringUtils; import org.apache.iceberg.CatalogProperties; import org.apache.iceberg.relocated.com.google.common.base.Objects; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; import org.apache.iceberg.relocated.com.google.common.collect.Sets; import org.apache.paimon.options.CatalogOptions; @@ -537,10 +539,15 @@ public void updateCatalog(Context ctx) { /** Check whether we could delete the catalog */ public void catalogDeleteCheck(Context ctx) { + String catalogName = ctx.pathParam("catalogName"); Preconditions.checkArgument( StringUtils.isNotEmpty(ctx.pathParam("catalogName")), "Catalog name is empty!"); - int tblCount = tableService.listManagedTables(ctx.pathParam("catalogName")).size(); - ctx.json(OkResponse.of(tblCount == 0)); + ServerCatalog serverCatalog = tableService.getServerCatalog(catalogName); + if (serverCatalog instanceof InternalCatalog) { + ctx.json(OkResponse.of(tableService.listManagedTables(catalogName).size() == 0)); + } else { + ctx.json(OkResponse.of(true)); + } } /** Delete some catalog and information associate with the catalog */ @@ -548,13 +555,8 @@ public void deleteCatalog(Context ctx) { String catalogName = ctx.pathParam("catalogName"); Preconditions.checkArgument( StringUtils.isNotEmpty(ctx.pathParam("catalogName")), "Catalog name is empty!"); - List dbs = tableService.listDatabases(catalogName); - if (dbs != null && dbs.isEmpty()) { - tableService.dropCatalog(catalogName); - ctx.json(OkResponse.of("OK")); - } else { - throw new RuntimeException("Some tables in catalog!"); - } + tableService.dropCatalog(catalogName); + ctx.json(OkResponse.of("OK")); } /** Construct a url */