Apache Lucene open-source search software
SOLR-3993: If multiple SolrCore's for a shard coexist on a node, on cluster restart, leader election would stall until timeout, waiting to see all of the replicas come up.
Mark Robert Millerf902314d7412
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 15a8b8b3646..2f07f30a70c 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -163,6 +163,10 @@ Bug Fixescause actions to be targeted at the wrong SolrCores.(Raintung Li via Mark Miller)+* SOLR-3993: If multiple SolrCore's for a shard coexist on a node, on cluster+ restart, leader election would stall until timeout, waiting to see all of+ the replicas come up. (Mark Miller, Alexey Kudinov)+Other Changes----------------------diff --git a/solr/core/src/test-files/solr/solr.xml b/solr/core/src/test-files/solr/solr.xmlindex 45acb6aaa3d..77064a934a5 100644--- a/solr/core/src/test-files/solr/solr.xml+++ b/solr/core/src/test-files/solr/solr.xml@@ -22,7 +22,7 @@persistent: Save changes made via the API to this filesharedLib: path to a lib directory that will be shared across all cores-->-<solr persistent="false">+<solr persistent="${solr.xml.persist:false}"><!--adminPath: RequestHandler path to manage cores.diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.javaindex bd1af85ba9e..4dbe95baae8 100644--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java@@ -126,6 +126,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {public void setUp() throws Exception {super.setUp();System.setProperty("numShards", Integer.toString(sliceCount));+ System.setProperty("solr.xml.persist", "true");}@@ -341,6 +342,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {testCollectionsAPI();testCoreUnloadAndLeaders();testUnloadLotsOfCores();+ testStopAndStartCoresInOneInstance();// Thread.sleep(10000000000L);if (DEBUG) {super.printLayout();@@ -550,54 +552,97 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),new DefaultSolrThreadFactory("testExecutor"));int cnt = atLeast(6);- for (int i = 0; i < cnt; i++) {- final int freezeI = i;++ // create the 6 cores+ createCores(server, executor, "multiunload", 2, cnt);++ executor.shutdown();+ executor.awaitTermination(120, TimeUnit.SECONDS);+ executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,+ TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),+ new DefaultSolrThreadFactory("testExecutor"));+ for (int j = 0; j < cnt; j++) {+ final int freezeJ = j;executor.execute(new Runnable() {-@Overridepublic void run() {- Create createCmd = new Create();- createCmd.setCoreName("multiunload" + freezeI);- createCmd.setCollection("multiunload");- String core3dataDir = dataDir.getAbsolutePath() + File.separator- + System.currentTimeMillis() + "unloadcollection" + "_3n" + freezeI;- createCmd.setDataDir(core3dataDir);+ Unload unloadCmd = new Unload(true);+ unloadCmd.setCoreName("multiunload" + freezeJ);try {- server.request(createCmd);+ server.request(unloadCmd);} catch (SolrServerException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}-});+ Thread.sleep(random().nextInt(50));}executor.shutdown();executor.awaitTermination(120, TimeUnit.SECONDS);- executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,- TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),+ }++ private void testStopAndStartCoresInOneInstance() throws Exception {+ SolrServer client = clients.get(0);+ String url3 = getBaseUrl(client);+ final HttpSolrServer server = new HttpSolrServer(url3);++ ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,+ 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),new DefaultSolrThreadFactory("testExecutor"));- for (int j = 0; j < cnt; j++) {- final int freezeJ = j;+ int cnt = 3;++ // create the cores+ createCores(server, executor, "multiunload2", 1, cnt);++ executor.shutdown();+ executor.awaitTermination(120, TimeUnit.SECONDS);++ ChaosMonkey.stop(cloudJettys.get(0).jetty);+ printLayout();+ // nocommit+ System.out.println("start again");+ Thread.sleep(5000);+ ChaosMonkey.start(cloudJettys.get(0).jetty);+ cloudClient.getZkStateReader().updateClusterState(true);+ try {+ cloudClient.getZkStateReader().getLeaderProps("multiunload2", "shard1", 30000);+ } catch (SolrException e) {+ printLayout();+ throw e;+ }++ printLayout();++ }++ private void createCores(final HttpSolrServer server,+ ThreadPoolExecutor executor, final String collection, final int numShards, int cnt) {+ for (int i = 0; i < cnt; i++) {+ final int freezeI = i;executor.execute(new Runnable() {+@Overridepublic void run() {- Unload unloadCmd = new Unload(true);- unloadCmd.setCoreName("multiunload" + freezeJ);+ Create createCmd = new Create();+ createCmd.setCoreName(collection + freezeI);+ createCmd.setCollection(collection);+ String core3dataDir = dataDir.getAbsolutePath() + File.separator+ + System.currentTimeMillis() + collection + "_3n" + freezeI;+ createCmd.setDataDir(core3dataDir);+ createCmd.setNumShards(numShards);try {- server.request(unloadCmd);+ server.request(createCmd);} catch (SolrServerException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}+});- Thread.sleep(random().nextInt(50));}- executor.shutdown();- executor.awaitTermination(120, TimeUnit.SECONDS);}@@ -1439,6 +1484,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {}System.clearProperty("numShards");System.clearProperty("zkHost");+ System.clearProperty("solr.xml.persist");// insuranceDirectUpdateHandler2.commitOnClose = true;diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.javaindex 02c8b4f325c..aa2b729931a 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java@@ -407,7 +407,7 @@ public class ZkStateReader {long timeoutAt = System.currentTimeMillis() + timeout;while (System.currentTimeMillis() < timeoutAt) {if (clusterState != null) {- final ZkNodeProps nodeProps = clusterState.getLeader(collection, shard);+ final ZkNodeProps nodeProps = clusterState.getLeader(collection, shard);if (nodeProps != null && getClusterState().liveNodesContain((String) nodeProps.get(ZkStateReader.NODE_NAME_PROP))) {return nodeProps;}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.javaindex cdb2c3bb6ff..c7d5ca7ff8e 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@@ -337,9 +337,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesreturn jettys;}- protected int getNumShards(String defaultCollection) {+ protected int getNumShards(String collection) {ZkStateReader zkStateReader = cloudClient.getZkStateReader();- Map<String,Slice> slices = zkStateReader.getClusterState().getSlices(defaultCollection);+ Map<String,Slice> slices = zkStateReader.getClusterState().getSlices(collection);+ if (slices == null) {+ throw new IllegalArgumentException("Could not find collection:" + collection);+ }int cnt = 0;for (Map.Entry<String,Slice> entry : slices.entrySet()) {cnt += entry.getValue().getReplicasMap().size();