jerryshao commented on code in PR #12675:
URL: https://github.com/apache/gravitino/pull/12675#discussion_r3871625670
##########
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:
No, I don't solve the OCC problem. I just use update to solve the
check-and-update problem. I think you can work on OCC based on this.
--
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]