Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

more constraints added

Noble Paul011712ff005f
diff --git a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Clause.java b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Clause.java
index dfac6b88ef7..71ced9e814a 100644
--- a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Clause.java
+++ b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Clause.java
@@ -29,15 +29,12 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.solr.cloud.autoscaling.Policy.ReplicaInfo;
import org.apache.solr.common.MapWriter;
+import org.apache.solr.common.util.StrUtils;
import org.apache.solr.common.util.Utils;
-import org.apache.solr.cloud.autoscaling.Policy.ReplicaInfo;
-import static java.util.Collections.reverseOrder;
import static java.util.Collections.singletonMap;
-import static org.apache.solr.common.params.CoreAdminParams.COLLECTION;
-import static org.apache.solr.common.params.CoreAdminParams.REPLICA;
-import static org.apache.solr.common.params.CoreAdminParams.SHARD;
import static org.apache.solr.cloud.autoscaling.Clause.TestStatus.PASS;
import static org.apache.solr.cloud.autoscaling.Operand.EQUAL;
import static org.apache.solr.cloud.autoscaling.Operand.GREATER_THAN;
@@ -45,6 +42,9 @@ import static org.apache.solr.cloud.autoscaling.Operand.LESS_THAN;
import static org.apache.solr.cloud.autoscaling.Operand.NOT_EQUAL;
import static org.apache.solr.cloud.autoscaling.Operand.WILDCARD;
import static org.apache.solr.cloud.autoscaling.Policy.ANY;
+import static org.apache.solr.common.params.CoreAdminParams.COLLECTION;
+import static org.apache.solr.common.params.CoreAdminParams.REPLICA;
+import static org.apache.solr.common.params.CoreAdminParams.SHARD;
// a set of conditions in a policy
public class Clause implements MapWriter, Comparable<Clause> {
@@ -62,13 +62,21 @@ public class Clause implements MapWriter, Comparable<Clause> {
if (m.size() > 2) {
throw new RuntimeException("Only one extra tag supported for the tag " + globalTagName.get() + " in " + Utils.toJSONString(m));
}
- tag = parse(m.keySet().stream().filter(s -> (!globalTagName.get().equals(s) && !IGNORE_TAGS.contains(s))).findFirst().get(), m);
+ tag = parse(m.keySet().stream()
+ .filter(s -> (!globalTagName.get().equals(s) && !IGNORE_TAGS.contains(s)))
+ .findFirst().get(), m);
} else {
collection = parse(COLLECTION, m);
shard = parse(SHARD, m);
+ if(m.get(REPLICA) == null){
+ throw new RuntimeException(StrUtils.formatString("'replica' is required" + Utils.toJSONString(m)));
+ }
Condition replica = parse(REPLICA, m);
try {
int replicaCount = Integer.parseInt(String.valueOf(replica.val));
+ if(replicaCount<0){
+ throw new RuntimeException("replica value sould be non null "+ Utils.toJSONString(m));
+ }
this.replica = new Condition(replica.name, replicaCount, replica.op);
} catch (NumberFormatException e) {
throw new RuntimeException("Only an integer value is supported for replica " + Utils.toJSONString(m));
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 af258abda32..c8a661e20bf 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
@@ -262,7 +262,14 @@ public class Policy implements MapWriter {
}
enum SortParam {
- freedisk, cores, heapUsage, sysLoadAvg;
+ freedisk(0, Integer.MAX_VALUE), cores(0, Integer.MAX_VALUE), heapUsage(0, Integer.MAX_VALUE), sysLoadAvg(0, 100);
+
+ public final int min,max;
+
+ SortParam(int min, int max) {
+ this.min = min;
+ this.max = max;
+ }
static SortParam get(String m) {
for (SortParam p : values()) if (p.name().equals(m)) return p;
@@ -323,8 +330,7 @@ public class Policy implements MapWriter {
/* A suggester is capable of suggesting a collection operation
* given a particular session. Before it suggests a new operation,
* it ensures that ,
- * a) the node that it lightens load on the 'most loaded node' and/or 'lightens load'
- * on the least loaded node
+ * a) load is reduced on the most loaded node
* b) it causes no new violations
*
*/
diff --git a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Preference.java b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Preference.java
index 4b69e72e0c0..69a9b9eefcd 100644
--- a/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Preference.java
+++ b/solr/solrj/src/java/org/apache/solr/cloud/autoscaling/Preference.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.apache.solr.common.MapWriter;
+import org.apache.solr.common.util.StrUtils;
import org.apache.solr.common.util.Utils;
class Preference implements MapWriter {
@@ -41,6 +42,10 @@ class Preference implements MapWriter {
if (precision < 0) {
throw new RuntimeException("precision must be a positive value ");
}
+ if(precision< name.min || precision> name.max){
+ throw new RuntimeException(StrUtils.formatString("invalid precision value {0} must lie between {1} and {1}",
+ precision, name.min, name.max ) );
+ }
}