This is an automated email from the ASF dual-hosted git repository.
payert 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 f977d9f AMBARI-25629 For kerberos service check IN clause must be
split into batches (#3293)
f977d9f is described below
commit f977d9f43e2e59d8d4c2a08de67a7972cc8a21f9
Author: Tamas Payer <[email protected]>
AuthorDate: Wed Mar 10 10:56:24 2021 +0100
AMBARI-25629 For kerberos service check IN clause must be split into
batches (#3293)
---
.../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 bb8ac6c..eb43439 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])));