SOLR-15113 Do not attempt to start Solr server when embedded ZK fails (#2255)

This commit is contained in:
Mike Drob 2021-01-28 11:37:51 -06:00 committed by GitHub
parent acb98e549d
commit 9be71b3939
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 21 deletions

View File

@ -191,6 +191,8 @@ Other Changes
* SOLR-14297: Replace commons-codec Base64 with JDK8 Base64 (Andras Salamon via Houston Putman)
* SOLR-15113: Do not attempt to start Solr server when embedded ZK fails (Mike Drob)
Bug Fixes
---------------------
* SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order execution

View File

@ -36,6 +36,7 @@ import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
@ -107,26 +108,24 @@ public class SolrZkServer {
if (System.getProperty(ZK_WHITELIST_PROPERTY) == null) {
System.setProperty(ZK_WHITELIST_PROPERTY, "ruok, mntr, conf");
}
zkThread = new Thread() {
@Override
public void run() {
try {
if (zkProps.getServers().size() > 1) {
QuorumPeerMain zkServer = new QuorumPeerMain();
zkServer.runFromConfig(zkProps);
} else {
ServerConfig sc = new ServerConfig();
sc.readFrom(zkProps);
ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
zkServer.runFromConfig(sc);
}
log.info("ZooKeeper Server exited.");
} catch (Exception e) {
log.error("ZooKeeper Server ERROR", e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
AtomicReference<Exception> zkException = new AtomicReference<>();
zkThread = new Thread(() -> {
try {
if (zkProps.getServers().size() > 1) {
QuorumPeerMain zkServer = new QuorumPeerMain();
zkServer.runFromConfig(zkProps);
} else {
ServerConfig sc = new ServerConfig();
sc.readFrom(zkProps);
ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
zkServer.runFromConfig(sc);
}
log.info("ZooKeeper Server exited.");
} catch (Exception e) {
log.error("ZooKeeper Server ERROR", e);
zkException.set(e);
}
};
}, "embeddedZkServer");
if (zkProps.getServers().size() > 1) {
if (log.isInfoEnabled()) {
@ -143,9 +142,16 @@ public class SolrZkServer {
zkThread.setDaemon(true);
zkThread.start();
try {
// We don't have any way to hook into the ZK server object to check that it is running, so we just wait and hope
Thread.sleep(500); // pause for ZooKeeper to start
} catch (Exception e) {
log.error("STARTING ZOOKEEPER", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Interrupted while starting embedded zookeeper server", e);
}
if (zkException.get() != null) {
log.info("Embedded ZK dataHome={}", dataHome);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not start embedded zookeeper server", zkException.get());
}
}

View File

@ -230,9 +230,13 @@ public class ConnectionManager implements Watcher {
}
}
/**
* Wait for an established zookeeper connection
* @param waitForConnection time to wait, in ms
*/
public synchronized void waitForConnected(long waitForConnection)
throws TimeoutException {
log.info("Waiting for client to connect to ZooKeeper");
log.info("Waiting up to {}ms for client to connect to ZooKeeper", waitForConnection);
long expire = System.nanoTime() + TimeUnit.NANOSECONDS.convert(waitForConnection, TimeUnit.MILLISECONDS);
long left = 1;
while (!connected && left > 0) {