mirror of https://github.com/apache/lucene.git
SOLR-13504 improve autoscaling syntax by adding a nodeset attribute (#693)
* SOLR-13504: more checks and tests
This commit is contained in:
parent
b28de243be
commit
808f934cee
|
@ -57,13 +57,13 @@ import static org.apache.solr.common.util.Utils.toJSONString;
|
||||||
*/
|
*/
|
||||||
public class Clause implements MapWriter, Comparable<Clause> {
|
public class Clause implements MapWriter, Comparable<Clause> {
|
||||||
public static final String NODESET = "nodeset";
|
public static final String NODESET = "nodeset";
|
||||||
private static final Set<String> IGNORE_TAGS = new HashSet<>(Arrays.asList(REPLICA, COLLECTION, SHARD, "strict", "type", "put", NODESET));
|
static final Set<String> IGNORE_TAGS = new HashSet<>(Arrays.asList(REPLICA, COLLECTION, SHARD, "strict", "type", "put", NODESET));
|
||||||
|
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
final boolean hasComputedValue;
|
final boolean hasComputedValue;
|
||||||
final Map<String, Object> original;
|
final Map<String, Object> original;
|
||||||
final Clause derivedFrom;
|
final Clause derivedFrom;
|
||||||
private boolean nodeSetPresent = false;
|
boolean nodeSetPresent = false;
|
||||||
Condition collection, shard, replica, tag, globalTag;
|
Condition collection, shard, replica, tag, globalTag;
|
||||||
final Replica.Type type;
|
final Replica.Type type;
|
||||||
boolean strict;
|
boolean strict;
|
||||||
|
@ -568,10 +568,6 @@ public class Clause implements MapWriter, Comparable<Clause> {
|
||||||
|
|
||||||
public List<Violation> test(Policy.Session session, double[] deviations) {
|
public List<Violation> test(Policy.Session session, double[] deviations) {
|
||||||
if (isPerCollectiontag()) {
|
if (isPerCollectiontag()) {
|
||||||
if(nodeSetPresent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return tag.varType == Type.NODE ||
|
return tag.varType == Type.NODE ||
|
||||||
(tag.varType.meta.isNodeSpecificVal() && replica.computedType == null) ?
|
(tag.varType.meta.isNodeSpecificVal() && replica.computedType == null) ?
|
||||||
testPerNode(session, deviations) :
|
testPerNode(session, deviations) :
|
||||||
|
|
|
@ -45,6 +45,15 @@ public class VariableBase implements Variable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String postValidate(Condition condition) {
|
||||||
|
if(Clause.IGNORE_TAGS.contains(condition.getName())) return null;
|
||||||
|
if(condition.getOperand() == Operand.WILDCARD && condition.clause.nodeSetPresent){
|
||||||
|
return "#EACH not supported in tags in nodeset";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
static Object getOperandAdjustedValue(Object val, Object original) {
|
static Object getOperandAdjustedValue(Object val, Object original) {
|
||||||
if (original instanceof Condition) {
|
if (original instanceof Condition) {
|
||||||
Condition condition = (Condition) original;
|
Condition condition = (Condition) original;
|
||||||
|
|
|
@ -706,6 +706,12 @@ public class TestPolicy extends SolrTestCaseJ4 {
|
||||||
assertEquals(Variable.Type.NODE, clause.tag.varType);
|
assertEquals(Variable.Type.NODE, clause.tag.varType);
|
||||||
assertEquals(Operand.IN, clause.tag.op);
|
assertEquals(Operand.IN, clause.tag.op);
|
||||||
|
|
||||||
|
expectThrows(IllegalArgumentException.class,
|
||||||
|
() -> Clause.create("{replica:1, nodeset : {sysprop.zone : '#EACH'}}"));
|
||||||
|
|
||||||
|
expectThrows(IllegalArgumentException.class,
|
||||||
|
() -> Clause.create("{replica:1, nodeset : {host : '#EACH'}}"));
|
||||||
|
|
||||||
expectThrows(IllegalArgumentException.class,
|
expectThrows(IllegalArgumentException.class,
|
||||||
() -> Clause.create("{replica:1, node: n1, nodeset : {sysprop.zone : east}}"));
|
() -> Clause.create("{replica:1, node: n1, nodeset : {sysprop.zone : east}}"));
|
||||||
|
|
||||||
|
@ -1912,7 +1918,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
|
||||||
"{replica:0, nodeset:{'nodeRole':'overseer'},'strict':false}," +
|
"{replica:0, nodeset:{'nodeRole':'overseer'},'strict':false}," +
|
||||||
"{'replica':'<1','node':'node3'}," +
|
"{'replica':'<1','node':'node3'}," +
|
||||||
"{'replica':'<2','node':'#ANY','shard':'#EACH'}," +
|
"{'replica':'<2','node':'#ANY','shard':'#EACH'}," +
|
||||||
"{'replica':'<3','shard':'#EACH', nodeset : { 'sysprop.rack':'#EACH'}}" +
|
"{'replica':'<3','shard':'#EACH', nodeset : { 'sysprop.rack':[rack1, rack2, rack3, rack4]}}" +
|
||||||
"]" +
|
"]" +
|
||||||
"}" +
|
"}" +
|
||||||
"}";
|
"}";
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class TestPolicy2 extends SolrTestCaseJ4 {
|
||||||
" 'cluster-preferences':[{ minimize : cores},{maximize : freedisk, precision : 50}]}";
|
" 'cluster-preferences':[{ minimize : cores},{maximize : freedisk, precision : 50}]}";
|
||||||
if(useNodeset){
|
if(useNodeset){
|
||||||
autoScalingjson = "{cluster-policy:[" +
|
autoScalingjson = "{cluster-policy:[" +
|
||||||
" { replica : '<3' , shard : '#EACH', nodeset:{sysprop.zone: '#EACH'} } ]," +
|
" { replica : '<3' , shard : '#EACH', nodeset:{sysprop.zone: [east , west]} } ]," +
|
||||||
" 'cluster-preferences':[{ minimize : cores},{maximize : freedisk, precision : 50}]}";
|
" 'cluster-preferences':[{ minimize : cores},{maximize : freedisk, precision : 50}]}";
|
||||||
}
|
}
|
||||||
policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoScalingjson));
|
policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoScalingjson));
|
||||||
|
|
Loading…
Reference in New Issue