[rhq] modules/enterprise
Jay Shaughnessy
jshaughn at fedoraproject.org
Mon Aug 6 19:20:48 UTC 2012
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StatusManagerBean.java | 29 +++++++---
1 file changed, 22 insertions(+), 7 deletions(-)
New commits:
commit 11f741ebd98c10d294e23d5f7174d12b67baea90
Author: Jay Shaughnessy <jshaughn at redhat.com>
Date: Mon Aug 6 15:08:20 2012 -0400
[Bug 828428 - org.rhq.enterprise.server.cloud.instance.CacheConsistencyManagerBean ERROR ORA-01795: maximum number of expressions in a list is 1000]
This time the problem is 1000 or more agents on a server (with status <> 0).
Batch the updates to avoid the Oracle limitation.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StatusManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StatusManagerBean.java
index dfd1990..9658dd1 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StatusManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/cloud/StatusManagerBean.java
@@ -95,13 +95,28 @@ public class StatusManagerBean implements StatusManagerLocal {
List<Integer> agentIds = selectQuery.getResultList();
if (agentIds.size() > 0) {
- /*
- * note: not worried about size of the in clause, because the number of
- * agents per server will be reasonable, say, 50-150
- */
- Query updateQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_CLEAR_STATUS_BY_IDS);
- updateQuery.setParameter("agentIds", agentIds);
- updateQuery.executeUpdate();
+
+ // handle the oracle 1000 member IN clause issue
+ final int ORACLE_BATCH_SIZE = 1000;
+
+ int numAgents = agentIds.size();
+ int batches = (numAgents / ORACLE_BATCH_SIZE) + 1;
+
+ // iterate over the agent ids when we have more than 1000 of them
+ for (int batch = 0; batch < batches; ++batch) {
+ int fromIndex = batch * ORACLE_BATCH_SIZE;
+ int toIndex = fromIndex + ORACLE_BATCH_SIZE;
+ if (toIndex > numAgents) // don't run over the end of the list
+ toIndex = numAgents;
+ List<Integer> agentIdBatch = agentIds.subList(fromIndex, toIndex);
+
+ if (fromIndex == toIndex)
+ continue;
+
+ Query updateQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_CLEAR_STATUS_BY_IDS);
+ updateQuery.setParameter("agentIds", agentIdBatch);
+ int numUpdated = updateQuery.executeUpdate();
+ }
}
return agentIds;
More information about the rhq-commits
mailing list