jerryshao commented on code in PR #11036:
URL: https://github.com/apache/gravitino/pull/11036#discussion_r3225159799
##########
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:
Why do we delete then insert?
--
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]