This is an automated email from the ASF dual-hosted git repository. sureshanaparti pushed a commit to branch 4.18 in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push: new 22ef08154dc Switch back to CLOUD_DB after purging usage records (#9367) 22ef08154dc is described below commit 22ef08154dc89ccce27121578cabfa3b5030220d Author: Vishesh <vishes...@gmail.com> AuthorDate: Sun Jul 14 14:58:36 2024 +0530 Switch back to CLOUD_DB after purging usage records (#9367) --- .../java/com/cloud/usage/dao/UsageDaoImpl.java | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java index 4553ed822b4..038d17a85a3 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java @@ -28,6 +28,7 @@ import com.cloud.utils.db.QueryBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.exception.CloudRuntimeException; @@ -469,21 +470,25 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage @Override public void removeOldUsageRecords(int days) { - String sql = DELETE_ALL_BY_INTERVAL; - TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); - PreparedStatement pstmt = null; - try { - txn.start(); - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, days); - pstmt.executeUpdate(); - txn.commit(); - } catch (Exception ex) { - txn.rollback(); - s_logger.error("error removing old cloud_usage records for interval: " + days); - } finally { - txn.close(); - } + Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallbackNoReturn() { + @Override + public void doInTransactionWithoutResult(TransactionStatus status) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + PreparedStatement pstmt = null; + try { + txn.start(); + pstmt = txn.prepareAutoCloseStatement(DELETE_ALL_BY_INTERVAL); + pstmt.setLong(1, days); + pstmt.executeUpdate(); + txn.commit(); + } catch (Exception ex) { + txn.rollback(); + s_logger.error("error removing old cloud_usage records for interval: " + days); + } finally { + txn.close(); + } + } + }); } public UsageVO persistUsage(final UsageVO usage) {