Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 1115146 - Purge (delete) data using smaller batches
Browse files Browse the repository at this point in the history
Introduced JDBCPurgeTemplate

Update purge process for:
* availabilities
* traits
* events
* calltime data values
* alerts (and notif log and condition log)
* OOB

Batch size:
* is shared across implementation of the template
* is configurable through a sys prop
* value is unbounded
* defaults to 3000
  • Loading branch information
tsegismont committed Jul 23, 2014
1 parent fe30df2 commit df5ddda
Show file tree
Hide file tree
Showing 38 changed files with 1,566 additions and 399 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -20,6 +20,7 @@
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.rhq.core.domain.alert;

import java.io.Serializable;
Expand Down Expand Up @@ -215,6 +216,10 @@
@Table(name = "RHQ_ALERT")
public class Alert implements Serializable {
public static final String QUERY_FIND_BY_MEASUREMENT_DEFINITION_ID = "Alert.findByMeasurementDefinitionId";
/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String QUERY_DELETE_BY_CTIME = "Alert.deleteByCTime";
public static final String QUERY_RETURN_EXISTING_IDS = "Alert.returnExistingIds";
public static final String QUERY_CHECK_PERMISSION_BY_IDS = "Alert.checkPermissionByIds";
Expand All @@ -233,6 +238,10 @@ public class Alert implements Serializable {
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";

/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String QUERY_NATIVE_TRUNCATE_SQL = "TRUNCATE TABLE RHQ_ALERT";

// for subsystem view
Expand All @@ -253,7 +262,7 @@ public class Alert implements Serializable {
@ManyToOne
private AlertDefinition alertDefinition;

@OneToMany(mappedBy = "alert", cascade = CascadeType.ALL, orphanRemoval=true)
@OneToMany(mappedBy = "alert", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy
// primary key
private Set<AlertConditionLog> conditionLogs = new LinkedHashSet<AlertConditionLog>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -20,6 +20,7 @@
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.rhq.core.domain.alert;

import java.io.Serializable;
Expand Down Expand Up @@ -118,9 +119,17 @@ public class AlertConditionLog implements Serializable {
public static final String QUERY_DELETE_BY_RESOURCES_BULK_DELETE = "AlertConditionLog.deleteByResourcesBulkDelete";
public static final String QUERY_DELETE_BY_RESOURCE_TEMPLATE = "AlertConditionLog.deleteByResourceType";
public static final String QUERY_DELETE_BY_RESOURCE_GROUPS = "AlertConditionLog.deleteByResourceGroups";
/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String QUERY_DELETE_BY_ALERT_CTIME = "AlertConditionLog.deleteByAlertCTime";
public static final String QUERY_DELETE_UNMATCHED_BY_ALERT_DEFINITION_ID = "AlertConditionLog.deleteUnmatchedByAlertDefinitionId";

/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String QUERY_NATIVE_TRUNCATE_SQL = "TRUNCATE TABLE RHQ_ALERT_CONDITION_LOG";

public static final int MAX_LOG_LENGTH = 250;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -20,6 +20,7 @@
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.rhq.core.domain.alert.notification;

import java.io.Serializable;
Expand Down Expand Up @@ -98,8 +99,16 @@ public class AlertNotificationLog implements Serializable {
public static final String QUERY_DELETE_BY_RESOURCES = "AlertNotificationLog.deleteByResources";
public static final String QUERY_DELETE_BY_RESOURCE_TEMPLATE = "AlertNotificationLog.deleteByResourceType";
public static final String QUERY_DELETE_BY_RESOURCE_GROUPS = "AlertNotificationLog.deleteByResourceGroups";
/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String QUERY_DELETE_BY_ALERT_CTIME = "AlertNotificationLog.deleteByAlertCtime";

/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String QUERY_NATIVE_TRUNCATE_SQL = "TRUNCATE TABLE RHQ_ALERT_NOTIF_LOG";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -20,6 +20,7 @@
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.rhq.core.domain.measurement;

import java.io.Serializable;
Expand Down Expand Up @@ -156,6 +157,10 @@ public class Availability implements Serializable {
public static final String QUERY_DELETE_BY_RESOURCES = "Availability.deleteByResources";
public static final String FIND_FOR_AGENT_PLATFORM = "Availability.findForAgentPlatform";

/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String NATIVE_QUERY_PURGE = "DELETE FROM RHQ_AVAILABILITY WHERE END_TIME < ?";

@Column(name = "ID", nullable = false)
Expand Down Expand Up @@ -318,4 +323,4 @@ public boolean equals(Object obj) {

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation, and/or the GNU Lesser
* General Public License, version 2.1, also as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
* RHQ Management Platform
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation, and/or the GNU Lesser
* General Public License, version 2.1, also as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.rhq.core.domain.measurement;

import javax.persistence.Column;
Expand Down Expand Up @@ -52,6 +53,14 @@ public MeasurementDataPK(long timestamp, int scheduleId) {
this.scheduleId = scheduleId;
}

public long getTimestamp() {
return timestamp;
}

public int getScheduleId() {
return scheduleId;
}

@Override
public int hashCode() {
final int PRIME = 31;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -20,6 +20,7 @@
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.rhq.core.domain.measurement;

import javax.persistence.Entity;
Expand All @@ -28,7 +29,7 @@
import javax.persistence.Table;

@Entity
@NamedQueries( {
@NamedQueries({
@NamedQuery(name = MeasurementDataTrait.FIND_CURRENT_FOR_RESOURCE_AND_DISPLAY_TYPE, query = "SELECT trait, d.displayName "
+ "FROM MeasurementDataTrait trait JOIN trait.schedule s join s.definition d JOIN s.resource r"
+ " WHERE r.id = :resourceId "
Expand Down Expand Up @@ -78,11 +79,10 @@ public class MeasurementDataTrait extends MeasurementData {

public static final String QUERY_DELETE_BY_RESOURCES = "MeasurementDataTrait.deleteByResources";

/*
* NOTE: Avoid using the AS keyword in the FROM clauses in this query, because Oracle barfs on it
* (see http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/ap_standard_sql003.htm, subfeature id
* E051-08).
/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String NATIVE_QUERY_PURGE = "" //
+ "DELETE FROM rhq_measurement_data_trait " // SQL Server doesn't like aliases, use full table name
+ "WHERE EXISTS " // rewritten as exists because H2 doesn't support multi-column conditions
Expand Down Expand Up @@ -154,4 +154,4 @@ public String toString() {
+ this.id.scheduleId + ", timestamp=" + this.id.timestamp + "]";
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -13,9 +13,10 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

package org.rhq.core.domain.measurement;

import javax.persistence.Column;
Expand All @@ -30,7 +31,7 @@
*
* @author Heiko W. Rupp
*/
@NamedQueries( {
@NamedQueries({
@NamedQuery(name = MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE, query = "" //
+ " SELECT new org.rhq.core.domain.measurement.composite.MeasurementOOBComposite" //
+ " ( res.name, res.id, res.ancestry, res.resourceType.id, def.displayName, sched.id, o.timestamp, def.id, o.oobFactor, " //
Expand Down Expand Up @@ -140,6 +141,10 @@ public class MeasurementOOB {
public static final String GET_SCHEDULES_WITH_OOB_AGGREGATE = "GetSchedulesWithOObAggregate";
public static final String GET_SCHEDULES_WITH_OOB_AGGREGATE_ADMIN = "GetSchedulesWithOObAggregate_admin";
public static final String GET_SCHEDULES_WITH_OOB_AGGREGATE_COUNT = "GetSchedulesWithOObAggregateCount";
/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String DELETE_OUTDATED = "DeleteOutdatedOOBs";
public static final String COUNT_FOR_DATE = "CountOOBForDate";
public static final String GET_HIGHEST_FACTORS_FOR_RESOURCE = "GetHighestOOBFactorForResource";
Expand Down Expand Up @@ -225,8 +230,16 @@ public class MeasurementOOB {
+ " FROM rhq_measurement_oob \n "
+ " WHERE rhq_measurement_oob.schedule_id = rhq_measurement_oob_tmp.schedule_id ) )";

/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String TRUNCATE_TMP_TABLE = "TRUNCATE TABLE rhq_measurement_oob_tmp";

/**
* @deprecated as of RHQ 4.13, no longer used
*/
@Deprecated
public static final String SECURITY_ADDITION = "" //
+ " AND ( res.id IN ( SELECT rr.id FROM Resource rr " //
+ " JOIN rr.implicitGroups g JOIN g.roles r JOIN r.subjects s " //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2008 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -13,9 +13,10 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

package org.rhq.enterprise.server.alert.test;

import java.sql.Connection;
Expand All @@ -36,6 +37,7 @@
import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.resource.Resource;
import org.rhq.enterprise.server.alert.AlertManagerLocal;
import org.rhq.enterprise.server.purge.PurgeManagerLocal;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;

Expand All @@ -45,12 +47,14 @@
@Test(enabled = false)
public class DeleteAlertsTest extends AbstractEJB3Test {
private AlertManagerLocal alertManager;
private PurgeManagerLocal purgeManager;
private Subject superuser;
private Resource newResource;

@Override
protected void beforeMethod() throws Exception {
alertManager = LookupUtil.getAlertManager();
purgeManager = LookupUtil.getPurgeManager();
superuser = LookupUtil.getSubjectManager().getOverlord();

Connection connection = null;
Expand Down Expand Up @@ -115,7 +119,8 @@ public void deleteAlertsForResourceTemplate() {
}

public void testAlertDeleteInRange() {
assert 2 == alertManager.deleteAlerts(0L, System.currentTimeMillis() + 600000L); // go out into the future to make sure we get our alert
// go out into the future to make sure we get our alert
assert 2 == purgeManager.deleteAlerts(0L, System.currentTimeMillis() + 600000L);
}

}
}

0 comments on commit df5ddda

Please sign in to comment.