This is an automated email from the ASF dual-hosted git repository. hapylestat pushed a commit to branch branch-2.7 in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-2.7 by this push: new 9846f6d AMBARI-25627 ORA-01795 error when querying hostcomponentdesiredstate table on large cluster (#3292) (tpayer via dgrinenko) 9846f6d is described below commit 9846f6d8be30d42a6a37b1f1dac9897ce0a87016 Author: Tamas Payer <35402259+pay...@users.noreply.github.com> AuthorDate: Wed Mar 10 09:32:01 2021 +0100 AMBARI-25627 ORA-01795 error when querying hostcomponentdesiredstate table on large cluster (#3292) (tpayer via dgrinenko) --- .../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 1af1e0c..1df6120 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