From ef913581b51fd79ec54ebb4f99bcc84f731691ec Mon Sep 17 00:00:00 2001 From: xloya <982052490@qq.com> Date: Fri, 28 Jun 2024 20:56:13 +0800 Subject: [PATCH] [#3976] improvement(core): Improve the exception behavior in entity store (#3979) ### What changes were proposed in this pull request? Improve the throwing behavior of some SQL exceptions in EntityStore. ### Why are the changes needed? Fix: #3976 ### How was this patch tested? Through the existing tests. Co-authored-by: xiaojiebao --- .../EntityAlreadyExistsException.java | 25 +++++++++++----- .../com/datastrato/gravitino/EntityStore.java | 5 ++-- .../gravitino/storage/kv/KvBackend.java | 7 +++-- .../gravitino/storage/kv/KvEntityStore.java | 5 ++-- .../storage/kv/RocksDBKvBackend.java | 6 ++-- .../kv/TransactionalKvBackendImpl.java | 2 +- .../storage/relational/JDBCBackend.java | 21 +++++++------ .../storage/relational/RelationalBackend.java | 20 +++++++++---- .../relational/RelationalEntityStore.java | 3 +- .../converters/H2ExceptionConverter.java | 12 ++++---- .../converters/MySQLExceptionConverter.java | 12 ++++---- .../converters/SQLExceptionConverter.java | 8 ++--- .../service/CatalogMetaService.java | 2 +- .../service/FilesetMetaService.java | 2 +- .../relational/service/GroupMetaService.java | 5 ++-- .../service/MetalakeMetaService.java | 2 +- .../relational/service/RoleMetaService.java | 3 +- .../relational/service/SchemaMetaService.java | 2 +- .../relational/service/TableMetaService.java | 2 +- .../relational/service/TopicMetaService.java | 2 +- .../relational/service/UserMetaService.java | 5 ++-- .../relational/utils/ExceptionUtils.java | 5 ++-- .../gravitino/storage/TestEntityStorage.java | 4 +-- .../storage/kv/TestRocksDBKvBackend.java | 4 +-- .../storage/memory/TestMemoryEntityStore.java | 2 +- .../storage/relational/TestJDBCBackend.java | 30 +++++++++---------- .../service/TestGroupMetaService.java | 21 ++++++------- .../service/TestRoleMetaService.java | 17 ++++++----- .../service/TestSecurableObjects.java | 3 +- .../service/TestUserMetaService.java | 21 ++++++------- 30 files changed, 141 insertions(+), 117 deletions(-) diff --git a/core/src/main/java/com/datastrato/gravitino/EntityAlreadyExistsException.java b/core/src/main/java/com/datastrato/gravitino/EntityAlreadyExistsException.java index c29fd3a95e1..cbd20186cd4 100644 --- a/core/src/main/java/com/datastrato/gravitino/EntityAlreadyExistsException.java +++ b/core/src/main/java/com/datastrato/gravitino/EntityAlreadyExistsException.java @@ -4,28 +4,37 @@ */ package com.datastrato.gravitino; +import com.datastrato.gravitino.exceptions.GravitinoRuntimeException; +import com.google.errorprone.annotations.FormatMethod; +import com.google.errorprone.annotations.FormatString; + /** * Exception class indicating that an entity already exists. This exception is thrown when an * attempt is made to create an entity that already exists within the Gravitino framework. */ -public class EntityAlreadyExistsException extends RuntimeException { +public class EntityAlreadyExistsException extends GravitinoRuntimeException { /** * Constructs an EntityAlreadyExistsException. * - * @param message The detail message explaining the exception. + * @param message the detail message. + * @param args the arguments to the message. */ - public EntityAlreadyExistsException(String message) { - super(message); + @FormatMethod + public EntityAlreadyExistsException(@FormatString String message, Object... args) { + super(message, args); } /** * Constructs an EntityAlreadyExistsException. * - * @param message The detail message explaining the exception. - * @param cause The cause of the exception. + * @param cause the cause. + * @param message the detail message. + * @param args the arguments to the message. */ - public EntityAlreadyExistsException(String message, Throwable cause) { - super(message, cause); + @FormatMethod + public EntityAlreadyExistsException( + Throwable cause, @FormatString String message, Object... args) { + super(cause, message, args); } } diff --git a/core/src/main/java/com/datastrato/gravitino/EntityStore.java b/core/src/main/java/com/datastrato/gravitino/EntityStore.java index e2e5a55fdcf..5be1d19f21c 100644 --- a/core/src/main/java/com/datastrato/gravitino/EntityStore.java +++ b/core/src/main/java/com/datastrato/gravitino/EntityStore.java @@ -5,7 +5,6 @@ package com.datastrato.gravitino; import com.datastrato.gravitino.Entity.EntityType; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.utils.Executable; import java.io.Closeable; @@ -110,11 +109,11 @@ void put(E e, boolean overwritten) * @return E the updated entity * @throws IOException if the store operation fails * @throws NoSuchEntityException if the entity does not exist - * @throws AlreadyExistsException if the updated entity already existed. + * @throws EntityAlreadyExistsException if the updated entity already existed. */ E update( NameIdentifier ident, Class type, EntityType entityType, Function updater) - throws IOException, NoSuchEntityException, AlreadyExistsException; + throws IOException, NoSuchEntityException, EntityAlreadyExistsException; /** * Get the entity from the underlying storage. diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvBackend.java index f2d2d4be55c..6142e053078 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvBackend.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvBackend.java @@ -6,7 +6,7 @@ package com.datastrato.gravitino.storage.kv; import com.datastrato.gravitino.Config; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; +import com.datastrato.gravitino.EntityAlreadyExistsException; import java.io.Closeable; import java.io.IOException; import java.util.List; @@ -29,9 +29,10 @@ public interface KvBackend extends Closeable { * @param value The value of the pair. * @param overwrite If true, overwrites the existing value. * @throws IOException If an I/O exception occurs during the operation. - * @throws AlreadyExistsException If the key already exists and overwrite is false. + * @throws EntityAlreadyExistsException If the key already exists and overwrite is false. */ - void put(byte[] key, byte[] value, boolean overwrite) throws IOException, AlreadyExistsException; + void put(byte[] key, byte[] value, boolean overwrite) + throws IOException, EntityAlreadyExistsException; /** * Retrieves the value associated with a given key. diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java index 917558888ab..e389d8d22a8 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/KvEntityStore.java @@ -24,7 +24,6 @@ import com.datastrato.gravitino.HasIdentifier; import com.datastrato.gravitino.NameIdentifier; import com.datastrato.gravitino.Namespace; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.exceptions.NonEmptyEntityException; import com.datastrato.gravitino.storage.EntityKeyEncoder; @@ -168,7 +167,7 @@ public void put(E e, boolean overwritten) @Override public E update( NameIdentifier ident, Class type, EntityType entityType, Function updater) - throws IOException, NoSuchEntityException, AlreadyExistsException { + throws IOException, NoSuchEntityException, EntityAlreadyExistsException { return executeInTransaction( () -> { byte[] key = entityKeyEncoder.encode(ident, entityType); @@ -188,7 +187,7 @@ public E update( // Check whether the new entities already existed boolean newEntityExist = exists(updatedE.nameIdentifier(), entityType); if (newEntityExist) { - throw new AlreadyExistsException( + throw new EntityAlreadyExistsException( "Entity %s already exist, please check again", updatedE.nameIdentifier()); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java index 35d549a68f9..28003e20c72 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/RocksDBKvBackend.java @@ -7,7 +7,7 @@ import com.datastrato.gravitino.Config; import com.datastrato.gravitino.Configs; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; +import com.datastrato.gravitino.EntityAlreadyExistsException; import com.datastrato.gravitino.utils.ByteUtils; import com.datastrato.gravitino.utils.Bytes; import com.google.common.annotations.VisibleForTesting; @@ -95,7 +95,7 @@ public void initialize(Config config) throws IOException { public void put(byte[] key, byte[] value, boolean overwrite) throws IOException { try { handlePut(key, value, overwrite); - } catch (AlreadyExistsException e) { + } catch (EntityAlreadyExistsException e) { throw e; } catch (Exception e) { throw new IOException(e); @@ -110,7 +110,7 @@ void handlePut(byte[] key, byte[] value, boolean overwrite) throws RocksDBExcept } byte[] existKey = db.get(key); if (existKey != null) { - throw new AlreadyExistsException( + throw new EntityAlreadyExistsException( "Key %s already exists in the database, please use overwrite option to overwrite it", ByteUtils.formatByteArray(key)); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java b/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java index 1ab4b4062fa..d241bf4d6da 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/kv/TransactionalKvBackendImpl.java @@ -142,7 +142,7 @@ public void put(byte[] key, byte[] value, boolean overwrite) throws IOException, EntityAlreadyExistsException { byte[] oldValue = get(key); if (oldValue != null && !overwrite) { - throw new EntityAlreadyExistsException("Key already exists: " + Bytes.wrap(key)); + throw new EntityAlreadyExistsException("Key already exists: %s", Bytes.wrap(key)); } putPairs .get() diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java index b36f7e71545..5b0feccc1b7 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java @@ -15,7 +15,6 @@ import com.datastrato.gravitino.NameIdentifier; import com.datastrato.gravitino.Namespace; import com.datastrato.gravitino.UnsupportedEntityTypeException; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.meta.BaseMetalake; import com.datastrato.gravitino.meta.CatalogEntity; @@ -69,7 +68,7 @@ public void initialize(Config config) { @Override public List list( - Namespace namespace, Entity.EntityType entityType) { + Namespace namespace, Entity.EntityType entityType) throws IOException { switch (entityType) { case METALAKE: return (List) MetalakeMetaService.getInstance().listMetalakes(); @@ -90,7 +89,7 @@ public List list( } @Override - public boolean exists(NameIdentifier ident, Entity.EntityType entityType) { + public boolean exists(NameIdentifier ident, Entity.EntityType entityType) throws IOException { try { Entity entity = get(ident, entityType); return entity != null; @@ -101,7 +100,7 @@ public boolean exists(NameIdentifier ident, Entity.EntityType entityType) { @Override public void insert(E e, boolean overwritten) - throws EntityAlreadyExistsException { + throws EntityAlreadyExistsException, IOException { if (e instanceof BaseMetalake) { MetalakeMetaService.getInstance().insertMetalake((BaseMetalake) e, overwritten); } else if (e instanceof CatalogEntity) { @@ -129,7 +128,7 @@ public void insert(E e, boolean overwritten) @Override public E update( NameIdentifier ident, Entity.EntityType entityType, Function updater) - throws IOException, NoSuchEntityException, AlreadyExistsException { + throws IOException, NoSuchEntityException, EntityAlreadyExistsException { switch (entityType) { case METALAKE: return (E) MetalakeMetaService.getInstance().updateMetalake(ident, updater); @@ -155,7 +154,8 @@ public E update( @Override public E get( - NameIdentifier ident, Entity.EntityType entityType) throws NoSuchEntityException { + NameIdentifier ident, Entity.EntityType entityType) + throws NoSuchEntityException, IOException { switch (entityType) { case METALAKE: return (E) MetalakeMetaService.getInstance().getMetalakeByIdentifier(ident); @@ -182,7 +182,8 @@ public E get( } @Override - public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) { + public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) + throws IOException { switch (entityType) { case METALAKE: return MetalakeMetaService.getInstance().deleteMetalake(ident, cascade); @@ -209,7 +210,8 @@ public boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolea } @Override - public int hardDeleteLegacyData(Entity.EntityType entityType, long legacyTimeline) { + public int hardDeleteLegacyData(Entity.EntityType entityType, long legacyTimeline) + throws IOException { switch (entityType) { case METALAKE: return MetalakeMetaService.getInstance() @@ -260,7 +262,8 @@ public int hardDeleteLegacyData(Entity.EntityType entityType, long legacyTimelin } @Override - public int deleteOldVersionData(Entity.EntityType entityType, long versionRetentionCount) { + public int deleteOldVersionData(Entity.EntityType entityType, long versionRetentionCount) + throws IOException { switch (entityType) { case METALAKE: case CATALOG: diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalBackend.java index e60b8be56a6..d3c5c83e72e 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalBackend.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalBackend.java @@ -35,9 +35,10 @@ public interface RelationalBackend extends Closeable { * if the entities does not exist. * @throws NoSuchEntityException If the corresponding parent entity of these list entities cannot * be found. + * @throws IOException If the store operation fails */ List list(Namespace namespace, Entity.EntityType entityType) - throws NoSuchEntityException; + throws NoSuchEntityException, IOException; /** * Checks the entity associated with the given identifier and entityType whether exists. @@ -45,8 +46,9 @@ List list(Namespace namespace, Entity.Enti * @param ident The identifier of the entity. * @param entityType The type of the entity. * @return True, if the entity can be found, else return false. + * @throws IOException If the store operation fails */ - boolean exists(NameIdentifier ident, Entity.EntityType entityType); + boolean exists(NameIdentifier ident, Entity.EntityType entityType) throws IOException; /** * Stores the entity, possibly overwriting an existing entity if specified. @@ -54,9 +56,10 @@ List list(Namespace namespace, Entity.Enti * @param e The entity which need be stored. * @param overwritten If true, overwrites the existing value. * @throws EntityAlreadyExistsException If the entity already exists and overwrite is false. + * @throws IOException If the store operation fails */ void insert(E e, boolean overwritten) - throws EntityAlreadyExistsException; + throws EntityAlreadyExistsException, IOException; /** * Updates the entity. @@ -90,8 +93,10 @@ E get(NameIdentifier ident, Entity.EntityType * @param entityType The type of the entity. * @param cascade True, If you need to cascade delete entities, else false. * @return True, if the entity was successfully deleted, else false. + * @throws IOException If the store operation fails */ - boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade); + boolean delete(NameIdentifier ident, Entity.EntityType entityType, boolean cascade) + throws IOException; /** * Permanently deletes the legacy data that has been marked as deleted before the given legacy @@ -100,8 +105,9 @@ E get(NameIdentifier ident, Entity.EntityType * @param entityType The type of the entity. * @param legacyTimeline The time before which the data has been marked as deleted. * @return The count of the deleted data. + * @throws IOException If the store operation fails */ - int hardDeleteLegacyData(Entity.EntityType entityType, long legacyTimeline); + int hardDeleteLegacyData(Entity.EntityType entityType, long legacyTimeline) throws IOException; /** * Soft deletes the old version data that is older than or equal to the given version retention @@ -110,6 +116,8 @@ E get(NameIdentifier ident, Entity.EntityType * @param entityType The type of the entity. * @param versionRetentionCount The count of versions to retain. * @return The count of the deleted data. + * @throws IOException If the store operation fails */ - int deleteOldVersionData(Entity.EntityType entityType, long versionRetentionCount); + int deleteOldVersionData(Entity.EntityType entityType, long versionRetentionCount) + throws IOException; } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalEntityStore.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalEntityStore.java index cf8ae99458d..52170f1676b 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalEntityStore.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/RelationalEntityStore.java @@ -15,7 +15,6 @@ import com.datastrato.gravitino.HasIdentifier; import com.datastrato.gravitino.NameIdentifier; import com.datastrato.gravitino.Namespace; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.utils.Executable; import com.google.common.collect.ImmutableMap; @@ -88,7 +87,7 @@ public void put(E e, boolean overwritten) @Override public E update( NameIdentifier ident, Class type, Entity.EntityType entityType, Function updater) - throws IOException, NoSuchEntityException, AlreadyExistsException { + throws IOException, NoSuchEntityException, EntityAlreadyExistsException { return backend.update(ident, entityType, updater); } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/H2ExceptionConverter.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/H2ExceptionConverter.java index b47f8ce208d..6b57b6aa0a7 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/H2ExceptionConverter.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/H2ExceptionConverter.java @@ -5,8 +5,8 @@ package com.datastrato.gravitino.storage.relational.converters; import com.datastrato.gravitino.Entity; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; -import com.datastrato.gravitino.exceptions.GravitinoRuntimeException; +import com.datastrato.gravitino.EntityAlreadyExistsException; +import java.io.IOException; import java.sql.SQLException; /** @@ -19,13 +19,13 @@ public class H2ExceptionConverter implements SQLExceptionConverter { @SuppressWarnings("FormatStringAnnotation") @Override - public GravitinoRuntimeException toGravitinoException( - SQLException se, Entity.EntityType type, String name) { + public void toGravitinoException(SQLException se, Entity.EntityType type, String name) + throws IOException { switch (se.getErrorCode()) { case DUPLICATED_ENTRY_ERROR_CODE: - return new AlreadyExistsException(se, se.getMessage()); + throw new EntityAlreadyExistsException(se, se.getMessage()); default: - return new GravitinoRuntimeException(se, se.getMessage()); + throw new IOException(se); } } } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/MySQLExceptionConverter.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/MySQLExceptionConverter.java index de8136629cc..7f3e1ac2efe 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/MySQLExceptionConverter.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/MySQLExceptionConverter.java @@ -5,8 +5,8 @@ package com.datastrato.gravitino.storage.relational.converters; import com.datastrato.gravitino.Entity; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; -import com.datastrato.gravitino.exceptions.GravitinoRuntimeException; +import com.datastrato.gravitino.EntityAlreadyExistsException; +import java.io.IOException; import java.sql.SQLException; /** @@ -20,13 +20,13 @@ public class MySQLExceptionConverter implements SQLExceptionConverter { @SuppressWarnings("FormatStringAnnotation") @Override - public GravitinoRuntimeException toGravitinoException( - SQLException se, Entity.EntityType type, String name) { + public void toGravitinoException(SQLException se, Entity.EntityType type, String name) + throws IOException { switch (se.getErrorCode()) { case DUPLICATED_ENTRY_ERROR_CODE: - return new AlreadyExistsException(se, se.getMessage()); + throw new EntityAlreadyExistsException(se, se.getMessage()); default: - return new GravitinoRuntimeException(se, se.getMessage()); + throw new IOException(se); } } } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/SQLExceptionConverter.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/SQLExceptionConverter.java index 47fe684cf93..4fd92a82f5d 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/SQLExceptionConverter.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/converters/SQLExceptionConverter.java @@ -5,7 +5,7 @@ package com.datastrato.gravitino.storage.relational.converters; import com.datastrato.gravitino.Entity; -import com.datastrato.gravitino.exceptions.GravitinoRuntimeException; +import java.io.IOException; import java.sql.SQLException; /** Interface for converter JDBC SQL exceptions to Gravitino exceptions. */ @@ -16,9 +16,7 @@ public interface SQLExceptionConverter { * @param sqlException The sql exception to map * @param type The type of the entity * @param name The name of the entity - * @return A best attempt at a corresponding jdbc connector exception or generic with the - * SQLException as the cause */ - GravitinoRuntimeException toGravitinoException( - SQLException sqlException, Entity.EntityType type, String name); + void toGravitinoException(SQLException sqlException, Entity.EntityType type, String name) + throws IOException; } diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java index 94fee06c222..4ff0293d6b7 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java @@ -107,7 +107,7 @@ public List listCatalogsByNamespace(Namespace namespace) { return POConverters.fromCatalogPOs(catalogPOS, namespace); } - public void insertCatalog(CatalogEntity catalogEntity, boolean overwrite) { + public void insertCatalog(CatalogEntity catalogEntity, boolean overwrite) throws IOException { try { NameIdentifierUtil.checkCatalog(catalogEntity.nameIdentifier()); diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java index 0bc14605fd8..5f769b20293 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java @@ -105,7 +105,7 @@ public List listFilesetsByNamespace(Namespace namespace) { return POConverters.fromFilesetPOs(filesetPOs, namespace); } - public void insertFileset(FilesetEntity filesetEntity, boolean overwrite) { + public void insertFileset(FilesetEntity filesetEntity, boolean overwrite) throws IOException { try { NameIdentifierUtil.checkFileset(filesetEntity.nameIdentifier()); diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/GroupMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/GroupMetaService.java index 36a9dd99fa3..93703696176 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/GroupMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/GroupMetaService.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import java.io.IOException; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -78,7 +79,7 @@ public GroupEntity getGroupByIdentifier(NameIdentifier identifier) { return POConverters.fromGroupPO(groupPO, rolePOs, identifier.namespace()); } - public void insertGroup(GroupEntity groupEntity, boolean overwritten) { + public void insertGroup(GroupEntity groupEntity, boolean overwritten) throws IOException { try { AuthorizationUtils.checkGroup(groupEntity.nameIdentifier()); @@ -140,7 +141,7 @@ public boolean deleteGroup(NameIdentifier identifier) { } public GroupEntity updateGroup( - NameIdentifier identifier, Function updater) { + NameIdentifier identifier, Function updater) throws IOException { AuthorizationUtils.checkGroup(identifier); Long metalakeId = diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java index 90537ccc7ff..5c84202ae37 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java @@ -91,7 +91,7 @@ public MetalakePO getMetalakePOById(Long id) { return metalakePO; } - public void insertMetalake(BaseMetalake baseMetalake, boolean overwrite) { + public void insertMetalake(BaseMetalake baseMetalake, boolean overwrite) throws IOException { try { NameIdentifierUtil.checkMetalake(baseMetalake.nameIdentifier()); SessionUtils.doWithCommit( diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/RoleMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/RoleMetaService.java index 238ba26c2ca..6f7bb1ab3f9 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/RoleMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/RoleMetaService.java @@ -23,6 +23,7 @@ import com.datastrato.gravitino.storage.relational.utils.POConverters; import com.datastrato.gravitino.storage.relational.utils.SessionUtils; import com.google.common.collect.Lists; +import java.io.IOException; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -79,7 +80,7 @@ public List listRolesByGroupId(Long groupId) { RoleMetaMapper.class, mapper -> mapper.listRolesByGroupId(groupId)); } - public void insertRole(RoleEntity roleEntity, boolean overwritten) { + public void insertRole(RoleEntity roleEntity, boolean overwritten) throws IOException { try { AuthorizationUtils.checkRole(roleEntity.nameIdentifier()); diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java index b75941b7acf..de59f4c1b79 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java @@ -99,7 +99,7 @@ public List listSchemasByNamespace(Namespace namespace) { return POConverters.fromSchemaPOs(schemaPOs, namespace); } - public void insertSchema(SchemaEntity schemaEntity, boolean overwrite) { + public void insertSchema(SchemaEntity schemaEntity, boolean overwrite) throws IOException { try { NameIdentifierUtil.checkSchema(schemaEntity.nameIdentifier()); diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java index 97a1d862f81..9f015eb9d34 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java @@ -94,7 +94,7 @@ public List listTablesByNamespace(Namespace namespace) { return POConverters.fromTablePOs(tablePOs, namespace); } - public void insertTable(TableEntity tableEntity, boolean overwrite) { + public void insertTable(TableEntity tableEntity, boolean overwrite) throws IOException { try { NameIdentifierUtil.checkTable(tableEntity.nameIdentifier()); diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java index d35e0e8934f..f138a856f25 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java @@ -36,7 +36,7 @@ public static TopicMetaService getInstance() { private TopicMetaService() {} - public void insertTopic(TopicEntity topicEntity, boolean overwrite) { + public void insertTopic(TopicEntity topicEntity, boolean overwrite) throws IOException { try { NameIdentifierUtil.checkTopic(topicEntity.nameIdentifier()); diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/UserMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/UserMetaService.java index b0175de4383..1730f127b4c 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/UserMetaService.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/UserMetaService.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import java.io.IOException; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -78,7 +79,7 @@ public UserEntity getUserByIdentifier(NameIdentifier identifier) { return POConverters.fromUserPO(userPO, rolePOs, identifier.namespace()); } - public void insertUser(UserEntity userEntity, boolean overwritten) { + public void insertUser(UserEntity userEntity, boolean overwritten) throws IOException { try { AuthorizationUtils.checkUser(userEntity.nameIdentifier()); @@ -139,7 +140,7 @@ public boolean deleteUser(NameIdentifier identifier) { } public UserEntity updateUser( - NameIdentifier identifier, Function updater) { + NameIdentifier identifier, Function updater) throws IOException { AuthorizationUtils.checkUser(identifier); Long metalakeId = diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java index f11b3c2fc77..54e82239d7e 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java @@ -6,15 +6,16 @@ import com.datastrato.gravitino.Entity; import com.datastrato.gravitino.storage.relational.converters.SQLExceptionConverterFactory; +import java.io.IOException; import java.sql.SQLException; public class ExceptionUtils { private ExceptionUtils() {} public static void checkSQLException( - RuntimeException re, Entity.EntityType type, String entityName) { + RuntimeException re, Entity.EntityType type, String entityName) throws IOException { if (re.getCause() instanceof SQLException) { - throw SQLExceptionConverterFactory.getConverter() + SQLExceptionConverterFactory.getConverter() .toGravitinoException((SQLException) re.getCause(), type, entityName); } } diff --git a/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java b/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java index f4da55bc555..050e4195200 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/TestEntityStorage.java @@ -26,6 +26,7 @@ import com.datastrato.gravitino.Configs; import com.datastrato.gravitino.Entity; import com.datastrato.gravitino.Entity.EntityType; +import com.datastrato.gravitino.EntityAlreadyExistsException; import com.datastrato.gravitino.EntityStore; import com.datastrato.gravitino.EntityStoreFactory; import com.datastrato.gravitino.NameIdentifier; @@ -34,7 +35,6 @@ import com.datastrato.gravitino.authorization.Privileges; import com.datastrato.gravitino.authorization.SecurableObject; import com.datastrato.gravitino.authorization.SecurableObjects; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.exceptions.NonEmptyEntityException; import com.datastrato.gravitino.file.Fileset; @@ -1854,7 +1854,7 @@ private void validateNotChangedEntity(EntityStore store, SchemaEntity schema) th private void validateAlreadyExistEntity(EntityStore store, SchemaEntity schema) { // The updated entities already existed, should throw exception Assertions.assertThrowsExactly( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> store.update( NameIdentifier.of("metalakeChanged", "catalogChanged", "schema2"), diff --git a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java index dc2b8b7aa1c..bcce979d2d7 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/kv/TestRocksDBKvBackend.java @@ -8,7 +8,7 @@ import static com.datastrato.gravitino.Configs.ENTITY_KV_ROCKSDB_BACKEND_PATH; import com.datastrato.gravitino.Config; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; +import com.datastrato.gravitino.EntityAlreadyExistsException; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -66,7 +66,7 @@ void testPutAndGet() throws IOException, RocksDBException { Assertions.assertEquals("testValue", new String(bytes, StandardCharsets.UTF_8)); Assertions.assertThrowsExactly( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> kvBackend.put( "testKey".getBytes(StandardCharsets.UTF_8), diff --git a/core/src/test/java/com/datastrato/gravitino/storage/memory/TestMemoryEntityStore.java b/core/src/test/java/com/datastrato/gravitino/storage/memory/TestMemoryEntityStore.java index c3f916c603d..856bb7f5522 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/memory/TestMemoryEntityStore.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/memory/TestMemoryEntityStore.java @@ -90,7 +90,7 @@ public void put(E e, boolean overwritten) executeInTransaction( () -> { if (exists(e.nameIdentifier(), e.type())) { - throw new EntityAlreadyExistsException("Entity " + ident + " already exists"); + throw new EntityAlreadyExistsException("Entity %s already exists", ident); } entityMap.put(ident, e); return null; diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java index 60e822ad64f..cb7d59ab9f5 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java @@ -21,12 +21,12 @@ import com.datastrato.gravitino.Config; import com.datastrato.gravitino.Configs; import com.datastrato.gravitino.Entity; +import com.datastrato.gravitino.EntityAlreadyExistsException; import com.datastrato.gravitino.Namespace; import com.datastrato.gravitino.authorization.AuthorizationUtils; import com.datastrato.gravitino.authorization.Privileges; import com.datastrato.gravitino.authorization.SecurableObject; import com.datastrato.gravitino.authorization.SecurableObjects; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.file.Fileset; import com.datastrato.gravitino.meta.AuditInfo; import com.datastrato.gravitino.meta.BaseMetalake; @@ -189,7 +189,7 @@ private static void dropAllTables() { } @Test - public void testInsertAlreadyExistsException() { + public void testInsertAlreadyExistsException() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); @@ -198,7 +198,7 @@ public void testInsertAlreadyExistsException() { BaseMetalake metalakeCopy = createBaseMakeLake(RandomIdGenerator.INSTANCE.nextId(), "metalake", auditInfo); backend.insert(metalake, false); - assertThrows(AlreadyExistsException.class, () -> backend.insert(metalakeCopy, false)); + assertThrows(EntityAlreadyExistsException.class, () -> backend.insert(metalakeCopy, false)); CatalogEntity catalog = createCatalog( @@ -213,7 +213,7 @@ public void testInsertAlreadyExistsException() { "catalog", auditInfo); backend.insert(catalog, false); - assertThrows(AlreadyExistsException.class, () -> backend.insert(catalogCopy, false)); + assertThrows(EntityAlreadyExistsException.class, () -> backend.insert(catalogCopy, false)); SchemaEntity schema = createSchemaEntity( @@ -228,7 +228,7 @@ public void testInsertAlreadyExistsException() { "schema", auditInfo); backend.insert(schema, false); - assertThrows(AlreadyExistsException.class, () -> backend.insert(schemaCopy, false)); + assertThrows(EntityAlreadyExistsException.class, () -> backend.insert(schemaCopy, false)); TableEntity table = createTableEntity( @@ -243,7 +243,7 @@ public void testInsertAlreadyExistsException() { "table", auditInfo); backend.insert(table, false); - assertThrows(AlreadyExistsException.class, () -> backend.insert(tableCopy, false)); + assertThrows(EntityAlreadyExistsException.class, () -> backend.insert(tableCopy, false)); FilesetEntity fileset = createFilesetEntity( @@ -258,7 +258,7 @@ public void testInsertAlreadyExistsException() { "fileset", auditInfo); backend.insert(fileset, false); - assertThrows(AlreadyExistsException.class, () -> backend.insert(filesetCopy, false)); + assertThrows(EntityAlreadyExistsException.class, () -> backend.insert(filesetCopy, false)); TopicEntity topic = createTopicEntity( @@ -273,11 +273,11 @@ public void testInsertAlreadyExistsException() { "topic", auditInfo); backend.insert(topic, false); - assertThrows(AlreadyExistsException.class, () -> backend.insert(topicCopy, false)); + assertThrows(EntityAlreadyExistsException.class, () -> backend.insert(topicCopy, false)); } @Test - public void testUpdateAlreadyExistsException() { + public void testUpdateAlreadyExistsException() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); @@ -288,7 +288,7 @@ public void testUpdateAlreadyExistsException() { backend.insert(metalake, false); backend.insert(metalakeCopy, false); assertThrows( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> backend.update( metalakeCopy.nameIdentifier(), @@ -310,7 +310,7 @@ public void testUpdateAlreadyExistsException() { backend.insert(catalog, false); backend.insert(catalogCopy, false); assertThrows( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> backend.update( catalogCopy.nameIdentifier(), @@ -334,7 +334,7 @@ public void testUpdateAlreadyExistsException() { backend.insert(schema, false); backend.insert(schemaCopy, false); assertThrows( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> backend.update( schemaCopy.nameIdentifier(), @@ -358,7 +358,7 @@ public void testUpdateAlreadyExistsException() { backend.insert(table, false); backend.insert(tableCopy, false); assertThrows( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> backend.update( tableCopy.nameIdentifier(), @@ -380,7 +380,7 @@ public void testUpdateAlreadyExistsException() { backend.insert(fileset, false); backend.insert(filesetCopy, false); assertThrows( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> backend.update( filesetCopy.nameIdentifier(), @@ -404,7 +404,7 @@ public void testUpdateAlreadyExistsException() { backend.insert(topic, false); backend.insert(topicCopy, false); assertThrows( - AlreadyExistsException.class, + EntityAlreadyExistsException.class, () -> backend.update( topicCopy.nameIdentifier(), diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestGroupMetaService.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestGroupMetaService.java index ecb29dee2ed..cf86da29bc7 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestGroupMetaService.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestGroupMetaService.java @@ -5,9 +5,9 @@ package com.datastrato.gravitino.storage.relational.service; +import com.datastrato.gravitino.EntityAlreadyExistsException; import com.datastrato.gravitino.Namespace; import com.datastrato.gravitino.authorization.AuthorizationUtils; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.meta.AuditInfo; import com.datastrato.gravitino.meta.BaseMetalake; @@ -22,6 +22,7 @@ import com.datastrato.gravitino.storage.relational.utils.SessionUtils; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -38,7 +39,7 @@ class TestGroupMetaService extends TestJDBCBackend { String metalakeName = "metalake"; @Test - void getGroupByIdentifier() { + void getGroupByIdentifier() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); @@ -103,7 +104,7 @@ void getGroupByIdentifier() { } @Test - void insertGroup() { + void insertGroup() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -138,7 +139,7 @@ void insertGroup() { "group1", auditInfo); Assertions.assertThrows( - AlreadyExistsException.class, () -> groupMetaService.insertGroup(group1Exist, false)); + EntityAlreadyExistsException.class, () -> groupMetaService.insertGroup(group1Exist, false)); // insert overwrite GroupEntity group1Overwrite = @@ -193,7 +194,7 @@ void insertGroup() { "group2", auditInfo); Assertions.assertThrows( - AlreadyExistsException.class, () -> groupMetaService.insertGroup(group2Exist, false)); + EntityAlreadyExistsException.class, () -> groupMetaService.insertGroup(group2Exist, false)); // insert overwrite group with 2 roles GroupEntity group2Overwrite = @@ -255,7 +256,7 @@ void insertGroup() { } @Test - void deleteGroup() { + void deleteGroup() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -332,7 +333,7 @@ void deleteGroup() { } @Test - void updateGroup() { + void updateGroup() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -547,7 +548,7 @@ void updateGroup() { } @Test - void deleteMetalake() { + void deleteMetalake() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -628,7 +629,7 @@ void deleteMetalake() { } @Test - void deleteMetalakeCascade() { + void deleteMetalakeCascade() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -707,7 +708,7 @@ void deleteMetalakeCascade() { } @Test - void deleteGroupMetasByLegacyTimeline() { + void deleteGroupMetasByLegacyTimeline() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestRoleMetaService.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestRoleMetaService.java index f4d058927ee..4f4c35d1fef 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestRoleMetaService.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestRoleMetaService.java @@ -5,12 +5,12 @@ package com.datastrato.gravitino.storage.relational.service; +import com.datastrato.gravitino.EntityAlreadyExistsException; import com.datastrato.gravitino.Namespace; import com.datastrato.gravitino.authorization.AuthorizationUtils; import com.datastrato.gravitino.authorization.Privileges; import com.datastrato.gravitino.authorization.SecurableObject; import com.datastrato.gravitino.authorization.SecurableObjects; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.meta.AuditInfo; import com.datastrato.gravitino.meta.BaseMetalake; @@ -28,6 +28,7 @@ import com.datastrato.gravitino.storage.relational.utils.SessionUtils; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -43,7 +44,7 @@ class TestRoleMetaService extends TestJDBCBackend { String metalakeName = "metalake"; @Test - void getRoleByIdentifier() { + void getRoleByIdentifier() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); @@ -87,7 +88,7 @@ void getRoleByIdentifier() { } @Test - void insertRole() { + void insertRole() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -148,7 +149,7 @@ void insertRole() { "catalog", Lists.newArrayList(Privileges.UseCatalog.allow())), ImmutableMap.of("k1", "v1")); Assertions.assertThrows( - AlreadyExistsException.class, () -> roleMetaService.insertRole(role1Exist, false)); + EntityAlreadyExistsException.class, () -> roleMetaService.insertRole(role1Exist, false)); // insert overwrite RoleEntity role1Overwrite = @@ -169,7 +170,7 @@ void insertRole() { } @Test - void deleteRole() { + void deleteRole() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -283,7 +284,7 @@ void deleteRole() { } @Test - void deleteMetalake() { + void deleteMetalake() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -396,7 +397,7 @@ void deleteMetalake() { } @Test - void deleteMetalakeCascade() { + void deleteMetalakeCascade() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -505,7 +506,7 @@ void deleteMetalakeCascade() { } @Test - void deleteRoleMetasByLegacyTimeline() { + void deleteRoleMetasByLegacyTimeline() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestSecurableObjects.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestSecurableObjects.java index f7dbc03d175..2d9a8282e73 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestSecurableObjects.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestSecurableObjects.java @@ -21,6 +21,7 @@ import com.datastrato.gravitino.storage.relational.TestJDBCBackend; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import java.io.IOException; import java.time.Instant; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -29,7 +30,7 @@ public class TestSecurableObjects extends TestJDBCBackend { RoleMetaService roleMetaService = RoleMetaService.getInstance(); @Test - public void testAllTypeSecurableObjects() { + public void testAllTypeSecurableObjects() throws IOException { String metalakeName = "metalake"; AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestUserMetaService.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestUserMetaService.java index adca7051315..6c59bd5fbc3 100644 --- a/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestUserMetaService.java +++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/service/TestUserMetaService.java @@ -5,9 +5,9 @@ package com.datastrato.gravitino.storage.relational.service; +import com.datastrato.gravitino.EntityAlreadyExistsException; import com.datastrato.gravitino.Namespace; import com.datastrato.gravitino.authorization.AuthorizationUtils; -import com.datastrato.gravitino.exceptions.AlreadyExistsException; import com.datastrato.gravitino.exceptions.NoSuchEntityException; import com.datastrato.gravitino.meta.AuditInfo; import com.datastrato.gravitino.meta.BaseMetalake; @@ -22,6 +22,7 @@ import com.datastrato.gravitino.storage.relational.utils.SessionUtils; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -38,7 +39,7 @@ class TestUserMetaService extends TestJDBCBackend { String metalakeName = "metalake"; @Test - void getUserByIdentifier() { + void getUserByIdentifier() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); @@ -102,7 +103,7 @@ void getUserByIdentifier() { } @Test - void insertUser() { + void insertUser() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -137,7 +138,7 @@ void insertUser() { "user1", auditInfo); Assertions.assertThrows( - AlreadyExistsException.class, () -> userMetaService.insertUser(user1Exist, false)); + EntityAlreadyExistsException.class, () -> userMetaService.insertUser(user1Exist, false)); // insert overwrite UserEntity user1Overwrite = @@ -192,7 +193,7 @@ void insertUser() { "user2", auditInfo); Assertions.assertThrows( - AlreadyExistsException.class, () -> userMetaService.insertUser(user2Exist, false)); + EntityAlreadyExistsException.class, () -> userMetaService.insertUser(user2Exist, false)); // insert overwrite user with 2 roles UserEntity user2Overwrite = @@ -254,7 +255,7 @@ void insertUser() { } @Test - void deleteUser() { + void deleteUser() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -331,7 +332,7 @@ void deleteUser() { } @Test - void updateUser() { + void updateUser() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -545,7 +546,7 @@ void updateUser() { } @Test - void deleteMetalake() { + void deleteMetalake() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -626,7 +627,7 @@ void deleteMetalake() { } @Test - void deleteMetalakeCascade() { + void deleteMetalakeCascade() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake = @@ -705,7 +706,7 @@ void deleteMetalakeCascade() { } @Test - void deleteUserMetasByLegacyTimeline() { + void deleteUserMetasByLegacyTimeline() throws IOException { AuditInfo auditInfo = AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build(); BaseMetalake metalake =