You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2020/02/26 15:59:44 UTC
[lucene-solr] 02/02: SOLR-14275: More imrpovements.
This is an automated email from the ASF dual-hosted git repository.
ab pushed a commit to branch jira/solr-14275
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 97450ee53d8a60096da18172aae9507f0160241f
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Wed Feb 26 16:53:52 2020 +0100
SOLR-14275: More imrpovements.
---
.../client/solrj/cloud/autoscaling/Clause.java | 6 +--
.../solrj/cloud/autoscaling/FreeDiskVariable.java | 45 ++++++++++++++--------
.../client/solrj/cloud/autoscaling/Policy.java | 2 +-
.../solrj/cloud/autoscaling/ReplicaVariable.java | 3 ++
.../solr/client/solrj/cloud/autoscaling/Row.java | 4 ++
5 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Clause.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Clause.java
index 474d67b..56671b2 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Clause.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Clause.java
@@ -669,9 +669,9 @@ public class Clause implements MapWriter, Comparable<Clause> {
return Policy.ANY.equals(shard.val);
}
- public List<Violation> test(Policy.Session session, double[] deviations) {
- return test(session, null, deviations);
- }
+// public List<Violation> test(Policy.Session session, double[] deviations) {
+// return test(session, null, deviations);
+// }
public List<Violation> test(Policy.Session session, Row changedRow, double[] deviations) {
if (isPerCollectiontag()) {
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/FreeDiskVariable.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/FreeDiskVariable.java
index a3a14dd..29de2a1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/FreeDiskVariable.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/FreeDiskVariable.java
@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -145,26 +144,40 @@ public class FreeDiskVariable extends VariableBase {
}
+ private static final class IndexSizeGetter {
+ final String collection, shard;
+
+ IndexSizeGetter(String collection, String shard) {
+ this.collection = collection;
+ this.shard = shard;
+ }
+
+ Object getIndexSize(Row row) {
+ Object[] result = new Object[1];
+ row.forEachShard(collection, (sh, replicas) -> {
+ if (sh.equals(shard)) {
+ for (ReplicaInfo replicaInfo : replicas) {
+ if (replicaInfo.getVariable(CORE_IDX.tagName) != null) {
+ result[0] = replicaInfo.getVariable(CORE_IDX.tagName);
+ return;
+ }
+ }
+ }
+ });
+ return result[0];
+ }
+ }
+
//When a replica is added, freedisk should be decremented
@Override
public void projectAddReplica(Cell cell, ReplicaInfo ri, Consumer<Row.OperationInfo> ops, boolean strictMode) {
//go through other replicas of this shard and copy the index size value into this
- AtomicBoolean indexSizeSet = new AtomicBoolean();
+ IndexSizeGetter getter = new IndexSizeGetter(ri.getCollection(), ri.getShard());
for (Row row : cell.getRow().session.matrix) {
- Object indexSize = row.computeCacheIfAbsent(ri.getCollection(), ri.getShard(), "freedisk", CORE_IDX.tagName, o -> {
- Object[] result = new Object[1];
- row.forEachShard(ri.getCollection(), (shard, replicas) -> {
- if (ri.getShard().equals(shard)) {
- for (ReplicaInfo replicaInfo : replicas) {
- if (replicaInfo.getVariable(CORE_IDX.tagName) != null) {
- result[0] = replicaInfo.getVariable(CORE_IDX.tagName);
- return;
- }
- }
- }
- });
- return result[0];
- });
+ if (row.isEmpty() || !row.isLive() || !row.hasColl(ri.getCollection())) {
+ continue;
+ }
+ Object indexSize = row.computeCacheIfAbsent(ri.getCollection(), ri.getShard(), "freedisk", CORE_IDX.tagName, o -> getter.getIndexSize(row));
if (indexSize != null) {
ri.getVariables().put(CORE_IDX.tagName, validate(CORE_IDX.tagName, indexSize, false));
break;
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
index 0cb3cb3..e624920 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
@@ -682,7 +682,7 @@ public class Policy implements MapWriter {
sortNodes();
for (Clause clause : expandedClauses) {
- List<Violation> errs = clause.test(this, null);
+ List<Violation> errs = clause.test(this, null, null);
violations.addAll(errs);
}
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaVariable.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaVariable.java
index d31bd2d..cff1f73 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaVariable.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaVariable.java
@@ -58,6 +58,9 @@ class ReplicaVariable extends VariableBase {
Clause clause = cv.getClause();
ReplicaCounter counter = new ReplicaCounter(collection, shard, clause);
for (Row row : session.matrix) {
+ if (row.isEmpty() || !row.isLive() || !row.hasColl(collection)) {
+ continue;
+ }
Integer perShardCount = row.computeCacheIfAbsent(collection, shard, REPLICASCOUNT, cv.clause, o -> counter.calculate(row));
if (perShardCount != null)
totalReplicasOfInterest += perShardCount;
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
index ddf9751..196e17c 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
@@ -268,6 +268,10 @@ public class Row implements MapWriter {
isAlreadyCopied = true;
}
+ boolean isEmpty() {
+ return collectionVsShardVsReplicas.isEmpty();
+ }
+
boolean hasColl(String coll) {
return collectionVsShardVsReplicas.containsKey(coll);
}