janhoy commented on code in PR #2391:
URL: https://github.com/apache/solr/pull/2391#discussion_r3217196903
##########
solr/core/src/java/org/apache/solr/core/ZkContainer.java:
##########
@@ -70,42 +80,109 @@ public class ZkContainer {
public ZkContainer() {}
public void initZooKeeper(final CoreContainer cc, CloudConfig config) {
- boolean zkRun =
EnvUtils.getPropertyAsBool("solr.zookeeper.server.enabled", false);
+ // zkServerEnabled is set whenever in solrCloud mode ('-c') but no
explicit zkHost/ZK_HOST is
+ // provided.
+ final boolean zkServerEnabled =
+ EnvUtils.getPropertyAsBool("solr.zookeeper.server.enabled", false);
+ boolean zkQuorumNode = false;
+ if
(NodeRoles.MODE_ON.equals(cc.nodeRoles.getRoleMode(NodeRoles.Role.ZOOKEEPER_QUORUM)))
{
+ zkQuorumNode = true;
+ log.info("Starting node in ZooKeeper Quorum role.");
+ }
- if (zkRun && config == null)
+ if (zkServerEnabled && config == null) {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
"Cannot start Solr in cloud mode - no cloud config provided");
+ }
+
+ if (config == null) {
+ log.info("Solr is running in standalone mode");
+ return;
+ }
- if (config == null) return; // not in zk mode
+ final boolean runAsQuorum = config.getZkHost() != null && zkQuorumNode;
String zookeeperHost = config.getZkHost();
+ final var solrHome = cc.getSolrHome();
+ if (zkServerEnabled) {
+ if (!runAsQuorum) {
+ // Old school ZooKeeperServerMain being used under the covers.
+ zkServer =
+ SolrZkServer.createAndStart(config.getZkHost(), solrHome,
config.getSolrHostPort());
+
+ // set client from server config if not already set
+ if (zookeeperHost == null) {
+ zookeeperHost = zkServer.getClientString();
+ }
+ } else {
+ // ZooKeeperServerEmbedded being used under the covers.
+ // Figure out where to put zoo-data
+ final var zkHomeDir = solrHome.resolve("zoo_home");
+ final var zkDataDir = zkHomeDir.resolve("data");
+
+ // Populate a zoo.cfg
+ final String zooCfgTemplate =
+ ""
+ + "tickTime=2000\n"
+ + "initLimit=10\n"
+ + "syncLimit=5\n"
+ + "dataDir=@@DATA_DIR@@\n"
+ + "4lw.commands.whitelist=mntr,conf,ruok\n"
+ + "admin.enableServer=false\n"
+ + "clientPort=@@ZK_CLIENT_PORT@@\n";
+
+ final int zkPort = config.getSolrHostPort() + 1000;
+ String zooCfgContents =
+ zooCfgTemplate
+ .replace("@@DATA_DIR@@", zkDataDir.toString())
+ .replace("@@ZK_CLIENT_PORT@@", String.valueOf(zkPort));
+ final String[] zkHosts = config.getZkHost().split(",");
+ int myId = -1;
+ // TODO: myId detection uses exact string matching between
config.getHost() and the host
+ // portion of zkHost entries. This fails when zkHost uses "localhost"
but Solr is
+ // configured with "127.0.0.1" (or vice versa). Consider resolving
hostnames/IPs before
+ // matching, or matching by port alone (which is unique per node in a
single-machine setup).
+ final String targetConnStringSection = config.getHost() + ":" + zkPort;
+ if (log.isInfoEnabled()) {
+ log.info(
+ "Trying to match {} against zkHostString {} to determine myid",
+ targetConnStringSection,
+ config.getZkHost());
+ }
+ for (int i = 0; i < zkHosts.length; i++) {
+ final String host = zkHosts[i];
Review Comment:
Risk of ArrayIndexOutOfBounds
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]