Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-13882: Collections API COLSTATUS does not check live_nodes when reporting replica's status.

Andrzej Bialecki720fb94113d0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7606233b608..4cf81bc39e2 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -153,6 +153,9 @@ Bug Fixes
* SOLR-13762: Fix BinaryField support for non-binary wt's (Thomas Woeckinger via Jason Gerlowski)
+* SOLR-13882: Collections API COLSTATUS does not check live_nodes when reporting replica's status.
+ (Erick Erickson, Andrzej Białecki)
+
Other Changes
---------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java b/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java
index df022b9e2eb..1fb25336658 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ColStatus.java
@@ -123,6 +123,11 @@ public class ColStatus {
int recoveringReplicas = 0;
int recoveryFailedReplicas = 0;
for (Replica r : s.getReplicas()) {
+ // replica may still be marked as ACTIVE even though its node is no longer live
+ if (! r.isActive(clusterState.getLiveNodes())) {
+ downReplicas++;
+ continue;
+ }
switch (r.getState()) {
case ACTIVE:
activeReplicas++;
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
index 34d1b8d6c86..4db1152a901 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
@@ -43,6 +43,7 @@ import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
@@ -658,6 +659,19 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
assertNotNull(Utils.toJSONString(rsp), segInfos.get("fieldInfoLegend"));
assertNotNull(Utils.toJSONString(rsp), segInfos.findRecursive("segments", "_0", "fields", "id", "flags"));
assertNotNull(Utils.toJSONString(rsp), segInfos.findRecursive("segments", "_0", "ramBytesUsed"));
+ // test for replicas not active - SOLR-13882
+ DocCollection coll = cluster.getSolrClient().getClusterStateProvider().getClusterState().getCollection(collectionName);
+ Replica firstReplica = coll.getSlice("shard1").getReplicas().iterator().next();
+ String firstNode = firstReplica.getNodeName();
+ for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
+ if (jetty.getNodeName().equals(firstNode)) {
+ cluster.stopJettySolrRunner(jetty);
+ }
+ }
+ rsp = req.process(cluster.getSolrClient());
+ assertEquals(0, rsp.getStatus());
+ Number down = (Number) rsp.getResponse().findRecursive(collectionName, "shards", "shard1", "replicas", "down");
+ assertTrue("should be some down replicas, but there were none in shard1:" + rsp, down.intValue() > 0);
}
private static final int NUM_DOCS = 10;