Skip to content

Commit

Permalink
[AMORO-2180]: Remove existed database/table check when delete externa…
Browse files Browse the repository at this point in the history
…l catalog (#2182)

* Fix delete catalog bug

* Fix delete catalog bug

* Add catalog delete check
  • Loading branch information
shidayang authored Oct 24, 2023
1 parent 1d134d7 commit f1b911b
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -537,24 +539,24 @@ 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 */
public void deleteCatalog(Context ctx) {
String catalogName = ctx.pathParam("catalogName");
Preconditions.checkArgument(
StringUtils.isNotEmpty(ctx.pathParam("catalogName")), "Catalog name is empty!");
List<String> 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 */
Expand Down

0 comments on commit f1b911b

Please sign in to comment.