diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b94e6a98e63..8d3aef71cd9 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -81,6 +81,8 @@ Bug Fixes * SOLR-4567: copyField source glob matching explicit field(s) stopped working in Solr 4.2. (Alexandre Rafalovitch, Steve Rowe) +* SOLR-4566: Fix DocCollection to return all shards not just active shards. + (Mark Miller) Other Changes ---------------------- diff --git a/solr/core/src/test/org/apache/solr/cloud/SliceStateUpdateTest.java b/solr/core/src/test/org/apache/solr/cloud/SliceStateUpdateTest.java index 52fdf7b6825..1dfb4229620 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SliceStateUpdateTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SliceStateUpdateTest.java @@ -171,7 +171,7 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 { Map slices = null; for (int i = 75; i > 0; i--) { clusterState2 = zkController2.getClusterState(); - slices = clusterState2.getAllSlicesMap("collection1"); + slices = clusterState2.getSlicesMap("collection1"); if (slices != null && slices.containsKey("shard1") && slices.get("shard1").getState().equals("inactive")) { break; diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index 867bab55868..d33d62ed6e7 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -114,17 +114,11 @@ public class ClusterState implements JSONWriter.Writable { if (coll == null) return null; return coll.getSlicesMap(); } - - public Map getAllSlicesMap(String collection) { - DocCollection coll = collectionStates.get(collection); - if (coll == null) return null; - return coll.getAllSlicesMap(); - } public Collection getSlices(String collection) { DocCollection coll = collectionStates.get(collection); if (coll == null) return null; - return coll.getSlices(); + return coll.getSlicesMap().values(); } /** diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java index b07b56e2370..3d935b12407 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java @@ -17,16 +17,14 @@ package org.apache.solr.common.cloud; * limitations under the License. */ -import org.apache.noggit.JSONUtil; -import org.apache.noggit.JSONWriter; - import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import org.apache.noggit.JSONUtil; +import org.apache.noggit.JSONWriter; + /** * Models a Collection in zookeeper (but that Java name is obviously taken, hence "DocCollection") */ @@ -36,7 +34,6 @@ public class DocCollection extends ZkNodeProps { private final String name; private final Map slices; - private final Map allSlices; private final DocRouter router; /** @@ -48,16 +45,7 @@ public class DocCollection extends ZkNodeProps { super( props==null ? Collections.emptyMap() : props); this.name = name; - this.allSlices = slices; - this.slices = new HashMap(); - - Iterator> iter = slices.entrySet().iterator(); - - while (iter.hasNext()) { - Map.Entry slice = iter.next(); - if (slice.getValue().getState().equals(Slice.ACTIVE)) - this.slices.put(slice.getKey(), slice.getValue()); - } + this.slices = slices; this.router = router; assert name != null && slices != null; @@ -72,22 +60,14 @@ public class DocCollection extends ZkNodeProps { } public Slice getSlice(String sliceName) { - return allSlices.get(sliceName); + return slices.get(sliceName); } - /** - * Gets the list of active slices for this collection. - */ - public Collection getSlices() { - return slices.values(); - } - - /** * Return the list of all slices for this collection. */ - public Collection getAllSlices() { - return allSlices.values(); + public Collection getSlices() { + return slices.values(); } /** @@ -97,13 +77,6 @@ public class DocCollection extends ZkNodeProps { return slices; } - /** - * Get the map of all slices (sliceName->Slice) for this collection. - */ - public Map getAllSlicesMap() { - return allSlices; - } - public DocRouter getRouter() { return router; } @@ -115,9 +88,9 @@ public class DocCollection extends ZkNodeProps { @Override public void write(JSONWriter jsonWriter) { - LinkedHashMap all = new LinkedHashMap(allSlices.size() + 1); + LinkedHashMap all = new LinkedHashMap(slices.size() + 1); all.putAll(propMap); - all.put(SHARDS, allSlices); + all.put(SHARDS, slices); jsonWriter.write(all); } }