mirror of https://github.com/apache/lucene.git
added extra clause
This commit is contained in:
parent
b933b60407
commit
a1f5cc8d9b
|
@ -195,16 +195,18 @@ public class Clause implements MapWriter, Comparable<Clause> {
|
|||
final String shard, coll, node;
|
||||
final Object actualVal;
|
||||
final Integer delta;//how far is the actual value from the expected value
|
||||
final Object tagKey;
|
||||
private final int hash;
|
||||
|
||||
|
||||
private Violation(String coll, String shard, String node, Object actualVal, Integer delta ) {
|
||||
private Violation(String coll, String shard, String node, Object actualVal, Integer delta, Object tagKey) {
|
||||
this.shard = shard;
|
||||
this.coll = coll;
|
||||
this.node = node;
|
||||
this.delta = delta;
|
||||
this.actualVal = actualVal;
|
||||
hash = ("" + coll + " " + shard + " " + node + " " + Utils.toJSONString(getClause().toMap(new HashMap<>()))).hashCode();
|
||||
this.tagKey = tagKey;
|
||||
hash = ("" + coll + " " + shard + " " + node + " " + String.valueOf(tagKey) + " " + Utils.toJSONString(getClause().toMap(new HashMap<>()))).hashCode();
|
||||
}
|
||||
|
||||
public Clause getClause() {
|
||||
|
@ -219,10 +221,12 @@ public class Clause implements MapWriter, Comparable<Clause> {
|
|||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof Violation) {
|
||||
Violation ve = (Violation) that;
|
||||
return Objects.equals(this.shard, (ve).shard) &&
|
||||
Objects.equals(this.coll, (ve).coll) &&
|
||||
Objects.equals(this.node, (ve).node);
|
||||
Violation v = (Violation) that;
|
||||
return Objects.equals(this.shard, v.shard) &&
|
||||
Objects.equals(this.coll, v.coll) &&
|
||||
Objects.equals(this.node, v.node) &&
|
||||
Objects.equals(this.tagKey, v.tagKey)
|
||||
;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -232,6 +236,7 @@ public class Clause implements MapWriter, Comparable<Clause> {
|
|||
ew.putIfNotNull("collection", coll);
|
||||
ew.putIfNotNull("shard", shard);
|
||||
ew.putIfNotNull("node", node);
|
||||
ew.putIfNotNull("tagKey", String.valueOf(tagKey));
|
||||
ew.putIfNotNull("violation", (MapWriter) ew1 -> {
|
||||
ew1.put(getClause().isPerCollectiontag() ? "replica" : tag.name,
|
||||
String.valueOf(actualVal));
|
||||
|
@ -252,8 +257,14 @@ public class Clause implements MapWriter, Comparable<Clause> {
|
|||
if (!shard.isPass(shardVsCount.getKey())) continue;
|
||||
for (Map.Entry<String, AtomicInteger> counts : shardVsCount.getValue().entrySet()) {
|
||||
if (!replica.isPass(counts.getValue())) {
|
||||
errors.add(new Violation(e.getKey(), shardVsCount.getKey(),
|
||||
tag.name.equals("node") ? counts.getKey() : null, counts.getValue(), replica.delta(counts.getValue())));
|
||||
errors.add(new Violation(
|
||||
e.getKey(),
|
||||
shardVsCount.getKey(),
|
||||
tag.name.equals("node") ? counts.getKey() : null,
|
||||
counts.getValue(),
|
||||
replica.delta(counts.getValue()),
|
||||
counts.getKey()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +272,7 @@ public class Clause implements MapWriter, Comparable<Clause> {
|
|||
} else {
|
||||
for (Row r : allRows) {
|
||||
if (!tag.isPass(r)) {
|
||||
errors.add(new Violation(null, null, r.node, r.getVal(tag.name) , tag.delta(r.getVal(tag.name))));
|
||||
errors.add(new Violation(null, null, r.node, r.getVal(tag.name), tag.delta(r.getVal(tag.name)), null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,14 +384,17 @@ public class Policy implements MapWriter {
|
|||
boolean isLessSerious(List<Violation> fresh, List<Violation> old) {
|
||||
if (old == null || fresh.size() < old.size()) return true;
|
||||
if(fresh.size() == old.size()){
|
||||
for (int i = 0; i < old.size(); i++) {
|
||||
if(fresh.get(i).equals(old.get(i))) {
|
||||
if (fresh.get(i) != null &&
|
||||
old.get(i).delta != null &&
|
||||
Math.abs(fresh.get(i).delta) < Math.abs(old.get(i).delta))
|
||||
return true;
|
||||
for (int i = 0; i < fresh.size(); i++) {
|
||||
Violation freshViolation = fresh.get(i);
|
||||
Violation oldViolation = null;
|
||||
for (Violation v : old) {
|
||||
if(v.equals(freshViolation)){
|
||||
oldViolation =v;
|
||||
}
|
||||
}
|
||||
if (oldViolation != null && oldViolation.delta != null &&
|
||||
Math.abs(fresh.get(i).delta) < Math.abs(oldViolation.delta)) return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -221,7 +221,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
|
|||
" 'cluster-policy':[" +
|
||||
" {'cores':'<10','node':'#ANY'}," +
|
||||
" {'replica':'<3','shard':'#EACH','node':'#ANY'}," +
|
||||
" { 'replica': 2, 'sysprop.fs': 'ssd', 'shard': '#EACH'}," +
|
||||
" { 'replica': 2, 'sysprop.fs': 'ssd', 'shard': '#EACH'}," +//greedy condition
|
||||
" {'nodeRole':'overseer','replica':'0'}]," +
|
||||
" 'cluster-preferences':[" +
|
||||
" {'minimize':'cores', 'precision':3}," +
|
||||
|
@ -264,12 +264,23 @@ public class TestPolicy extends SolrTestCaseJ4 {
|
|||
.getOperation();
|
||||
assertNotNull(op);
|
||||
assertEquals("node3", op.getParams().get("node"));
|
||||
op = suggester
|
||||
suggester = suggester
|
||||
.getSession()
|
||||
.getSuggester(ADDREPLICA)
|
||||
.hint(Hint.COLL, "newColl")
|
||||
.hint(Hint.SHARD, "shard1")
|
||||
.getOperation();
|
||||
.hint(Hint.SHARD, "shard1");
|
||||
op = suggester.getOperation();
|
||||
assertNotNull(op);
|
||||
assertEquals("node3", op.getParams().get("node"));
|
||||
|
||||
suggester = suggester
|
||||
.getSession()
|
||||
.getSuggester(ADDREPLICA)
|
||||
.hint(Hint.COLL, "newColl")
|
||||
.hint(Hint.SHARD, "shard1");
|
||||
op = suggester.getOperation();
|
||||
assertNotNull(op);
|
||||
assertEquals("node2", op.getParams().get("node"));
|
||||
}
|
||||
|
||||
public void testMoveReplica() {
|
||||
|
|
Loading…
Reference in New Issue