modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
| 111 ++--------
1 file changed, 28 insertions(+), 83 deletions(-)
New commits:
commit c4b841ac57b3d2cc6c0302184d027d499da2375c
Author: Joseph Marques <joseph(a)redhat.com>
Date: Mon Jun 28 23:30:21 2010 -0400
delete obsolete call-time data code
* CallTimeData reports already ensure that (schedule_id, begin_time) is unique
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
index 265c0e7..253765d 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
@@ -88,12 +88,6 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
+ "(schedule_id, call_destination) " + "SELECT ?, ? FROM
RHQ_numbers WHERE i = 42 "
+ "AND NOT EXISTS (SELECT * FROM " + DATA_KEY_TABLE_NAME + " WHERE
schedule_id = ? AND call_destination = ?)";
- /*
- private static final String CALLTIME_VALUE_DELETE_SUPERCEDED_STATEMENT = "DELETE
FROM " + DATA_VALUE_TABLE_NAME
- + " WHERE key_id = " + "(SELECT id FROM " +
DATA_KEY_TABLE_NAME
- + " WHERE schedule_id = ? AND call_destination = ?) AND begin_time =
?";
- */
-
private static final String CALLTIME_VALUE_INSERT_STATEMENT = "INSERT /*+ APPEND
*/ INTO " + DATA_VALUE_TABLE_NAME
+ "(id, key_id, begin_time, end_time, minimum, maximum, total, count)
"
+ "SELECT %s, key.id, ?, ?, ?, ?, ?, ? FROM RHQ_numbers num,
RHQ_calltime_data_key key WHERE num.i = 42 "
@@ -135,32 +129,6 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
// First make sure a single row exists in the key table for each reported call
destination.
callTimeDataManager.insertCallTimeDataKeys(callTimeDataSet);
- /*
- * TODO: JM - Is this really needed? Under what circumstances are duplicates
generated? Are we presuming
- * this is a misbehaving plugin, or a problem at the comm-layer where the
same piece of data is delivered
- * twice? I'm tentatively removing this because it is a big hit to
call-time data reporting performance.
- * If, however, evidence is presented that implores us to bring this
functionality back, it should be
- * implemented by getting rid of the duplicate data points that share the
same key_id and begin_time.
- * These records can be found with:
- *
- * SELECT key_id, begin_time, count(id)
- * FROM rhq_calltime_data_value
- * GROUP BY key_id, begin_time
- * HAVING count(id) > 1
- *
- * This is functionally equivalent to the
CALLTIME_VALUE_DELETE_SUPERCEDED_STATEMENT query, but takes
- * advantage of the fact that key_id represents the already-computed pair
of schedule_id/destination, thus
- * allowing the duplicate-search to be implemented against a single table.
- *
- * Taking this solution one step further, an appropriate delete statement
can be crafted which leverages
- * the above concept but deletes all but one of the duplicates (perhaps
leaving the record with the
- * smallest id/pk). This purge routine can either be grouped in with the
rest in DataPurgeJob, or it can
- * be implemented as its own quartz job that runs more (or less)
frequently, depending on our needs
- * (i.e., how often we anticipate duplicates)
- */
- // Delete any existing rows that have the same key and begin time as the data
about to be inserted.
- //callTimeDataManager.deleteRedundantCallTimeDataValues(callTimeDataSet);
-
// Finally, add the stats themselves to the value table.
callTimeDataManager.insertCallTimeDataValues(callTimeDataSet);
}
@@ -373,55 +341,6 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
}
/*
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void deleteRedundantCallTimeDataValues(Set<CallTimeData>
callTimeDataSet) {
-
- int[] results;
- PreparedStatement ps = null;
- Connection conn = null;
-
- try {
- conn = rhqDs.getConnection();
- ps = conn.prepareStatement(CALLTIME_VALUE_DELETE_SUPERCEDED_STATEMENT);
- for (CallTimeData callTimeData : callTimeDataSet) {
- ps.setInt(1, callTimeData.getScheduleId());
- Set<String> callDestinations = callTimeData.getValues().keySet();
- for (String callDestination : callDestinations) {
- ps.setString(2, callDestination);
- CallTimeDataValue value =
callTimeData.getValues().get(callDestination);
- ps.setLong(3, value.getBeginTime());
- ps.addBatch();
- }
- }
-
- results = ps.executeBatch();
-
- int deletedRowCount = 0;
- for (int i = 0; i < results.length; i++) {
- if ((results[i] < 0) && (results[i] != -2)) // oracle returns
-2 because it can't count updated rows
- {
- throw new MeasurementStorageException("Failed to delete
redundant call-time data rows - result ["
- + results[i] + "] for batch command [" + i + "] is
less than 0.");
- }
-
- deletedRowCount += results[i];
- }
-
- log
- .debug("Deleted "
- + ((deletedRowCount >= 0) ? deletedRowCount : "?")
- + " redundant call-time data value rows that were superceded by
data in the measurement report currently being processed.");
- } catch (SQLException e) {
- logSQLException("Failed to delete redundant call-time data values",
e);
- } catch (Throwable t) {
- log.error("Failed to delete redundant call-time data values", t);
- } finally {
- JDBCUtil.safeClose(conn, ps, null);
- }
- }
- */
-
- /*
* internal method, do not expose to the remote API
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
commit bff7953bd68384a51ae5d9f8c629f42e3d29d9e6
Author: Joseph Marques <joseph(a)redhat.com>
Date: Mon Jun 28 23:28:15 2010 -0400
use hints for postgres and oracle to allow faster insertion of call-time data
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
index 5a25f85..265c0e7 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/CallTimeDataManagerBean.java
@@ -21,6 +21,7 @@ package org.rhq.enterprise.server.measurement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -44,6 +45,7 @@ import org.rhq.core.db.DatabaseType;
import org.rhq.core.db.DatabaseTypeFactory;
import org.rhq.core.db.H2DatabaseType;
import org.rhq.core.db.OracleDatabaseType;
+import org.rhq.core.db.Postgresql83DatabaseType;
import org.rhq.core.db.PostgresqlDatabaseType;
import org.rhq.core.db.SQLServerDatabaseType;
import org.rhq.core.domain.auth.Subject;
@@ -78,7 +80,7 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
private static final String DATA_VALUE_TABLE_NAME =
"RHQ_CALLTIME_DATA_VALUE";
private static final String DATA_KEY_TABLE_NAME = "RHQ_CALLTIME_DATA_KEY";
- private static final String CALLTIME_KEY_INSERT_STATEMENT = "INSERT INTO "
+ DATA_KEY_TABLE_NAME
+ private static final String CALLTIME_KEY_INSERT_STATEMENT = "INSERT /*+ APPEND
*/ INTO " + DATA_KEY_TABLE_NAME
+ "(id, schedule_id, call_destination) " + "SELECT %s, ?, ? FROM
RHQ_numbers WHERE i = 42 "
+ "AND NOT EXISTS (SELECT * FROM " + DATA_KEY_TABLE_NAME + " WHERE
schedule_id = ? AND call_destination = ?)";
@@ -92,7 +94,7 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
+ " WHERE schedule_id = ? AND call_destination = ?) AND begin_time =
?";
*/
- private static final String CALLTIME_VALUE_INSERT_STATEMENT = "INSERT INTO
" + DATA_VALUE_TABLE_NAME
+ private static final String CALLTIME_VALUE_INSERT_STATEMENT = "INSERT /*+ APPEND
*/ INTO " + DATA_VALUE_TABLE_NAME
+ "(id, key_id, begin_time, end_time, minimum, maximum, total, count)
"
+ "SELECT %s, key.id, ?, ?, ?, ?, ?, ? FROM RHQ_numbers num,
RHQ_calltime_data_key key WHERE num.i = 42 "
+ "AND key.id = (SELECT id FROM " + DATA_KEY_TABLE_NAME + " WHERE
schedule_id = ? AND call_destination = ?)";
@@ -312,6 +314,18 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
try {
conn = rhqDs.getConnection();
DatabaseType dbType = DatabaseTypeFactory.getDatabaseType(conn);
+
+ if (dbType instanceof Postgresql83DatabaseType) {
+ Statement st = null;
+ try {
+ // Take advantage of async commit here
+ st = conn.createStatement();
+ st.execute("SET synchronous_commit = off");
+ } finally {
+ JDBCUtil.safeClose(st);
+ }
+ }
+
if (dbType instanceof PostgresqlDatabaseType || dbType instanceof
OracleDatabaseType
|| dbType instanceof H2DatabaseType) {
String keyNextvalSql = JDBCUtil.getNextValSql(conn,
"RHQ_calltime_data_key");
@@ -420,6 +434,18 @@ public class CallTimeDataManagerBean implements
CallTimeDataManagerLocal, CallTi
try {
conn = rhqDs.getConnection();
DatabaseType dbType = DatabaseTypeFactory.getDatabaseType(conn);
+
+ if (dbType instanceof Postgresql83DatabaseType) {
+ Statement st = null;
+ try {
+ // Take advantage of async commit here
+ st = conn.createStatement();
+ st.execute("SET synchronous_commit = off");
+ } finally {
+ JDBCUtil.safeClose(st);
+ }
+ }
+
if (dbType instanceof PostgresqlDatabaseType || dbType instanceof
OracleDatabaseType
|| dbType instanceof H2DatabaseType) {
String valueNextvalSql = JDBCUtil.getNextValSql(conn,
"RHQ_calltime_data_value");