From 6c6aa4eae6f79b06c5b4617cd87f7caec7c2451a Mon Sep 17 00:00:00 2001 From: Aaron Chung Date: Mon, 4 May 2026 22:26:07 -0700 Subject: [PATCH] Optimize UsageJobDaoImpl.updateJobSuccess to use direct UPDATE instead of row-level lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace lockRow + explicit transaction with a single update(jobId, jobForUpdate) call. All field values are parameters passed by the caller — nothing is read from the locked row. The TransactionLegacy.open(USAGE_DB) is kept since this method explicitly targets the usage database. The txn.start/commit/rollback are removed since the single update() call is autocommit. The lock was redundant because the usage server model is single-owner: one server processes one job at a time. --- .../main/java/com/cloud/usage/dao/UsageJobDaoImpl.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java index 6f340501cf18..68ad8fa12edd 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java @@ -61,9 +61,6 @@ public long getLastJobSuccessDateMillis() { public void updateJobSuccess(Long jobId, long startMillis, long endMillis, long execTime, boolean success) { TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); try { - txn.start(); - - UsageJobVO job = lockRow(jobId, Boolean.TRUE); UsageJobVO jobForUpdate = createForUpdate(); jobForUpdate.setStartMillis(startMillis); jobForUpdate.setEndMillis(endMillis); @@ -71,11 +68,8 @@ public void updateJobSuccess(Long jobId, long startMillis, long endMillis, long jobForUpdate.setStartDate(new Date(startMillis)); jobForUpdate.setEndDate(new Date(endMillis)); jobForUpdate.setSuccess(success); - update(job.getId(), jobForUpdate); - - txn.commit(); + update(jobId, jobForUpdate); } catch (Exception ex) { - txn.rollback(); logger.error("error updating job success date", ex); throw new CloudRuntimeException(ex.getMessage()); } finally {