roryqi commented on code in PR #11036:
URL: https://github.com/apache/gravitino/pull/11036#discussion_r3225189378
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/OwnerMetaService.java:
##########
@@ -172,4 +173,49 @@ public void setOwner(
SessionUtils.doWithoutCommit(
OwnerMetaMapper.class, mapper ->
mapper.insertOwnerRel(ownerRelPO)));
}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "batchSetOwner")
+ public void batchSetOwners(
+ List<NameIdentifier> ownedObjects,
+ Entity.EntityType ownedObjectType,
+ NameIdentifier ownerIdent,
+ Entity.EntityType ownerType) {
+ if (CollectionUtils.isEmpty(ownedObjects)) {
+ return;
+ }
+
+ String metalake = NameIdentifierUtil.getMetalake(ownedObjects.get(0));
+ for (NameIdentifier entity : ownedObjects) {
+ Preconditions.checkArgument(
+ Objects.equals(NameIdentifierUtil.getMetalake(entity), metalake),
+ "All owned objects must be in the same metalake");
+ }
+
+ long metalakeId =
MetalakeMetaService.getInstance().getMetalakeIdByName(metalake);
+ Long ownerId = EntityIdService.getEntityId(ownerIdent, ownerType);
+
+ List<OwnerRelDeletion> deletions = new ArrayList<>(ownedObjects.size());
+ List<OwnerRelPO> ownerRelPOs = new ArrayList<>(ownedObjects.size());
+ for (NameIdentifier entity : ownedObjects) {
+ Long entityId = EntityIdService.getEntityId(entity, ownedObjectType);
+ deletions.add(
+ new OwnerRelDeletion(
+ entityId,
+ NameIdentifierUtil.toMetadataObject(entity,
ownedObjectType).type().name()));
+ ownerRelPOs.add(
+ POConverters.initializeOwnerRelPOsWithVersion(
+ metalakeId, ownerType.name(), ownerId, ownedObjectType.name(),
entityId));
+ }
+
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ SessionUtils.doWithoutCommit(
+ OwnerMetaMapper.class,
+ mapper ->
mapper.batchSoftDeleteOwnerRelByMetadataObjects(deletions)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ OwnerMetaMapper.class, mapper ->
mapper.batchInsertOwnerRels(ownerRelPOs)));
+ }
Review Comment:
We need remove the old owner of the metadata object then set the new owner
to the metadata object.
For removing the old owner, we delete a old data.
For setting the new owner, we insert a new data.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]