You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by wu...@apache.org on 2022/11/26 08:15:34 UTC
[ambari] branch trunk updated: AMBARI-25627: ORA-01795 error when querying hostcomponentdesiredstate table on large cluster (#3574)
This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9780d3f817 AMBARI-25627: ORA-01795 error when querying hostcomponentdesiredstate table on large cluster (#3574)
9780d3f817 is described below
commit 9780d3f817092ec2738026506249d0b655d17812
Author: Yu Hou <52...@qq.com>
AuthorDate: Sat Nov 26 16:15:29 2022 +0800
AMBARI-25627: ORA-01795 error when querying hostcomponentdesiredstate table on large cluster (#3574)
---
.../orm/dao/HostComponentDesiredStateDAO.java | 28 ++++++++++++++++------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
index 1af1e0ce5e..1df6120c99 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
@@ -18,7 +18,9 @@
package org.apache.ambari.server.orm.dao;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import javax.persistence.EntityManager;
@@ -28,7 +30,11 @@ import javax.persistence.TypedQuery;
import org.apache.ambari.server.orm.RequiresSession;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.helpers.SQLConstants;
+import org.apache.ambari.server.orm.helpers.SQLOperations;
+import org.apache.commons.collections.CollectionUtils;
+import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -124,13 +130,21 @@ public class HostComponentDesiredStateDAO {
@RequiresSession
public List<HostComponentDesiredStateEntity> findByHostsAndCluster(Collection<Long> hostIds, Long clusterId) {
- final TypedQuery<HostComponentDesiredStateEntity> query = entityManagerProvider.get()
- .createNamedQuery("HostComponentDesiredStateEntity.findByHostsAndCluster", HostComponentDesiredStateEntity.class);
-
- query.setParameter("hostIds", hostIds);
- query.setParameter("clusterId", clusterId);
-
- return daoUtils.selectList(query);
+ if (CollectionUtils.isEmpty(hostIds)) {
+ return Collections.<HostComponentDesiredStateEntity>emptyList();
+ }
+ final EntityManager entityManager = entityManagerProvider.get();
+ final TypedQuery<HostComponentDesiredStateEntity> query = entityManager.
+ createNamedQuery("HostComponentDesiredStateEntity.findByHostsAndCluster", HostComponentDesiredStateEntity.class);
+
+ final List<HostComponentDesiredStateEntity> result = new ArrayList<>();
+ SQLOperations.batch(hostIds, SQLConstants.IN_ARGUMENT_MAX_SIZE, (chunk, currentBatch, totalBatches, totalSize) -> {
+ query.setParameter("hostIds", chunk);
+ query.setParameter("clusterId", clusterId);
+ result.addAll(daoUtils.selectList(query));
+ return 0;
+ });
+ return Lists.newArrayList(result);
}
@Transactional
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org