World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
Fix early return in GroupMetaService.updateGroup ignoring non-role changes (#8255)
JeonDaehongbfddf5cbcac2
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/GroupMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/GroupMetaService.javaindex 4329b3a0a1..14fec721e1 100644--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/GroupMetaService.java+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/GroupMetaService.java@@ -210,9 +210,6 @@ public class GroupMetaService {Set<Long> insertRoleIds = Sets.difference(newRoleIds, oldRoleIds);Set<Long> deleteRoleIds = Sets.difference(oldRoleIds, newRoleIds);- if (insertRoleIds.isEmpty() && deleteRoleIds.isEmpty()) {- return newEntity;- }try {SessionUtils.doMultipleWithCommit(() ->@@ -223,25 +220,23 @@ public class GroupMetaService {POConverters.updateGroupPOWithVersion(oldGroupPO, newEntity),oldGroupPO)),() -> {- if (insertRoleIds.isEmpty()) {- return;+ if (!insertRoleIds.isEmpty()) {+ SessionUtils.doWithoutCommit(+ GroupRoleRelMapper.class,+ mapper ->+ mapper.batchInsertGroupRoleRel(+ POConverters.initializeGroupRoleRelsPOWithVersion(+ newEntity, Lists.newArrayList(insertRoleIds))));}- SessionUtils.doWithoutCommit(- GroupRoleRelMapper.class,- mapper ->- mapper.batchInsertGroupRoleRel(- POConverters.initializeGroupRoleRelsPOWithVersion(- newEntity, Lists.newArrayList(insertRoleIds))));},() -> {- if (deleteRoleIds.isEmpty()) {- return;+ if (!deleteRoleIds.isEmpty()) {+ SessionUtils.doWithoutCommit(+ GroupRoleRelMapper.class,+ mapper ->+ mapper.softDeleteGroupRoleRelByGroupAndRoles(+ newEntity.id(), Lists.newArrayList(deleteRoleIds)));}- SessionUtils.doWithoutCommit(- GroupRoleRelMapper.class,- mapper ->- mapper.softDeleteGroupRoleRelByGroupAndRoles(- newEntity.id(), Lists.newArrayList(deleteRoleIds)));});} catch (RuntimeException re) {ExceptionUtils.checkSQLException(diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestGroupMetaService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestGroupMetaService.javaindex 5e90f0eb89..a5ab960693 100644--- a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestGroupMetaService.java+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestGroupMetaService.java@@ -1012,4 +1012,44 @@ class TestGroupMetaService extends TestJDBCBackend {}return count;}++ @Test+ void updateGroupWithoutRoleChange() throws IOException {+ AuditInfo auditInfo =+ AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build();+ BaseMetalake metalake =+ createBaseMakeLake(RandomIdGenerator.INSTANCE.nextId(), metalakeName, auditInfo);+ backend.insert(metalake, false);++ GroupMetaService groupMetaService = GroupMetaService.getInstance();++ GroupEntity group1 =+ createGroupEntity(+ RandomIdGenerator.INSTANCE.nextId(),+ AuthorizationUtils.ofGroupNamespace(metalakeName),+ "group1",+ auditInfo);+ groupMetaService.insertGroup(group1, false);++ Function<GroupEntity, GroupEntity> renameUpdater =+ group ->+ GroupEntity.builder()+ .withNamespace(group.namespace())+ .withId(group.id())+ .withName("group_renamed")+ .withRoleNames(group.roleNames())+ .withRoleIds(group.roleIds())+ .withAuditInfo(group.auditInfo())+ .build();+ groupMetaService.updateGroup(group1.nameIdentifier(), renameUpdater);++ Assertions.assertThrows(+ NoSuchEntityException.class,+ () -> groupMetaService.getGroupByIdentifier(group1.nameIdentifier()));++ GroupEntity updated =+ groupMetaService.getGroupByIdentifier(+ AuthorizationUtils.ofGroup(metalakeName, "group_renamed"));+ Assertions.assertEquals("group_renamed", updated.name());+ }}