<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [5096] [RHQ-2407] - use truncate statements instead of delete statements for alerts purging (this has been sitting on my box for weeks now); </title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5096</dd> <dt>Author</dt> <dd>jmarques</dd> <dt>Date</dt> <dd>2009-09-03 06:22:20 -0500 (Thu, 03 Sep 2009)</dd> </dl> <h3>Log Message</h3> <pre>[RHQ-2407] - use truncate statements instead of delete statements for alerts purging (this has been sitting on my box for weeks now); </pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainalertAlertjava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java</a></li> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainalertAlertConditionLogjava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertConditionLog.java</a></li> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainalertnotificationAlertNotificationLogjava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotificationLog.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserveralertAlertManagerBeanjava">rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainalertAlertjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java (5095 => 5096)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java 2009-09-03 11:20:53 UTC (rev 5095) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java 2009-09-03 11:22:20 UTC (rev 5096) </span><span class="lines">@@ -204,6 +204,8 @@ </span><span class="cx"> public static final String QUERY_FIND_BY_MEAS_DEF_ID_AND_RESOURCE = "Alert.findByMeasDefIdAndResource"; public static final String QUERY_GET_ALERT_COUNT_FOR_SCHEDULES = "Alert.QUERY_GET_ALERT_COUNT_FOR_SCHEDULES"; </span><span class="add">+ public static final String QUERY_NATIVE_TRUNCATE_SQL = "TRUNCATE TABLE RHQ_ALERT"; + </span><span class="cx"> // for subsystem view public static final String QUERY_FIND_ALL_COMPOSITES = "Alert.findAllComposites"; public static final String QUERY_FIND_ALL_COMPOSITES_ADMIN = "Alert.findAllComposites_admin"; </span></pre></div> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainalertAlertConditionLogjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertConditionLog.java (5095 => 5096)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertConditionLog.java 2009-09-03 11:20:53 UTC (rev 5095) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertConditionLog.java 2009-09-03 11:22:20 UTC (rev 5096) </span><span class="lines">@@ -72,6 +72,8 @@ </span><span class="cx"> public static final String QUERY_DELETE_BY_ALERT_CTIME = "AlertConditionLog.deleteByAlertCTime"; public static final String QUERY_DELETE_UNMATCHED_BY_ALERT_DEFINITION_ID = "AlertConditionLog.deleteUnmatchedByAlertDefinitionId"; </span><span class="add">+ public static final String QUERY_NATIVE_TRUNCATE_SQL = "TRUNCATE TABLE RHQ_ALERT_CONDITION_LOG"; + </span><span class="cx"> public static final int MAX_LOG_LENGTH = 250; private static final long serialVersionUID = 1L; </span></pre></div> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainalertnotificationAlertNotificationLogjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotificationLog.java (5095 => 5096)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotificationLog.java 2009-09-03 11:20:53 UTC (rev 5095) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotificationLog.java 2009-09-03 11:22:20 UTC (rev 5096) </span><span class="lines">@@ -70,6 +70,8 @@ </span><span class="cx"> public static final String QUERY_DELETE_BY_ALERT_CTIME = "AlertNotificationLog.deleteByAlertCtime"; public static final String QUERY_DELETE_BY_RESOURCES = "AlertNotificationLog.deleteByResources"; </span><span class="add">+ public static final String QUERY_NATIVE_TRUNCATE_SQL = "TRUNCATE TABLE RHQ_ALERT_NOTIF_LOG"; + </span><span class="cx"> @Column(name = "ID", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO, generator = "RHQ_ALERT_NOTIF_LOG_ID_SEQ") @Id </span></pre></div> <a id="rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserveralertAlertManagerBeanjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java (5095 => 5096)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java 2009-09-03 11:20:53 UTC (rev 5095) +++ rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java 2009-09-03 11:22:20 UTC (rev 5096) </span><span class="lines">@@ -18,6 +18,9 @@ </span><span class="cx"> */ package org.rhq.enterprise.server.alert; </span><span class="add">+import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; </span><span class="cx"> import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; </span><span class="lines">@@ -34,6 +37,7 @@ </span><span class="cx"> import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; </span><span class="add">+import javax.sql.DataSource; </span><span class="cx"> import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; </span><span class="lines">@@ -69,6 +73,7 @@ </span><span class="cx"> import org.rhq.core.domain.util.PageOrdering; import org.rhq.core.domain.util.PersistenceUtility; import org.rhq.core.util.collection.ArrayUtils; </span><span class="add">+import org.rhq.core.util.jdbc.JDBCUtil; </span><span class="cx"> import org.rhq.enterprise.server.RHQConstants; import org.rhq.enterprise.server.alert.i18n.AlertI18NFactory; import org.rhq.enterprise.server.alert.i18n.AlertI18NResourceKeys; </span><span class="lines">@@ -88,6 +93,7 @@ </span><span class="cx"> * @author Ian Springer */ @Stateless </span><span class="add">+...@ja...source(name = "RHQ_DS", mappedName = RHQConstants.DATASOURCE_JNDI_NAME) </span><span class="cx"> public class AlertManagerBean implements AlertManagerLocal, AlertManagerRemote { @PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME) private EntityManager entityManager; </span><span class="lines">@@ -114,6 +120,9 @@ </span><span class="cx"> @EJB private EmailManagerLocal emailManager; </span><span class="add">+ @javax.annotation.Resource(name = "RHQ_DS") + private DataSource rhqDs; + </span><span class="cx"> private static Date bootTime = null; /** </span><span class="lines">@@ -256,6 +265,59 @@ </span><span class="cx"> return deletedAlerts; } </span><span class="add">+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) + @TransactionTimeout(6 * 60 * 60) + public int purgeAlerts() { + long totalTime = 0; + + Connection conn = null; + PreparedStatement truncateConditionLogsStatement = null; + PreparedStatement truncateNotificationLogsStatement = null; + PreparedStatement truncateAlertsStatement = null; + try { + conn = rhqDs.getConnection(); + + truncateConditionLogsStatement = conn.prepareStatement(AlertConditionLog.QUERY_NATIVE_TRUNCATE_SQL); + truncateNotificationLogsStatement = conn.prepareStatement(AlertNotificationLog.QUERY_NATIVE_TRUNCATE_SQL); + truncateAlertsStatement = conn.prepareStatement(Alert.QUERY_NATIVE_TRUNCATE_SQL); + + long start = System.currentTimeMillis(); + int purgedConditions = truncateConditionLogsStatement.executeUpdate(); + long end = System.currentTimeMillis(); + log.debug("Purged [" + purgedConditions + "] alert condition logs in [" + (end - start) + "]ms"); + totalTime += (end - start); + + start = System.currentTimeMillis(); + int purgedNotifications = truncateNotificationLogsStatement.executeUpdate(); + end = System.currentTimeMillis(); + log.debug("Purged [" + purgedNotifications + "] alert notifications in [" + (end - start) + "]ms"); + totalTime += (end - start); + + start = System.currentTimeMillis(); + int purgedAlerts = truncateAlertsStatement.executeUpdate(); + end = System.currentTimeMillis(); + log.debug("Purged [" + purgedAlerts + "] alerts in [" + (end - start) + "]ms"); + totalTime += (end - start); + + MeasurementMonitor.getMBean().incrementPurgeTime(totalTime); + MeasurementMonitor.getMBean().setPurgedAlerts(purgedAlerts); + MeasurementMonitor.getMBean().setPurgedAlertConditions(purgedConditions); + MeasurementMonitor.getMBean().setPurgedAlertNotifications(purgedNotifications); + log.debug("Deleted [" + (purgedAlerts + purgedConditions + purgedNotifications) + "] " + + "alert audit records in [" + (totalTime) + "]ms"); + + return purgedAlerts; + } catch (SQLException sqle) { + log.error("Error purging alerts", sqle); + throw new RuntimeException("Error purging alerts: " + sqle.getMessage()); + } finally { + JDBCUtil.safeClose(truncateConditionLogsStatement); + JDBCUtil.safeClose(truncateNotificationLogsStatement); + JDBCUtil.safeClose(truncateAlertsStatement); + JDBCUtil.safeClose(conn); + } + } + </span><span class="cx"> /** * Get the alert with the specified id. */ </span> </pre> </div> </div> </body> </html> |