Apache Lucene open-source search software
SOLR-4075: A logical shard that has had all of it's SolrCores unloaded should be removed from the cluster state.
Mark Robert Miller146404526867
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 2da511558f8..7795b4b41b8 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -209,6 +209,9 @@ Bug Fixes* SOLR-3959: Ensure the internal comma separator of poly fields is escapedfor CSVResponseWriter. (Areek Zillur via Robert Muir)++* SOLR-4075: A logical shard that has had all of it's SolrCores unloaded should+ be removed from the cluster state. (Mark Miller, Gilles Comeau)Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.javaindex 8ef14b1a0ac..d4a3a48edaf 100644--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java@@ -398,8 +398,11 @@ public class Overseer {if(slice.getReplicasMap().containsKey(coreNodeName)) {Map<String, Replica> newReplicas = slice.getReplicasCopy();newReplicas.remove(coreNodeName);- Slice newSlice = new Slice(slice.getName(), newReplicas, slice.getProperties());- newSlices.put(slice.getName(), newSlice);+ if (newReplicas.size() != 0) {+ Slice newSlice = new Slice(slice.getName(), newReplicas,+ slice.getProperties());+ newSlices.put(slice.getName(), newSlice);+ }} else {newSlices.put(slice.getName(), slice);}diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.javaindex a15b42870a4..31a4bf8e2f1 100644--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java@@ -343,12 +343,82 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {testCoreUnloadAndLeaders();testUnloadLotsOfCores();testStopAndStartCoresInOneInstance();+ testUnloadShardAndCollection();// Thread.sleep(10000000000L);if (DEBUG) {super.printLayout();}}+ private void testUnloadShardAndCollection() throws Exception{+ // create one leader and one replica++ Create createCmd = new Create();+ createCmd.setCoreName("test_unload_shard_and_collection_1");+ String collection = "test_unload_shard_and_collection";+ createCmd.setCollection(collection);+ String coreDataDir = dataDir.getAbsolutePath() + File.separator+ + System.currentTimeMillis() + collection + "1";+ createCmd.setDataDir(coreDataDir);+ createCmd.setNumShards(2);++ SolrServer client = clients.get(0);+ String url1 = getBaseUrl(client);+ HttpSolrServer server = new HttpSolrServer(url1);++ server.request(createCmd);++ createCmd = new Create();+ createCmd.setCoreName("test_unload_shard_and_collection_2");+ collection = "test_unload_shard_and_collection";+ createCmd.setCollection(collection);+ coreDataDir = dataDir.getAbsolutePath() + File.separator+ + System.currentTimeMillis() + collection + "2";+ createCmd.setDataDir(coreDataDir);++ server.request(createCmd);++ // now unload one of the two+ Unload unloadCmd = new Unload(false);+ unloadCmd.setCoreName("test_unload_shard_and_collection_2");+ server.request(unloadCmd);++ // there should be only one shard+ Slice shard2 = solrj.getZkStateReader().getClusterState().getSlice(collection, "shard2");+ long timeoutAt = System.currentTimeMillis() + 30000;+ while (shard2 != null) {+ if (System.currentTimeMillis() > timeoutAt) {+ printLayout();+ fail("Still found shard");+ }++ Thread.sleep(50);+ shard2 = solrj.getZkStateReader().getClusterState().getSlice(collection, "shard2");+ }++ Slice shard1 = solrj.getZkStateReader().getClusterState().getSlice(collection, "shard1");+ assertNotNull(shard1);+ assertTrue(solrj.getZkStateReader().getClusterState().getCollections().contains(collection));++ // now unload one of the other+ unloadCmd = new Unload(false);+ unloadCmd.setCoreName("test_unload_shard_and_collection_1");+ server.request(unloadCmd);++ //printLayout();+ // the collection should be gone+ timeoutAt = System.currentTimeMillis() + 30000;+ while (solrj.getZkStateReader().getClusterState().getCollections().contains(collection)) {+ if (System.currentTimeMillis() > timeoutAt) {+ printLayout();+ fail("Still found collection");+ }++ Thread.sleep(50);+ }++ }+/*** @throws Exception on any problem*/