SOLR-14412 zkRun+https (#1437)

SOLR-14412

Check for results after retries failed in SolrClientNodeStateProvider
Set urlScheme=https with zkRun
This commit is contained in:
Mike Drob 2020-04-20 12:55:43 -05:00 committed by GitHub
parent f914e08b36
commit 58f9c79c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 70 deletions

View File

@ -30,12 +30,15 @@ import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.apache.commons.lang3.StringUtils;
import org.apache.solr.cloud.SolrZkServer;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.AlreadyClosedException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ClusterProperties;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkConfigManager;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.cloud.ZooKeeperException;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.logging.MDCLoggingContext;
@ -124,12 +127,18 @@ public class ZkContainer {
ZkController zkController = new ZkController(cc, zookeeperHost, zkClientConnectTimeout, config, descriptorsSupplier);
if (zkRun != null && zkServer.getServers().size() > 1 && confDir == null && boostrapConf == false) {
// we are part of an ensemble and we are not uploading the config - pause to give the config time
// to get up
Thread.sleep(10000);
if (zkRun != null) {
if (StringUtils.isNotEmpty(System.getProperty("solr.jetty.https.port"))) {
// Embedded ZK and probably running with SSL
new ClusterProperties(zkController.getZkClient()).setClusterProperty(ZkStateReader.URL_SCHEME, "https");
}
if (zkServer.getServers().size() > 1 && confDir == null && boostrapConf == false) {
// we are part of an ensemble and we are not uploading the config - pause to give the config time
// to get up
Thread.sleep(10000);
}
}
if(confDir != null) {
Path configPath = Paths.get(confDir);
if (!Files.isDirectory(configPath))

View File

@ -193,37 +193,9 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("key", metricsKeyVsTag.keySet().toArray(new String[0]));
try {
SimpleSolrResponse rsp = null;
int cnt = 0;
while (cnt++ < 3) {
try {
rsp = ctx.invoke(solrNode, CommonParams.METRICS_PATH, params);
break;
} catch (SolrException | SolrServerException | IOException e) {
boolean hasCauseIOException = false;
Throwable cause = e;
while (cause != null) {
if (cause instanceof IOException) {
hasCauseIOException = true;
break;
}
cause = cause.getCause();
}
if (hasCauseIOException || e instanceof IOException) {
log.info("Error on getting remote info, trying again: " + e.getMessage());
Thread.sleep(500);
continue;
} else {
throw e;
}
}
}
SimpleSolrResponse frsp = rsp;
SimpleSolrResponse rsp = ctx.invokeWithRetry(solrNode, CommonParams.METRICS_PATH, params);
metricsKeyVsTag.forEach((key, tag) -> {
Object v = Utils.getObjectByPath(frsp.nl, true, Arrays.asList("metrics", key));
Object v = Utils.getObjectByPath(rsp.nl, true, Arrays.asList("metrics", key));
if (tag instanceof Function) {
Pair<String, Object> p = (Pair<String, Object>) ((Function) tag).apply(v);
ctx.getTags().put(p.first(), p.second());
@ -300,41 +272,8 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter
params.add("prefix", StrUtils.join(prefixes, ','));
try {
SimpleSolrResponse rsp = null;
int retries = 5;
int cnt = 0;
while (cnt++ < retries) {
try {
rsp = snitchContext.invoke(solrNode, CommonParams.METRICS_PATH, params);
break;
} catch (SolrException | SolrServerException | IOException e) {
if (e instanceof SolrServerException) {
}
boolean hasCauseIOException = false;
Throwable cause = e;
while (cause != null) {
if (cause instanceof IOException) {
hasCauseIOException = true;
break;
}
cause = cause.getCause();
}
if (hasCauseIOException || e instanceof IOException) {
log.info("Error on getting remote info, trying again: " + e.getMessage());
Thread.sleep(500);
continue;
} else {
throw e;
}
}
}
if (cnt == retries || rsp == null) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not get remote info after many retries on NoHttpResponseException");
}
SimpleSolrResponse rsp = snitchContext.invokeWithRetry(solrNode, CommonParams.METRICS_PATH, params);
Map m = rsp.nl.asMap(4);
if (requestedTags.contains(FREEDISK.tagName)) {
Object n = Utils.getObjectByPath(m, true, "metrics/solr.node/CONTAINER.fs.usableSpace");
@ -398,6 +337,39 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter
return Utils.getJson(zkClientClusterStateProvider.getZkStateReader().getZkClient(), path, true);
}
/**
* Will attempt to call {@link #invoke(String, String, SolrParams)} up to five times, retrying on any IO Exceptions
*/
public SimpleSolrResponse invokeWithRetry(String solrNode, String path, SolrParams params) throws InterruptedException, IOException, SolrServerException {
int retries = 5;
int cnt = 0;
while (cnt++ < retries) {
try {
return invoke(solrNode, path, params);
} catch (SolrException | SolrServerException | IOException e) {
boolean hasIOExceptionCause = false;
Throwable t = e;
while (t != null) {
if (t instanceof IOException) {
hasIOExceptionCause = true;
break;
}
t = t.getCause();
}
if (hasIOExceptionCause) {
log.info("Error on getting remote info, trying again: " + e.getMessage());
Thread.sleep(500);
} else {
throw e;
}
}
}
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not get remote info after many retries on NoHttpResponseException");
}
public SimpleSolrResponse invoke(String solrNode, String path, SolrParams params)
throws IOException, SolrServerException {