World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#3075] fix(core): Fix issues schema entity cannot delete if the schema is not found from underlying sources (#3095)
Jerry Shaod2d1450a25ac
diff --git a/api/src/main/java/com/datastrato/gravitino/rel/SupportsSchemas.java b/api/src/main/java/com/datastrato/gravitino/rel/SupportsSchemas.javaindex e490aa7648..2c47c30411 100644--- a/api/src/main/java/com/datastrato/gravitino/rel/SupportsSchemas.java+++ b/api/src/main/java/com/datastrato/gravitino/rel/SupportsSchemas.java@@ -108,7 +108,8 @@ public interface SupportsSchemas {** @param ident The name identifier of the schema.* @param cascade If true, recursively drop all objects within the schema.- * @return True if the schema exists and is dropped successfully, false otherwise.+ * @return True if the schema exists and is dropped successfully, false if the schema doesn't+ * exist.* @throws NonEmptySchemaException If the schema is not empty and cascade is false.*/boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException;diff --git a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.javaindex 22bd93f18f..c9c61cb616 100644--- a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java@@ -502,6 +502,47 @@ public class HadoopCatalogIT extends AbstractIT {Assertions.assertEquals(0, newFileset.properties().size(), "properties should be removed");}+ @Test+ public void testDropCatalogWithEmptySchema() {+ String catalogName =+ GravitinoITUtils.genRandomName("test_drop_catalog_with_empty_schema_catalog");+ // Create a catalog without specifying location.+ Catalog filesetCatalog =+ metalake.createCatalog(+ NameIdentifier.of(metalakeName, catalogName),+ Catalog.Type.FILESET,+ provider,+ "comment",+ ImmutableMap.of());++ // Create a schema without specifying location.+ String schemaName =+ GravitinoITUtils.genRandomName("test_drop_catalog_with_empty_schema_schema");+ filesetCatalog+ .asSchemas()+ .createSchema(+ NameIdentifier.of(metalakeName, catalogName, schemaName), "comment", ImmutableMap.of());++ // Drop the empty schema.+ boolean dropped =+ filesetCatalog+ .asSchemas()+ .dropSchema(NameIdentifier.of(metalakeName, catalogName, schemaName), true);+ Assertions.assertTrue(dropped, "schema should be dropped");+ Assertions.assertFalse(+ filesetCatalog+ .asSchemas()+ .schemaExists(NameIdentifier.of(metalakeName, catalogName, schemaName)),+ "schema should not be exists");++ // Drop the catalog.+ dropped = metalake.dropCatalog(NameIdentifier.of(metalakeName, catalogName));+ Assertions.assertTrue(dropped, "catalog should be dropped");+ Assertions.assertFalse(+ metalake.catalogExists(NameIdentifier.of(metalakeName, catalogName)),+ "catalog should not be exists");+ }+private Fileset createFileset(String filesetName,String comment,diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.javaindex 46c3a10564..bd12d29b12 100644--- a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java@@ -1563,6 +1563,72 @@ public class CatalogHiveIT extends AbstractIT {hdfs.listStatus(tableDirectory).length > 0, "The table should not be empty");}+ @Test+ public void testRemoveNonExistTable() throws TException, InterruptedException {+ Column[] columns = createColumns();+ catalog+ .asTableCatalog()+ .createTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, tableName),+ columns,+ TABLE_COMMENT,+ ImmutableMap.of(TABLE_TYPE, EXTERNAL_TABLE.name().toLowerCase(Locale.ROOT)),+ new Transform[] {Transforms.identity(columns[2].name())});++ // Directly drop table from hive metastore.+ hiveClientPool.run(+ client -> {+ client.dropTable(schemaName, tableName, true, false, false);+ return null;+ });++ // Drop table from catalog, drop non-exist table should return false;+ Assertions.assertFalse(+ catalog+ .asTableCatalog()+ .dropTable(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName)),+ "The table should not be found in the catalog");++ Assertions.assertFalse(+ catalog+ .asTableCatalog()+ .tableExists(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName)),+ "The table should not be found in the catalog");+ }++ @Test+ public void testPurgeNonExistTable() throws TException, InterruptedException {+ Column[] columns = createColumns();+ catalog+ .asTableCatalog()+ .createTable(+ NameIdentifier.of(metalakeName, catalogName, schemaName, tableName),+ columns,+ TABLE_COMMENT,+ ImmutableMap.of(TABLE_TYPE, EXTERNAL_TABLE.name().toLowerCase(Locale.ROOT)),+ new Transform[] {Transforms.identity(columns[2].name())});++ // Directly drop table from hive metastore.+ hiveClientPool.run(+ client -> {+ client.dropTable(schemaName, tableName, true, false, true);+ return null;+ });++ // Drop table from catalog, drop non-exist table should return false;+ Assertions.assertFalse(+ catalog+ .asTableCatalog()+ .purgeTable(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName)),+ "The table should not be found in the catalog");++ Assertions.assertFalse(+ catalog+ .asTableCatalog()+ .tableExists(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName)),+ "The table should not be found in the catalog");+ }+@Testvoid testCustomCatalogOperations() {String catalogName = "custom_catalog";diff --git a/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java b/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.javaindex e98b918cf7..e7854705b8 100644--- a/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java+++ b/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java@@ -309,7 +309,7 @@ public class CatalogKafkaIT extends AbstractIT {}@Test- public void testDropTopic() {+ public void testDropTopic() throws ExecutionException, InterruptedException {String topicName = GravitinoITUtils.genRandomName("test-topic");Topic createdTopic =catalog@@ -332,6 +332,30 @@ public class CatalogKafkaIT extends AbstractIT {Assertions.assertThrows(ExecutionException.class, () -> getTopicDesc(createdTopic.name()));Assertions.assertTrue(ex.getMessage().contains("This server does not host this topic-partition"));++ // verify dropping non-exist topic+ String topicName1 = GravitinoITUtils.genRandomName("test-topic");+ catalog+ .asTopicCatalog()+ .createTopic(+ NameIdentifier.of(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME, topicName1),+ "comment",+ null,+ Collections.emptyMap());++ adminClient.deleteTopics(Collections.singleton(topicName1)).all().get();+ boolean dropped1 =+ catalog+ .asTopicCatalog()+ .dropTopic(+ NameIdentifier.of(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME, topicName1));+ Assertions.assertFalse(dropped1, "Should return false when dropping non-exist topic");+ Assertions.assertFalse(+ catalog+ .asTopicCatalog()+ .topicExists(+ NameIdentifier.of(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME, topicName1)),+ "Topic should not exist after dropping");}private void assertTopicWithKafka(Topic createdTopic)diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.javaindex 986de6bfa0..57c75681e0 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java@@ -14,6 +14,7 @@ import com.datastrato.gravitino.StringIdentifier;import com.datastrato.gravitino.connector.HasPropertyMetadata;import com.datastrato.gravitino.connector.capability.Capability;import com.datastrato.gravitino.exceptions.NoSuchCatalogException;+import com.datastrato.gravitino.exceptions.NoSuchEntityException;import com.datastrato.gravitino.exceptions.NoSuchSchemaException;import com.datastrato.gravitino.exceptions.NonEmptySchemaException;import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;@@ -292,25 +293,41 @@ public class SchemaOperationDispatcher extends OperationDispatcher implements Sc** @param ident The identifier of the schema to be dropped.* @param cascade If true, drops all tables within the schema as well.- * @return True if the schema was successfully dropped, false otherwise.+ * @return True if the schema was successfully dropped, false if the schema doesn't exist.* @throws NonEmptySchemaException If the schema contains tables and cascade is set to false.+ * @throws RuntimeException If an error occurs while dropping the schema.*/@Overridepublic boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {- boolean dropped =+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);+ boolean droppedFromCatalog =doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdent,c -> c.doWithSchemaOps(s -> s.dropSchema(ident, cascade)),- NonEmptySchemaException.class);-- if (!dropped) {- return false;- }+ NonEmptySchemaException.class,+ RuntimeException.class);+ // For unmanaged schema, it could happen that the schema:+ // 1. Is not found in the catalog (dropped directly from underlying sources)+ // 2. Is found in the catalog but not in the store (not managed by Gravitino)+ // 3. Is found in the catalog and the store (managed by Gravitino)+ // 4. Neither found in the catalog nor in the store.+ // In all situations, we try to delete the schema from the store, but we don't take the+ // return value of the store operation into account. We only take the return value of the+ // catalog into account.+ //+ // For managed schema, we should take the return value of the store operation into account.+ boolean droppedFromStore = false;try {- return store.delete(ident, SCHEMA, cascade);+ droppedFromStore = store.delete(ident, SCHEMA, cascade);+ } catch (NoSuchEntityException e) {+ LOG.warn("The schema to be dropped does not exist in the store: {}", ident, e);} catch (Exception e) {throw new RuntimeException(e);}++ return isManagedEntity(catalogIdent, Capability.Scope.SCHEMA)+ ? droppedFromStore+ : droppedFromCatalog;}}diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TableOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TableOperationDispatcher.javaindex 5ba444e777..df41cdc263 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/TableOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TableOperationDispatcher.java@@ -14,6 +14,8 @@ import com.datastrato.gravitino.NameIdentifier;import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.StringIdentifier;import com.datastrato.gravitino.connector.HasPropertyMetadata;+import com.datastrato.gravitino.connector.capability.Capability;+import com.datastrato.gravitino.exceptions.NoSuchEntityException;import com.datastrato.gravitino.exceptions.NoSuchSchemaException;import com.datastrato.gravitino.exceptions.NoSuchTableException;import com.datastrato.gravitino.exceptions.TableAlreadyExistsException;@@ -296,27 +298,37 @@ public class TableOperationDispatcher extends OperationDispatcher implements Tab* @param ident The identifier of the table to drop.* @return {@code true} if the table was successfully dropped, {@code false} if the table does not* exist.- * @throws NoSuchTableException If the table to drop does not exist.+ * @throws RuntimeException If an error occurs while dropping the table.*/@Overridepublic boolean dropTable(NameIdentifier ident) {- boolean dropped =+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);+ boolean droppedFromCatalog =doWithCatalog(- getCatalogIdentifier(ident),- c -> c.doWithTableOps(t -> t.dropTable(ident)),- NoSuchTableException.class);-- if (!dropped) {- return false;- }+ catalogIdent, c -> c.doWithTableOps(t -> t.dropTable(ident)), RuntimeException.class);+ // For unmanaged table, it could happen that the table:+ // 1. Is not found in the catalog (dropped directly from underlying sources)+ // 2. Is found in the catalog but not in the store (not managed by Gravitino)+ // 3. Is found in the catalog and the store (managed by Gravitino)+ // 4. Neither found in the catalog nor in the store.+ // In all situations, we try to delete the schema from the store, but we don't take the+ // return value of the store operation into account. We only take the return value of the+ // catalog into account.+ //+ // For managed table, we should take the return value of the store operation into account.+ boolean droppedFromStore = false;try {- store.delete(ident, TABLE);+ droppedFromStore = store.delete(ident, TABLE);+ } catch (NoSuchEntityException e) {+ LOG.warn("The table to be dropped does not exist in the store: {}", ident, e);} catch (Exception e) {throw new RuntimeException(e);}- return true;+ return isManagedEntity(catalogIdent, Capability.Scope.TABLE)+ ? droppedFromStore+ : droppedFromCatalog;}/**@@ -331,26 +343,40 @@ public class TableOperationDispatcher extends OperationDispatcher implements Tab* @param ident A table identifier.* @return True if the table was purged, false if the table did not exist.* @throws UnsupportedOperationException If the catalog does not support to purge a table.+ * @throws RuntimeException If an error occurs while purging the table.*/@Overridepublic boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationException {- boolean purged =+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);+ boolean droppedFromCatalog =doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdent,c -> c.doWithTableOps(t -> t.purgeTable(ident)),- NoSuchTableException.class,+ RuntimeException.class,UnsupportedOperationException.class);- if (!purged) {- return false;- }-+ // For unmanaged table, it could happen that the table:+ // 1. Is not found in the catalog (dropped directly from underlying sources)+ // 2. Is found in the catalog but not in the store (not managed by Gravitino)+ // 3. Is found in the catalog and the store (managed by Gravitino)+ // 4. Neither found in the catalog nor in the store.+ // In all situations, we try to delete the schema from the store, but we don't take the+ // return value of the store operation into account. We only take the return value of the+ // catalog into account.+ //+ // For managed table, we should take the return value of the store operation into account.+ boolean droppedFromStore = false;try {- store.delete(ident, TABLE);+ droppedFromStore = store.delete(ident, TABLE);+ } catch (NoSuchEntityException e) {+ LOG.warn("The table to be purged does not exist in the store: {}", ident, e);+ return false;} catch (Exception e) {throw new RuntimeException(e);}- return true;+ return isManagedEntity(catalogIdent, Capability.Scope.TABLE)+ ? droppedFromStore+ : droppedFromCatalog;}}diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.javaindex c9188093d6..6d52e92d75 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.java@@ -13,6 +13,8 @@ import com.datastrato.gravitino.NameIdentifier;import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.StringIdentifier;import com.datastrato.gravitino.connector.HasPropertyMetadata;+import com.datastrato.gravitino.connector.capability.Capability;+import com.datastrato.gravitino.exceptions.NoSuchEntityException;import com.datastrato.gravitino.exceptions.NoSuchSchemaException;import com.datastrato.gravitino.exceptions.NoSuchTopicException;import com.datastrato.gravitino.exceptions.TopicAlreadyExistsException;@@ -248,25 +250,36 @@ public class TopicOperationDispatcher extends OperationDispatcher implements Top** @param ident A topic identifier.* @return true If the topic is dropped, false if the topic does not exist.+ * @throws RuntimeException If an error occurs while dropping the topic.*/@Overridepublic boolean dropTopic(NameIdentifier ident) {- boolean dropped =+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);+ boolean droppedFromCatalog =doWithCatalog(- getCatalogIdentifier(ident),- c -> c.doWithTopicOps(t -> t.dropTopic(ident)),- NoSuchTopicException.class);-- if (!dropped) {- return false;- }+ catalogIdent, c -> c.doWithTopicOps(t -> t.dropTopic(ident)), RuntimeException.class);+ // For unmanaged topic, it could happen that the topic:+ // 1. Is not found in the catalog (dropped directly from underlying sources)+ // 2. Is found in the catalog but not in the store (not managed by Gravitino)+ // 3. Is found in the catalog and the store (managed by Gravitino)+ // 4. Neither found in the catalog nor in the store.+ // In all situations, we try to delete the schema from the store, but we don't take the+ // return value of the store operation into account. We only take the return value of the+ // catalog into account.+ //+ // For managed topic, we should take the return value of the store operation into account.+ boolean droppedFromStore = false;try {- store.delete(ident, TOPIC);+ droppedFromStore = store.delete(ident, TOPIC);+ } catch (NoSuchEntityException e) {+ LOG.warn("The topic to be dropped does not exist in the store: {}", ident, e);} catch (Exception e) {throw new RuntimeException(e);}- return true;+ return isManagedEntity(catalogIdent, Capability.Scope.TOPIC)+ ? droppedFromStore+ : droppedFromCatalog;}}diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.javaindex a5fc49e905..811553e193 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java@@ -99,11 +99,11 @@ public class RoleOperations {return Utils.doAs(httpRequest,() -> {- boolean deteted = accessControlManager.deleteRole(metalake, role);- if (!deteted) {+ boolean deleted = accessControlManager.deleteRole(metalake, role);+ if (!deleted) {LOG.warn("Failed to delete role {} under metalake {}", role, metalake);}- return Utils.ok(new DeleteResponse(deteted));+ return Utils.ok(new DeleteResponse(deleted));});} catch (Exception e) {return ExceptionHandlers.handleRoleException(OperationType.DELETE, role, metalake, e);