Skip to content

Commit 6c6aa4e

Browse files
sliceofapplepievishesh92
authored andcommitted
Optimize UsageJobDaoImpl.updateJobSuccess to use direct UPDATE instead of row-level lock
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.
1 parent a289bb0 commit 6c6aa4e

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,15 @@ public long getLastJobSuccessDateMillis() {
6161
public void updateJobSuccess(Long jobId, long startMillis, long endMillis, long execTime, boolean success) {
6262
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
6363
try {
64-
txn.start();
65-
66-
UsageJobVO job = lockRow(jobId, Boolean.TRUE);
6764
UsageJobVO jobForUpdate = createForUpdate();
6865
jobForUpdate.setStartMillis(startMillis);
6966
jobForUpdate.setEndMillis(endMillis);
7067
jobForUpdate.setExecTime(execTime);
7168
jobForUpdate.setStartDate(new Date(startMillis));
7269
jobForUpdate.setEndDate(new Date(endMillis));
7370
jobForUpdate.setSuccess(success);
74-
update(job.getId(), jobForUpdate);
75-
76-
txn.commit();
71+
update(jobId, jobForUpdate);
7772
} catch (Exception ex) {
78-
txn.rollback();
7973
logger.error("error updating job success date", ex);
8074
throw new CloudRuntimeException(ex.getMessage());
8175
} finally {

0 commit comments

Comments
 (0)