Apache Solr open-source search software
SOLR-10800: Factor out HttpShardHandler.transformReplicasToShardUrls from HttpShardHandler.prepDistributed. (Domenico Fabio Marino, Christine Poerschke)
Christine Poerschkeb25dda0b209c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex d7eb46f41ea..7e45c3bcdfd 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -253,6 +253,9 @@ Other Changes* SOLR-10419: All collection APIs should use the new Policy framework for replica placement. (Noble Paul, shalin)+* SOLR-10800: Factor out HttpShardHandler.transformReplicasToShardUrls from HttpShardHandler.prepDistributed.+ (Domenico Fabio Marino, Christine Poerschke)+================== 6.7.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.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.javaindex 2954cff54da..1c98f5814c1 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@@ -379,10 +379,11 @@ public class HttpShardHandler extends ShardHandler {for (int i=0; i<rb.shards.length; i++) {- final List<String> shardUrls;if (rb.shards[i] != null) {- shardUrls = StrUtils.splitSmart(rb.shards[i], "|", true);+ final List<String> shardUrls = StrUtils.splitSmart(rb.shards[i], "|", true);replicaListTransformer.transform(shardUrls);+ // And now recreate the | delimited list of equivalent servers+ rb.shards[i] = createSliceShardsStr(shardUrls);} else {if (clusterState == null) {clusterState = zkController.getClusterState();@@ -424,15 +425,11 @@ public class HttpShardHandler extends ShardHandler {final List<Replica> eligibleSliceReplicas = collectEligibleReplicas(slice, clusterState, onlyNrtReplicas, isShardLeader);- replicaListTransformer.transform(eligibleSliceReplicas);+ final List<String> shardUrls = transformReplicasToShardUrls(replicaListTransformer, eligibleSliceReplicas);- shardUrls = new ArrayList<>(eligibleSliceReplicas.size());- for (Replica replica : eligibleSliceReplicas) {- String url = ZkCoreNodeProps.getCoreUrl(replica);- shardUrls.add(url);- }-- if (shardUrls.isEmpty()) {+ // And now recreate the | delimited list of equivalent servers+ final String sliceShardsStr = createSliceShardsStr(shardUrls);+ if (sliceShardsStr.isEmpty()) {boolean tolerant = rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false);if (!tolerant) {// stop the check when there are no replicas available for a shard@@ -440,9 +437,8 @@ public class HttpShardHandler extends ShardHandler {"no servers hosting shard: " + rb.slices[i]);}}+ rb.shards[i] = sliceShardsStr;}- // And now recreate the | delimited list of equivalent servers- rb.shards[i] = createSliceShardsStr(shardUrls);}}String shards_rows = params.get(ShardParams.SHARDS_ROWS);@@ -475,6 +471,17 @@ public class HttpShardHandler extends ShardHandler {return eligibleSliceReplicas;}+ private static List<String> transformReplicasToShardUrls(final ReplicaListTransformer replicaListTransformer, final List<Replica> eligibleSliceReplicas) {+ replicaListTransformer.transform(eligibleSliceReplicas);++ final List<String> shardUrls = new ArrayList<>(eligibleSliceReplicas.size());+ for (Replica replica : eligibleSliceReplicas) {+ String url = ZkCoreNodeProps.getCoreUrl(replica);+ shardUrls.add(url);+ }+ return shardUrls;+ }+private static String createSliceShardsStr(final List<String> shardUrls) {final StringBuilder sliceShardsStr = new StringBuilder();boolean first = true;