ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From magyari_san...@apache.org
Subject ambari git commit: AMBARI-17449. When querying host role command entities, the number of parameters should be limited. (Daniel Gergely via magyari_sandor)
Date Tue, 28 Jun 2016 10:09:09 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 818de68ae -> 614b4c05a


AMBARI-17449. When querying host role command entities, the number of parameters should be
limited. (Daniel Gergely via magyari_sandor)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/614b4c05
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/614b4c05
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/614b4c05

Branch: refs/heads/branch-2.4
Commit: 614b4c05a4e1d5979ad41e3261016f18771cdfec
Parents: 818de68
Author: Daniel Gergely <dgergely@hortonworks.com>
Authored: Tue Jun 28 11:58:28 2016 +0200
Committer: Sandor Magyari <smagyari@hortonworks.com>
Committed: Tue Jun 28 12:04:32 2016 +0200

----------------------------------------------------------------------
 .../server/configuration/Configuration.java      | 18 ++++++++++++++++++
 .../apache/ambari/server/orm/dao/DaoUtils.java   |  2 --
 .../server/orm/dao/HostRoleCommandDAO.java       | 19 ++++++++++---------
 3 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/614b4c05/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 2eb0734..3743220 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -777,6 +777,14 @@ public class Configuration {
    */
   public static final String METRIC_RETRIEVAL_SERVICE_THREADPOOL_WORKER_QUEUE_SIZE = "server.metrics.retrieval-service.threadpool.worker.size";
 
+  /**
+   * The number of tasks that can be queried from the database at once
+   * In the case of more tasks, multiple queries are issued
+   * @return
+   */
+  private static final String TASK_ID_LIST_LIMIT = "task.query.parameterlist.size";
+  private static final int TASK_ID_LIST_LIMIT_DEFAULT = 999;
+
   private static final Logger LOG = LoggerFactory.getLogger(
     Configuration.class);
 
@@ -3216,4 +3224,14 @@ public class Configuration {
             String.valueOf(10 * getMetricsServiceThreadPoolMaxSize())));
   }
 
+  /**
+   * Returns the number of tasks that can be queried from the database at once
+   * In the case of more tasks, multiple queries are issued
+   * @return
+   */
+  public int getTaskIdListLimit() {
+    return Integer.parseInt(properties.getProperty(TASK_ID_LIST_LIMIT,
+            String.valueOf(TASK_ID_LIST_LIMIT_DEFAULT)));
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/614b4c05/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
index 7f157ec..bdcece5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
@@ -37,8 +37,6 @@ public class DaoUtils {
   @Inject
   private DBAccessor dbAccessor;
 
-  public static final int ORACLE_LIST_LIMIT = 999;
-
   public DbType getDbType() {
     return dbAccessor.getDbType();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/614b4c05/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
index 1768f21..17760c7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
@@ -18,9 +18,6 @@
 
 package org.apache.ambari.server.orm.dao;
 
-import static org.apache.ambari.server.orm.DBAccessor.DbType.ORACLE;
-import static org.apache.ambari.server.orm.dao.DaoUtils.ORACLE_LIST_LIMIT;
-
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -46,6 +43,7 @@ import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.api.query.JpaPredicateVisitor;
 import org.apache.ambari.server.api.query.JpaSortBuilder;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.spi.PageRequest;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
@@ -138,10 +136,13 @@ public class HostRoleCommandDAO {
 
 
   @Inject
-  Provider<EntityManager> entityManagerProvider;
+  private Provider<EntityManager> entityManagerProvider;
+
+  @Inject
+  private DaoUtils daoUtils;
 
   @Inject
-  DaoUtils daoUtils;
+  private Configuration configuration;
 
   /**
    * Used to ensure that methods which rely on the completion of
@@ -278,10 +279,10 @@ public class HostRoleCommandDAO {
         "ORDER BY task.taskId",
       HostRoleCommandEntity.class);
 
-    if (daoUtils.getDbType().equals(ORACLE) && taskIds.size() > ORACLE_LIST_LIMIT)
{
+    if (taskIds.size() > configuration.getTaskIdListLimit()) {
       List<HostRoleCommandEntity> result = new ArrayList<HostRoleCommandEntity>();
 
-      List<List<Long>> lists = Lists.partition(new ArrayList<Long>(taskIds),
ORACLE_LIST_LIMIT);
+      List<List<Long>> lists = Lists.partition(new ArrayList<Long>(taskIds),
configuration.getTaskIdListLimit());
       for (List<Long> list : lists) {
         result.addAll(daoUtils.selectList(query, list));
       }
@@ -348,10 +349,10 @@ public class HostRoleCommandDAO {
             "ORDER BY task.taskId", Long.class
     );
 
-    if (daoUtils.getDbType().equals(ORACLE) && taskIds.size() > ORACLE_LIST_LIMIT)
{
+    if (taskIds.size() > configuration.getTaskIdListLimit()) {
       List<Long> result = new ArrayList<Long>();
 
-      List<List<Long>> lists = Lists.partition(new ArrayList<Long>(taskIds),
ORACLE_LIST_LIMIT);
+      List<List<Long>> lists = Lists.partition(new ArrayList<Long>(taskIds),
configuration.getTaskIdListLimit());
       for (List<Long> taskIdList : lists) {
         result.addAll(daoUtils.selectList(query, requestIds, taskIdList));
       }


Mime
View raw message