diff --git a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Policy.java b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Policy.java index 8a1292d1490..614bfa27d82 100644 --- a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Policy.java +++ b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Policy.java @@ -165,13 +165,7 @@ public class Policy implements MapWriter { .collect(Collectors.toList()); for (String c : collections) { - String p = dataProvider.getPolicy(c); - if (p != null) { - List perCollPolicy = policies.get(p); - if (perCollPolicy == null) - throw new RuntimeException(StrUtils.formatString("Policy for collection {0} is {1} . It does not exist", c, p)); - } - expandedClauses.addAll(mergePolicies(c, policies.getOrDefault(p, emptyList()), clusterPolicy)); + addClausesForCollection(dataProvider, c); } Collections.sort(expandedClauses); @@ -183,6 +177,16 @@ public class Policy implements MapWriter { applyRules(); } + private void addClausesForCollection(ClusterDataProvider dataProvider, String c) { + String p = dataProvider.getPolicy(c); + if (p != null) { + List perCollPolicy = policies.get(p); + if (perCollPolicy == null) + throw new RuntimeException(StrUtils.formatString("Policy for collection {0} is {1} . It does not exist", c, p)); + } + expandedClauses.addAll(mergePolicies(c, policies.getOrDefault(p, emptyList()), clusterPolicy)); + } + Session copy() { return new Session(nodes, dataProvider, getMatrixCopy(), expandedClauses, paramsOfInterest); } @@ -343,6 +347,16 @@ public class Policy implements MapWriter { public SolrRequest getOperation() { if (!isInitialized) { + String coll = (String) hints.get(Hint.COLL); + if(coll != null){ + // if this is not a known collection from the existing clusterstate, + // then add it + if(session.matrix.stream().noneMatch(row -> row.replicaInfo.containsKey(coll))){ + session.matrix.get(0).replicaInfo.put(coll, new HashMap<>()); + session.addClausesForCollection(session.dataProvider, coll); + Collections.sort(session.expandedClauses); + } + } session.applyRules(); originalViolations.addAll(session.getViolations()); this.operation = init(); diff --git a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/PolicyHelper.java b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/PolicyHelper.java index 2012be805de..6b199c21026 100644 --- a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/PolicyHelper.java +++ b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/PolicyHelper.java @@ -54,13 +54,7 @@ public class PolicyHelper { @Override public Map>> getReplicaInfo(String node, Collection keys) { - Map>> replicaInfo = delegate.getReplicaInfo(node, keys); - for (String s : optionalPolicyMapping.keySet()) { - if (!replicaInfo.containsKey(s)) { - replicaInfo.put(s, new HashMap<>()); - } - } - return replicaInfo; + return delegate.getReplicaInfo(node, keys); } @Override