Skip to content

Commit 22ef081

Browse files
authored
Switch back to CLOUD_DB after purging usage records (#9367)
1 parent beebeed commit 22ef081

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.cloud.utils.db.SearchCriteria;
2929
import com.cloud.utils.db.Transaction;
3030
import com.cloud.utils.db.TransactionCallback;
31+
import com.cloud.utils.db.TransactionCallbackNoReturn;
3132
import com.cloud.utils.db.TransactionLegacy;
3233
import com.cloud.utils.db.TransactionStatus;
3334
import com.cloud.utils.exception.CloudRuntimeException;
@@ -469,21 +470,25 @@ public void saveUsageRecords(List<UsageVO> usageRecords) {
469470

470471
@Override
471472
public void removeOldUsageRecords(int days) {
472-
String sql = DELETE_ALL_BY_INTERVAL;
473-
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
474-
PreparedStatement pstmt = null;
475-
try {
476-
txn.start();
477-
pstmt = txn.prepareAutoCloseStatement(sql);
478-
pstmt.setLong(1, days);
479-
pstmt.executeUpdate();
480-
txn.commit();
481-
} catch (Exception ex) {
482-
txn.rollback();
483-
s_logger.error("error removing old cloud_usage records for interval: " + days);
484-
} finally {
485-
txn.close();
486-
}
473+
Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallbackNoReturn() {
474+
@Override
475+
public void doInTransactionWithoutResult(TransactionStatus status) {
476+
TransactionLegacy txn = TransactionLegacy.currentTxn();
477+
PreparedStatement pstmt = null;
478+
try {
479+
txn.start();
480+
pstmt = txn.prepareAutoCloseStatement(DELETE_ALL_BY_INTERVAL);
481+
pstmt.setLong(1, days);
482+
pstmt.executeUpdate();
483+
txn.commit();
484+
} catch (Exception ex) {
485+
txn.rollback();
486+
s_logger.error("error removing old cloud_usage records for interval: " + days);
487+
} finally {
488+
txn.close();
489+
}
490+
}
491+
});
487492
}
488493

489494
public UsageVO persistUsage(final UsageVO usage) {

0 commit comments

Comments
 (0)