yuqi1129 commented on code in PR #12675:
URL: https://github.com/apache/gravitino/pull/12675#discussion_r3871444215
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/JobMetaService.java:
##########
@@ -125,6 +117,46 @@ public void insertJob(JobEntity jobEntity, boolean
overwrite) throws IOException
}
}
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
baseMetricName = "updateJob")
+ public <E extends Entity & HasIdentifier> JobEntity updateJob(
+ NameIdentifier jobIdent, Function<E, E> updater) throws IOException {
+ JobPO oldJobPO = getJobPO(jobIdent);
+ JobEntity oldJobEntity = JobPO.fromJobPO(oldJobPO, jobIdent.namespace());
+ JobEntity newJobEntity = (JobEntity) updater.apply((E) oldJobEntity);
+ Preconditions.checkArgument(
+ Objects.equals(oldJobEntity.id(), newJobEntity.id()),
+ "The updated job entity id: %s is not equal to the old one: %s, which
is unexpected",
+ newJobEntity.id(),
+ oldJobEntity.id());
+
+ JobPO.JobPOBuilder newBuilder =
JobPO.builder().withMetalakeId(oldJobPO.metalakeId());
+ JobPO newJobPO = JobPO.updateJobPO(oldJobPO, newJobEntity, newBuilder);
+
+ Integer result;
+ try {
+ result =
+ SessionUtils.doWithCommitAndFetchResult(
+ JobMetaMapper.class, mapper -> mapper.updateJobMeta(newJobPO,
oldJobPO));
+ } catch (RuntimeException e) {
+ ExceptionUtils.checkSQLException(e, Entity.EntityType.JOB,
oldJobEntity.name());
+ throw e;
+ }
+
+ if (result == null || result == 0) {
+ throw new NoSuchEntityException(
Review Comment:
We can throw `OptimisticLockException` here.
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/JobMetaService.java:
##########
@@ -125,6 +117,46 @@ public void insertJob(JobEntity jobEntity, boolean
overwrite) throws IOException
}
}
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
baseMetricName = "updateJob")
+ public <E extends Entity & HasIdentifier> JobEntity updateJob(
+ NameIdentifier jobIdent, Function<E, E> updater) throws IOException {
+ JobPO oldJobPO = getJobPO(jobIdent);
+ JobEntity oldJobEntity = JobPO.fromJobPO(oldJobPO, jobIdent.namespace());
+ JobEntity newJobEntity = (JobEntity) updater.apply((E) oldJobEntity);
+ Preconditions.checkArgument(
+ Objects.equals(oldJobEntity.id(), newJobEntity.id()),
+ "The updated job entity id: %s is not equal to the old one: %s, which
is unexpected",
+ newJobEntity.id(),
+ oldJobEntity.id());
+
+ JobPO.JobPOBuilder newBuilder =
JobPO.builder().withMetalakeId(oldJobPO.metalakeId());
+ JobPO newJobPO = JobPO.updateJobPO(oldJobPO, newJobEntity, newBuilder);
+
+ Integer result;
+ try {
+ result =
+ SessionUtils.doWithCommitAndFetchResult(
+ JobMetaMapper.class, mapper -> mapper.updateJobMeta(newJobPO,
oldJobPO));
+ } catch (RuntimeException e) {
+ ExceptionUtils.checkSQLException(e, Entity.EntityType.JOB,
oldJobEntity.name());
+ throw e;
+ }
+
+ if (result == null || result == 0) {
+ throw new NoSuchEntityException(
Review Comment:
We should not regard `result == 0 ` as the entity does not exist; it can
also be the case that the job exists but has been changed by another writer.
--
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]