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:18:26 UTC

[ambari] branch trunk updated: AMBARI-25629: For kerberos service check IN clause must be split into batches (#3575)

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 3e3ab3f3b7 AMBARI-25629: For kerberos service check IN clause must be split into batches (#3575)
3e3ab3f3b7 is described below

commit 3e3ab3f3b731fbf86faca430c0b508ff8d4b85a3
Author: Yu Hou <52...@qq.com>
AuthorDate: Sat Nov 26 16:18:21 2022 +0800

    AMBARI-25629: For kerberos service check IN clause must be split into batches (#3575)
---
 .../ambari/server/orm/dao/KerberosKeytabPrincipalDAO.java   | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabPrincipalDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabPrincipalDAO.java
index bb8ac6cfa3..eb43439865 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabPrincipalDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabPrincipalDAO.java
@@ -36,6 +36,8 @@ import org.apache.ambari.server.orm.entities.KerberosKeytabEntity;
 import org.apache.ambari.server.orm.entities.KerberosKeytabPrincipalEntity;
 import org.apache.ambari.server.orm.entities.KerberosKeytabServiceMappingEntity;
 import org.apache.ambari.server.orm.entities.KerberosPrincipalEntity;
+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.inject.Inject;
@@ -242,8 +244,17 @@ public class KerberosKeytabPrincipalDAO {
       }
     }
 
+    //Split principals into batches and combine them using OR
     if (CollectionUtils.isNotEmpty(filter.getPrincipals())) {
-      predicates.add(root.get("principalName").in(filter.getPrincipals()));
+      ArrayList<Predicate> principalPredicates = new ArrayList<>();
+      SQLOperations.batch(filter.getPrincipals(), SQLConstants.IN_ARGUMENT_MAX_SIZE,
+        (chunk, currentBatch, totalBatches, totalSize) -> {
+          principalPredicates.add(root.get("principalName").in(chunk));
+          return 0;
+        });
+
+      Predicate principalCombinedPredicate = cb.or(principalPredicates.toArray(new Predicate[0]));
+      predicates.add(principalCombinedPredicate);
     }
     cq.where(cb.and(predicates.toArray(new Predicate[0])));
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org