World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#375] fix: Fix return value is incorrect when dropping metalake entities (#382)
Qi Yue903fff24d03
diff --git a/api/src/main/java/com/datastrato/graviton/rel/SupportsSchemas.java b/api/src/main/java/com/datastrato/graviton/rel/SupportsSchemas.javaindex dd0485a002..7ac746f30c 100644--- a/api/src/main/java/com/datastrato/graviton/rel/SupportsSchemas.java+++ b/api/src/main/java/com/datastrato/graviton/rel/SupportsSchemas.java@@ -106,7 +106,7 @@ 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 is dropped successfully, false otherwise.+ * @return True if the schema exists and is dropped successfully, false otherwise.* @throws NonEmptySchemaException If the schema is not empty and cascade is false.*/boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException;diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.javaindex d2300183b7..42366a64f1 100644--- a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java@@ -430,23 +430,21 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas}try {- store.executeInTransaction(+ return store.executeInTransaction(() -> {for (BaseTable t : tables) {store.delete(NameIdentifier.of(schemaNamespace, t.name()), TABLE);}- store.delete(ident, SCHEMA, true);+ boolean dropped = store.delete(ident, SCHEMA, true);clientPool.run(client -> {client.dropDatabase(ident.name(), false, false, cascade);return null;});- return null;+ LOG.info("Dropped Hive schema (database) {}", ident.name());+ return dropped;});- LOG.info("Dropped Hive schema (database) {}", ident.name());- return true;-} catch (InvalidOperationException e) {throw new NonEmptySchemaException(String.format(@@ -937,20 +935,17 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemastry {EntityStore store = GravitonEnv.getInstance().entityStore();- store.executeInTransaction(+ return store.executeInTransaction(() -> {- store.delete(tableIdent, TABLE);+ boolean dropped = store.delete(tableIdent, TABLE);clientPool.run(c -> {c.dropTable(schemaIdent.name(), tableIdent.name(), deleteData, false, ifPurge);return null;});- return null;+ LOG.info("Dropped Hive table {}", tableIdent.name());+ return dropped;});-- LOG.info("Dropped Hive table {}", tableIdent.name());- return true;-} catch (NoSuchObjectException e) {LOG.warn("Hive table {} does not exist in Hive Metastore", tableIdent.name());return false;diff --git a/core/src/main/java/com/datastrato/graviton/EntityStore.java b/core/src/main/java/com/datastrato/graviton/EntityStore.javaindex b39559251a..7b8a99151d 100644--- a/core/src/main/java/com/datastrato/graviton/EntityStore.java+++ b/core/src/main/java/com/datastrato/graviton/EntityStore.java@@ -131,7 +131,7 @@ public interface EntityStore extends Closeable {** @param ident the name identifier of the entity* @param entityType the type of the entity to be deleted- * @return true if the entity is deleted, false otherwise+ * @return true if the entity exists and is deleted successfully, false otherwise* @throws IOException if the delete operation fails*/default boolean delete(NameIdentifier ident, EntityType entityType) throws IOException {@@ -144,7 +144,7 @@ public interface EntityStore extends Closeable {* @param ident the name identifier of the entity* @param entityType the type of the entity to be deleted* @param cascade support cacade detele or not- * @return true if the entity is deleted, false otherwise+ * @return true if the entity exists and is deleted successfully, false otherwise* @throws IOException if the delete operation fails*/boolean delete(NameIdentifier ident, EntityType entityType, boolean cascade) throws IOException;diff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java b/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.javaindex eace5679a1..18fddaadda 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java@@ -291,11 +291,11 @@ public class KvEntityStore implements EntityStore {@Overridepublic boolean delete(NameIdentifier ident, EntityType entityType, boolean cascade)throws IOException {- byte[] dataKey = entityKeyEncoder.encode(ident, entityType, true);- if (dataKey == null) {- return true;+ if (!exists(ident, entityType)) {+ return false;}+ byte[] dataKey = entityKeyEncoder.encode(ident, entityType, true);List<byte[]> subEntityPrefix = getSubEntitiesPrefix(ident, entityType);if (subEntityPrefix.isEmpty()) {// has no sub-entitiesdiff --git a/core/src/test/java/com/datastrato/graviton/storage/kv/TestKvEntityStorage.java b/core/src/test/java/com/datastrato/graviton/storage/kv/TestKvEntityStorage.javaindex 99c23a7eb5..5f626fe7d5 100644--- a/core/src/test/java/com/datastrato/graviton/storage/kv/TestKvEntityStorage.java+++ b/core/src/test/java/com/datastrato/graviton/storage/kv/TestKvEntityStorage.java@@ -504,7 +504,7 @@ public class TestKvEntityStorage {store.get(table1InSchema2.nameIdentifier(), EntityType.TABLE, BaseTable.class));// Delete the table 'metalake.catalog.schema2.table1'- store.delete(table1InSchema2.nameIdentifier(), EntityType.TABLE);+ Assertions.assertTrue(store.delete(table1InSchema2.nameIdentifier(), EntityType.TABLE));Assertions.assertFalse(store.exists(table1InSchema2.nameIdentifier(), EntityType.TABLE));// Make sure table 'metalake.catalog.schema1.table1' still exist;Assertions.assertEquals(@@ -526,8 +526,8 @@ public class TestKvEntityStorage {Assertions.assertTrue(store.exists(table1.nameIdentifier(), EntityType.TABLE));// Delete table1 and schema1- store.delete(table1.nameIdentifier(), EntityType.TABLE);- store.delete(schema1.nameIdentifier(), EntityType.SCHEMA);+ Assertions.assertTrue(store.delete(table1.nameIdentifier(), EntityType.TABLE));+ Assertions.assertTrue(store.delete(schema1.nameIdentifier(), EntityType.SCHEMA));// Make sure table1 in 'metalake.catalog.schema1' can't be access;Assertions.assertFalse(store.exists(table1.nameIdentifier(), EntityType.TABLE));Assertions.assertFalse(store.exists(schema1.nameIdentifier(), EntityType.SCHEMA));@@ -597,6 +597,13 @@ public class TestKvEntityStorage {Assertions.assertThrowsExactly(NoSuchEntityException.class,() -> store.get(schema2.nameIdentifier(), EntityType.SCHEMA, CatalogEntity.class));++ Assertions.assertTrue(store.delete(metalake.nameIdentifier(), EntityType.METALAKE, true));++ // catalog has already deleted, so we can't delete it again and should return false+ Assertions.assertFalse(store.delete(catalog.nameIdentifier(), EntityType.CATALOG));+ Assertions.assertFalse(store.delete(schema2.nameIdentifier(), EntityType.SCHEMA));+ Assertions.assertFalse(store.delete(metalake.nameIdentifier(), EntityType.METALAKE));}}diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.javaindex 43fa4eb0ac..2d19af737c 100644--- a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java@@ -120,5 +120,8 @@ public class MetalakeIT extends AbstractIT {// Reload metatada from backend to check if the drop are appliedAssertions.assertThrows(NoSuchMetalakeException.class, () -> client.loadMetalake(NameIdentifier.of(metalakeName)));++ // Return false if the metalake has been dropped already+ Assertions.assertFalse(client.dropMetalake(NameIdentifier.of(metalakeName)));}}