Apache Solr open-source search software
SOLR-6390: CloudSolrServer constructor improvements
Shawn Heiseyf695231df7e4
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b643d339d84..64ae7ebb353 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -129,6 +129,10 @@ Other Changes* LUCENE-5650: Tests can no longer write to CWD. Update log dir is now made relativeto the instance dir if it is not an absolute path. (Ryan Ernst, Dawid Weiss)+* SOLR-6390: Remove unnecessary checked exception for CloudSolrServer+ constructors, improve javadocs for CloudSolrServer constructors.+ (Steve Davids via Shawn Heisey)+================== 4.10.0 =================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.javaindex d9e65cd031e..ca0bea6de11 100644--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java@@ -18,7 +18,6 @@ package org.apache.solr.cloud;*/import java.io.IOException;-import java.net.MalformedURLException;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;@@ -1138,16 +1137,12 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {protected CloudSolrServer getCommonCloudSolrServer() {if (commondCloudSolrServer == null) {synchronized(this) {- try {- commondCloudSolrServer = new CloudSolrServer(zkServer.getZkAddress(), random().nextBoolean());- commondCloudSolrServer.setParallelUpdates(random().nextBoolean());- commondCloudSolrServer.setDefaultCollection(DEFAULT_COLLECTION);- commondCloudSolrServer.getLbServer().setConnectionTimeout(15000);- commondCloudSolrServer.getLbServer().setSoTimeout(30000);- commondCloudSolrServer.connect();- } catch (MalformedURLException e) {- throw new RuntimeException(e);- }+ commondCloudSolrServer = new CloudSolrServer(zkServer.getZkAddress(), random().nextBoolean());+ commondCloudSolrServer.setParallelUpdates(random().nextBoolean());+ commondCloudSolrServer.setDefaultCollection(DEFAULT_COLLECTION);+ commondCloudSolrServer.getLbServer().setConnectionTimeout(15000);+ commondCloudSolrServer.getLbServer().setSoTimeout(30000);+ commondCloudSolrServer.connect();}}return commondCloudSolrServer;diff --git a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.javaindex cc064423a6f..f35027e9359 100644--- a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java@@ -614,7 +614,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {}@Override- protected CloudSolrServer createCloudClient(String defaultCollection) throws MalformedURLException {+ protected CloudSolrServer createCloudClient(String defaultCollection) {CloudSolrServer client = super.createCloudClient(defaultCollection);client.getLbServer().getHttpClient().getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5 * 60 * 1000);return client;diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.javaindex 019bee063ea..91d40760567 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java@@ -18,7 +18,6 @@ package org.apache.solr.client.solrj.impl;*/import java.io.IOException;-import java.net.MalformedURLException;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -113,24 +112,38 @@ public class CloudSolrServer extends SolrServer {}--/**- * @param zkHost The client endpoint of the zookeeper quorum containing the cloud state,- * in the form HOST:PORT.+ * Create a new client object that connects to Zookeeper and is always aware+ * of the SolrCloud state. If there is a fully redundant Zookeeper quorum and+ * SolrCloud has enough replicas for every shard in a collection, there is no+ * single point of failure. Updates will be sent to shard leaders by default.+ *+ * @param zkHost+ * The client endpoint of the zookeeper quorum containing the cloud+ * state. The full specification for this string is one or more comma+ * separated HOST:PORT values, followed by an optional chroot value+ * that starts with a forward slash. Using a chroot allows multiple+ * applications to coexist in one ensemble. For full details, see the+ * Zookeeper documentation. Some examples:+ * <p/>+ * "host1:2181"+ * <p/>+ * "host1:2181,host2:2181,host3:2181/mysolrchroot"+ * <p/>+ * "zoo1.example.com:2181,zoo2.example.com:2181,zoo3.example.com:2181"*/public CloudSolrServer(String zkHost) {- this.zkHost = zkHost;- this.myClient = HttpClientUtil.createClient(null);- this.lbServer = new LBHttpSolrServer(myClient);- this.lbServer.setRequestWriter(new BinaryRequestWriter());- this.lbServer.setParser(new BinaryResponseParser());- this.updatesToLeaders = true;- shutdownLBHttpSolrServer = true;+ this(zkHost, true);}- public CloudSolrServer(String zkHost, boolean updatesToLeaders)- throws MalformedURLException {+ /**+ * @param zkHost+ * A zookeeper client endpoint.+ * @param updatesToLeaders+ * If true, sends updates only to shard leaders.+ * @see #CloudSolrServer(String) for full description and details on zkHost+ */+ public CloudSolrServer(String zkHost, boolean updatesToLeaders) {this.zkHost = zkHost;this.myClient = HttpClientUtil.createClient(null);this.lbServer = new LBHttpSolrServer(myClient);@@ -141,22 +154,24 @@ public class CloudSolrServer extends SolrServer {}/**- * @param zkHost The client endpoint of the zookeeper quorum containing the cloud state,- * in the form HOST:PORT.- * @param lbServer LBHttpSolrServer instance for requests.+ * @param zkHost+ * A zookeeper client endpoint.+ * @param lbServer+ * LBHttpSolrServer instance for requests.+ * @see #CloudSolrServer(String) for full description and details on zkHost*/public CloudSolrServer(String zkHost, LBHttpSolrServer lbServer) {- this.zkHost = zkHost;- this.lbServer = lbServer;- this.updatesToLeaders = true;- shutdownLBHttpSolrServer = false;+ this(zkHost, lbServer, true);}/**- * @param zkHost The client endpoint of the zookeeper quorum containing the cloud state,- * in the form HOST:PORT.- * @param lbServer LBHttpSolrServer instance for requests.- * @param updatesToLeaders sends updates only to leaders - defaults to true+ * @param zkHost+ * A zookeeper client endpoint.+ * @param lbServer+ * LBHttpSolrServer instance for requests.+ * @param updatesToLeaders+ * If true, sends updates only to shard leaders.+ * @see #CloudSolrServer(String) for full description and details on zkHost*/public CloudSolrServer(String zkHost, LBHttpSolrServer lbServer, boolean updatesToLeaders) {this.zkHost = zkHost;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 5c2cc26390f..270d07338c6 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@@ -26,7 +26,6 @@ import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;import java.io.File;import java.io.IOException;-import java.net.MalformedURLException;import java.net.URI;import java.util.ArrayList;import java.util.Collection;@@ -243,13 +242,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesprotected void initCloud() throws Exception {assert(cloudInit == false);cloudInit = true;- try {- cloudClient = createCloudClient(DEFAULT_COLLECTION);-- cloudClient.connect();- } catch (MalformedURLException e) {- throw new RuntimeException(e);- }+ cloudClient = createCloudClient(DEFAULT_COLLECTION);+ cloudClient.connect();ZkStateReader zkStateReader = cloudClient.getZkStateReader();@@ -257,8 +251,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesshardToJetty, shardToLeaderJetty);}- protected CloudSolrServer createCloudClient(String defaultCollection)- throws MalformedURLException {+ protected CloudSolrServer createCloudClient(String defaultCollection) {CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress(), random().nextBoolean());server.setParallelUpdates(random().nextBoolean());if (defaultCollection != null) server.setDefaultCollection(defaultCollection);@@ -1655,16 +1648,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesprotected CloudSolrServer getCommonCloudSolrServer() {synchronized (this) {if (commondCloudSolrServer == null) {- try {- commondCloudSolrServer = new CloudSolrServer(zkServer.getZkAddress(),- random().nextBoolean());- commondCloudSolrServer.getLbServer().setConnectionTimeout(30000);- commondCloudSolrServer.setParallelUpdates(random().nextBoolean());- commondCloudSolrServer.setDefaultCollection(DEFAULT_COLLECTION);- commondCloudSolrServer.connect();- } catch (MalformedURLException e) {- throw new RuntimeException(e);- }+ commondCloudSolrServer = new CloudSolrServer(zkServer.getZkAddress(),+ random().nextBoolean());+ commondCloudSolrServer.getLbServer().setConnectionTimeout(30000);+ commondCloudSolrServer.setParallelUpdates(random().nextBoolean());+ commondCloudSolrServer.setDefaultCollection(DEFAULT_COLLECTION);+ commondCloudSolrServer.connect();}}return commondCloudSolrServer;