You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2017/06/07 14:11:20 UTC

[16/50] [abbrv] lucene-solr:feature/autoscaling: SOLR-10799: Refator HttpShardHandler.prepDistributed collection of shard replicas

SOLR-10799: Refator HttpShardHandler.prepDistributed collection of shard replicas


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/3618fc52
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/3618fc52
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/3618fc52

Branch: refs/heads/feature/autoscaling
Commit: 3618fc529dff85ee604614b3c545fa0b5fbf3b06
Parents: 393a2ed
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Fri Jun 2 10:34:30 2017 -0700
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Fri Jun 2 10:34:30 2017 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 ++
 .../handler/component/HttpShardHandler.java     | 47 +++++++++++++-------
 2 files changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3618fc52/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 195443d..6b664e4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -225,6 +225,9 @@ Other Changes
   support in favor of the <mergePolicyFactory> element introduced by SOLR-8621 in Solr 5.5.0.
   (Christine Poerschke, hossman)
 
+* SOLR-10799: Extracted functionality to collect eligible replicas from HttpShardHandler.prepDistributed()
+  to a new method (Domenico Fabio Marino via Tomás Fernández Löbbe)
+
 ==================  6.7.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3618fc52/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
index bc620b6..2954cff 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
@@ -30,6 +30,7 @@ import java.util.concurrent.CompletionService;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Predicate;
 
 import org.apache.http.client.HttpClient;
 import org.apache.solr.client.solrj.SolrClient;
@@ -398,18 +399,11 @@ public class HttpShardHandler extends ShardHandler {
             continue;
             // throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "no such shard: " + sliceName);
           }
-          Replica shardLeader = null;
-
-          final Collection<Replica> allSliceReplicas = slice.getReplicasMap().values();
-          final List<Replica> eligibleSliceReplicas = new ArrayList<>(allSliceReplicas.size());
-          for (Replica replica : allSliceReplicas) {
-            if (!clusterState.liveNodesContain(replica.getNodeName())
-                || replica.getState() != Replica.State.ACTIVE
-                || (onlyNrtReplicas && replica.getType() == Replica.Type.PULL)) {
-              continue;
-            }
-            
-            if (onlyNrtReplicas && replica.getType() == Replica.Type.TLOG) {
+          final Predicate<Replica> isShardLeader = new Predicate<Replica>() {
+            private Replica shardLeader = null;
+
+            @Override
+            public boolean test(Replica replica) {
               if (shardLeader == null) {
                 try {
                   shardLeader = zkController.getZkStateReader().getLeaderRetry(cloudDescriptor.getCollectionName(), slice.getName());
@@ -424,12 +418,11 @@ public class HttpShardHandler extends ShardHandler {
                   throw e;
                 }
               }
-              if (!replica.getName().equals(shardLeader.getName())) {
-                continue;
-              }
+              return replica.getName().equals(shardLeader.getName());
             }
-            eligibleSliceReplicas.add(replica);
-          }
+          };
+
+          final List<Replica> eligibleSliceReplicas = collectEligibleReplicas(slice, clusterState, onlyNrtReplicas, isShardLeader);
 
           replicaListTransformer.transform(eligibleSliceReplicas);
 
@@ -462,6 +455,26 @@ public class HttpShardHandler extends ShardHandler {
     }
   }
 
+  private static List<Replica> collectEligibleReplicas(Slice slice, ClusterState clusterState, boolean onlyNrtReplicas, Predicate<Replica> isShardLeader) {
+    final Collection<Replica> allSliceReplicas = slice.getReplicasMap().values();
+    final List<Replica> eligibleSliceReplicas = new ArrayList<>(allSliceReplicas.size());
+    for (Replica replica : allSliceReplicas) {
+      if (!clusterState.liveNodesContain(replica.getNodeName())
+          || replica.getState() != Replica.State.ACTIVE
+          || (onlyNrtReplicas && replica.getType() == Replica.Type.PULL)) {
+        continue;
+      }
+
+      if (onlyNrtReplicas && replica.getType() == Replica.Type.TLOG) {
+        if (!isShardLeader.test(replica)) {
+          continue;
+        }
+      }
+      eligibleSliceReplicas.add(replica);
+    }
+    return eligibleSliceReplicas;
+  }
+
   private static String createSliceShardsStr(final List<String> shardUrls) {
     final StringBuilder sliceShardsStr = new StringBuilder();
     boolean first = true;