diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java index eca5032d611..2793db92a9f 100644 --- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java +++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java @@ -464,7 +464,7 @@ public class Overseer { //request new shardId if (collectionExists) { // use existing numShards - numShards = state.getCollectionStates().get(collection).getSlices().size(); + numShards = state.getCollection(collection).getSlices().size(); log.info("Collection already exists with " + ZkStateReader.NUM_SHARDS_PROP + "=" + numShards); } sliceName = Assign.assignShard(collection, state, numShards); diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java index 1a74bf4772a..68ed988d119 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java @@ -1106,7 +1106,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread { private void migrateKey(ClusterState clusterState, DocCollection sourceCollection, Slice sourceSlice, DocCollection targetCollection, Slice targetSlice, String splitKey, int timeout, NamedList results) throws KeeperException, InterruptedException { String tempSourceCollectionName = "split_" + sourceSlice.getName() + "_temp_" + targetSlice.getName(); - if (clusterState.getCollectionStates().containsKey(tempSourceCollectionName)) { + if (clusterState.hasCollection(tempSourceCollectionName)) { log.info("Deleting temporary collection: " + tempSourceCollectionName); Map props = ZkNodeProps.makeMap( QUEUE_OPERATION, DELETECOLLECTION, diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java index 5c8c498bc64..d2379fff899 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java @@ -1009,10 +1009,11 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa private void collectStartTimes(String collectionName, Map urlToTime) throws SolrServerException, IOException { - Map collections = getCommonCloudSolrServer().getZkStateReader() - .getClusterState().getCollectionStates(); - if (collections.containsKey(collectionName)) { - Map slices = collections.get(collectionName).getSlicesMap(); + ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader() + .getClusterState(); +// Map collections = clusterState.getCollectionStates(); + if (clusterState.hasCollection(collectionName)) { + Map slices = clusterState.getSlicesMap(collectionName); Iterator> it = slices.entrySet().iterator(); while (it.hasNext()) { @@ -1036,13 +1037,13 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa } } else { throw new IllegalArgumentException("Could not find collection in :" - + collections.keySet()); + + clusterState.getCollections()); } } private String getUrlFromZk(String collection) { ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader().getClusterState(); - Map slices = clusterState.getCollectionStates().get(collection).getSlicesMap(); + Map slices = clusterState.getSlicesMap(collection); if (slices == null) { throw new SolrException(ErrorCode.BAD_REQUEST, "Could not find collection:" + collection); @@ -1097,9 +1098,9 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa while (System.currentTimeMillis() < timeoutAt) { getCommonCloudSolrServer().getZkStateReader().updateClusterState(true); ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader().getClusterState(); - Map collections = clusterState - .getCollectionStates(); - if (!collections.containsKey(collectionName)) { +// Map collections = clusterState +// .getCollectionStates(); + if (! clusterState.hasCollection(collectionName)) { found = false; break; } diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java index 68446b36264..7f3c06e2bae 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java @@ -744,7 +744,8 @@ public class OverseerTest extends SolrTestCaseJ4 { ClusterState state = reader.getClusterState(); int numFound = 0; - for (DocCollection collection : state.getCollectionStates().values()) { + for (String c : state.getCollections()) { + DocCollection collection = state.getCollection(c); for (Slice slice : collection.getSlices()) { if (slice.getReplicasMap().get("core_node1") != null) { numFound++; diff --git a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java index 9cf3d3dc516..dbc69718db1 100644 --- a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java @@ -172,7 +172,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { zkStateReader.updateClusterState(true); - int slices = zkStateReader.getClusterState().getCollectionStates().get("unloadcollection").getSlices().size(); + int slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size(); assertEquals(1, slices); client = clients.get(1); @@ -187,7 +187,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { server.request(createCmd); zkStateReader.updateClusterState(true); - slices = zkStateReader.getClusterState().getCollectionStates().get("unloadcollection").getSlices().size(); + slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size(); assertEquals(1, slices); waitForRecoveriesToFinish("unloadcollection", zkStateReader, false); 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 93fb1264d0c..d4d2ad95aad 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 @@ -136,6 +136,10 @@ public class ClusterState implements JSONWriter.Writable { return coll.getActiveSlices(); } + public DocCollection getCollectionOrNull(String collection) { + return collectionStates.get(collection); + + } /** * Get the named DocCollection object, or throw an exception if it doesn't exist. */ @@ -156,6 +160,7 @@ public class ClusterState implements JSONWriter.Writable { /** * @return Map<collectionName, Map<sliceName,Slice>> + * @deprecated */ public Map getCollectionStates() { return Collections.unmodifiableMap(collectionStates); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index 9fd762a0a79..9b118fbe9a9 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -440,7 +440,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes /* Total number of replicas (number of cores serving an index to the collection) shown by the cluster state */ protected int getTotalReplicas(String collection) { ZkStateReader zkStateReader = cloudClient.getZkStateReader(); - DocCollection coll = zkStateReader.getClusterState().getCollectionStates().get(collection); + DocCollection coll = zkStateReader.getClusterState().getCollectionOrNull(collection); if (coll == null) return 0; // support for when collection hasn't been created yet int cnt = 0; for (Slice slices : coll.getSlices()) { @@ -1690,10 +1690,10 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes int expectedShardsPerSlice = numShardsNumReplicaList.get(1); int expectedTotalShards = expectedSlices * expectedShardsPerSlice; - Map collections = clusterState - .getCollectionStates(); - if (collections.containsKey(collectionName)) { - Map slices = collections.get(collectionName).getSlicesMap(); +// Map collections = clusterState +// .getCollectionStates(); + if (clusterState.hasCollection(collectionName)) { + Map slices = clusterState.getCollection(collectionName).getSlicesMap(); // did we find expectedSlices slices/shards? if (slices.size() != expectedSlices) { return "Found new collection " + collectionName + ", but mismatch on number of slices. Expected: " + expectedSlices + ", actual: " + slices.size(); @@ -1758,7 +1758,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes return commondCloudSolrServer; } public static String getUrlFromZk(ClusterState clusterState, String collection) { - Map slices = clusterState.getCollectionStates().get(collection).getSlicesMap(); + Map slices = clusterState.getCollection(collection).getSlicesMap(); if (slices == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);