Skip to content

Commit

Permalink
SOLR-16339: refine "no servers hosting shard" wording (apache#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoerschke authored Aug 24, 2022
1 parent c0393d6 commit 2e58336
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Other Changes

* SOLR-16332: Upgrade Jetty to 9.4.48.v20220622 (Chris Sabelstrom, janhoy)

* SOLR-16339: Refined "no servers hosting shard" SolrException wording. (Christine Poerschke)

Build
---------------------
* SOLR-16204: Change Lucene dependency to Lucene 9.1.0 (Elia Porciani via Alessandro Benedetti)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.solr.client.solrj.impl.LBHttp2SolrClient;
import org.apache.solr.client.solrj.impl.LBSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.routing.NoOpReplicaListTransformer;
import org.apache.solr.client.solrj.routing.ReplicaListTransformer;
import org.apache.solr.client.solrj.util.AsyncListener;
import org.apache.solr.client.solrj.util.Cancellable;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void submit(

pending.incrementAndGet();
// if there are no shards available for a slice, urls.size()==0
if (urls.size() == 0) {
if (urls.isEmpty()) {
// TODO: what's the right error code here? We should use the same thing when
// all of the servers for a shard are down.
SolrException exception =
Expand Down Expand Up @@ -318,14 +319,26 @@ public void prepDistributed(ResponseBuilder rb) {
// be an optimization?
}

for (int i = 0; i < rb.slices.length; i++) {
if (!ShardParams.getShardsTolerantAsBool(params)
&& replicaSource.getReplicasBySlice(i).isEmpty()) {
// stop the check when there are no replicas available for a shard
// todo fix use of slices[i] which can be null if user specified urls in shards param
throw new SolrException(
SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"no servers hosting shard: " + rb.slices[i]);
if (!ShardParams.getShardsTolerantAsBool(params)) {
for (int i = 0; i < rb.slices.length; i++) {
if (replicaSource.getReplicasBySlice(i).isEmpty()) {
final ReplicaSource allActiveReplicaSource =
new CloudReplicaSource.Builder()
.params(params)
.zkStateReader(zkController.getZkStateReader())
.allowListUrlChecker(AllowListUrlChecker.ALLOW_ALL)
.replicaListTransformer(NoOpReplicaListTransformer.INSTANCE)
.collection(cloudDescriptor.getCollectionName())
.onlyNrt(false)
.build();
final String adjective =
(allActiveReplicaSource.getReplicasBySlice(i).isEmpty() ? "active" : "eligible");
// stop the check when there are no replicas available for a shard
// todo fix use of slices[i] which can be null if user specified urls in shards param
throw new SolrException(
SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"no " + adjective + " servers hosting shard: " + rb.slices[i]);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void testRequireZkConnectedDistrib() throws Exception {
try (HttpSolrClient httpSolrClient =
new HttpSolrClient.Builder(connectedReplica.getCoreUrl()).build()) {
ignoreException("ZooKeeper is not connected");
ignoreException("no servers hosting shard:");
ignoreException("no active servers hosting shard:");
JettySolrRunner disconnectedJetty = miniCluster.getReplicaJetty(disconnectedReplica);
disconnectedJetty.getCoreContainer().getZkController().getZkClient().close();
req.process(httpSolrClient);
Expand All @@ -272,12 +272,12 @@ public void testRequireZkConnectedDistrib() throws Exception {
} catch (Exception e) {
assertTrue(
"Unrecognized exception message: " + e,
e.getMessage().contains("no servers hosting shard:")
e.getMessage().contains("no active servers hosting shard:")
|| e.getMessage().contains("ZooKeeper is not connected"));
}
} finally {
miniCluster.shutdown();
unIgnoreException("no servers hosting shard:");
unIgnoreException("no active servers hosting shard:");
unIgnoreException("ZooKeeper is not connected");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.solrj.routing;

import java.util.List;

public final class NoOpReplicaListTransformer implements ReplicaListTransformer {

public static final ReplicaListTransformer INSTANCE = new NoOpReplicaListTransformer();

private NoOpReplicaListTransformer() {}

public <T> void transform(List<T> choices) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ public NodePreferenceRulesComparator(
}
}

private static final ReplicaListTransformer NOOP_RLT =
new ReplicaListTransformer() {
@Override
public <T> void transform(List<T> choices) {
// Cannot use a method reference because of generic types!
}
};
private static final ReplicaListTransformer NOOP_RLT = NoOpReplicaListTransformer.INSTANCE;
private static final ReplicaListTransformerFactory NOOP_RLTF =
(String configSpec, SolrParams requestParams, ReplicaListTransformerFactory fallback) ->
NOOP_RLT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ public <T> void transform(List<T> choices) {
}
}

// A transformer that makes no transformation
private static class ToyNoOpReplicaListTransformer implements ReplicaListTransformer {

public ToyNoOpReplicaListTransformer() {}

public <T> void transform(List<T> choices) {
// no-op
log.info("No-Op transform ignoring input: {}", choices);
}
}

@Test
public void testTransform() throws Exception {

Expand All @@ -99,7 +88,7 @@ protected ReplicaListTransformer getReplicaListTransformer(final SolrQueryReques
final SolrParams params = req.getParams();

if (params.getBool("toyNoTransform", false)) {
return new ToyNoOpReplicaListTransformer();
return NoOpReplicaListTransformer.INSTANCE;
}

final String regex = params.get("toyRegEx");
Expand Down

0 comments on commit 2e58336

Please sign in to comment.