mirror of
https://github.com/apache/lucene.git
synced 2025-02-08 19:15:06 +00:00
SOLR-7746: Ping requests stopped working with distrib=true in Solr 5.2.1
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1702581 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bab7afb072
commit
555cc50930
@ -188,6 +188,8 @@ Bug Fixes
|
|||||||
related to leader initiated recovery is performed by a dedicated LIR thread in the background.
|
related to leader initiated recovery is performed by a dedicated LIR thread in the background.
|
||||||
(Ramkumar Aiyengar, shalin)
|
(Ramkumar Aiyengar, shalin)
|
||||||
|
|
||||||
|
* SOLR-7746: Ping requests stopped working with distrib=true in Solr 5.2.1. (Michael Sun)
|
||||||
|
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
@ -23,18 +23,19 @@ import java.nio.file.Files;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
|
import org.apache.solr.common.params.ShardParams;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.util.DateFormatUtil;
|
|
||||||
import org.apache.solr.util.plugin.SolrCoreAware;
|
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrRequestHandler;
|
import org.apache.solr.request.SolrRequestHandler;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.solr.util.DateFormatUtil;
|
||||||
|
import org.apache.solr.util.plugin.SolrCoreAware;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -53,10 +54,13 @@ import org.slf4j.LoggerFactory;
|
|||||||
* executed. If the request succeeds, then the PingRequestHandler
|
* executed. If the request succeeds, then the PingRequestHandler
|
||||||
* will respond back with a simple "OK" status. If the request fails,
|
* will respond back with a simple "OK" status. If the request fails,
|
||||||
* then the PingRequestHandler will respond back with the
|
* then the PingRequestHandler will respond back with the
|
||||||
* corrisponding HTTP Error code. Clients (such as load balancers)
|
* corresponding HTTP Error code. Clients (such as load balancers)
|
||||||
* can be configured to poll the PingRequestHandler monitoring for
|
* can be configured to poll the PingRequestHandler monitoring for
|
||||||
* these types of responses (or for a simple connection failure) to
|
* these types of responses (or for a simple connection failure) to
|
||||||
* know if there is a problem with the Solr server.
|
* know if there is a problem with the Solr server.
|
||||||
|
*
|
||||||
|
* Note in case isShard=true, PingRequestHandler respond back with
|
||||||
|
* what the delegated handler returns (by default it's /select handler).
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <pre class="prettyprint">
|
* <pre class="prettyprint">
|
||||||
@ -233,7 +237,7 @@ public class PingRequestHandler extends RequestHandlerBase implements SolrCoreAw
|
|||||||
SolrCore core = req.getCore();
|
SolrCore core = req.getCore();
|
||||||
|
|
||||||
// Get the RequestHandler
|
// Get the RequestHandler
|
||||||
String qt = params.get( CommonParams.QT );//optional; you get the default otherwise
|
String qt = params.get( CommonParams.QT );//optional; you get the default otherwise
|
||||||
SolrRequestHandler handler = core.getRequestHandler( qt );
|
SolrRequestHandler handler = core.getRequestHandler( qt );
|
||||||
if( handler == null ) {
|
if( handler == null ) {
|
||||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
@ -241,27 +245,54 @@ public class PingRequestHandler extends RequestHandlerBase implements SolrCoreAw
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( handler instanceof PingRequestHandler ) {
|
if( handler instanceof PingRequestHandler ) {
|
||||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
// In case it's a query for shard, use default handler
|
||||||
"Cannot execute the PingRequestHandler recursively" );
|
if (params.getBool(ShardParams.IS_SHARD, false)) {
|
||||||
|
handler = core.getRequestHandler( null );
|
||||||
|
ModifiableSolrParams wparams = new ModifiableSolrParams(params);
|
||||||
|
wparams.remove(CommonParams.QT);
|
||||||
|
req.setParams(wparams);
|
||||||
|
} else {
|
||||||
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||||
|
"Cannot execute the PingRequestHandler recursively" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the ping query and catch any possible exception
|
// Execute the ping query and catch any possible exception
|
||||||
Throwable ex = null;
|
Throwable ex = null;
|
||||||
try {
|
|
||||||
SolrQueryResponse pingrsp = new SolrQueryResponse();
|
|
||||||
core.execute(handler, req, pingrsp );
|
|
||||||
ex = pingrsp.getException();
|
|
||||||
}
|
|
||||||
catch( Exception e ) {
|
|
||||||
ex = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send an error or an 'OK' message (response code will be 200)
|
// In case it's a query for shard, return the result from delegated handler for distributed query to merge result
|
||||||
if( ex != null ) {
|
if (params.getBool(ShardParams.IS_SHARD, false)) {
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
try {
|
||||||
"Ping query caused exception: "+ex.getMessage(), ex );
|
core.execute(handler, req, rsp );
|
||||||
}
|
ex = rsp.getException();
|
||||||
rsp.add( "status", "OK" );
|
}
|
||||||
|
catch( Exception e ) {
|
||||||
|
ex = e;
|
||||||
|
}
|
||||||
|
// Send an error or return
|
||||||
|
if( ex != null ) {
|
||||||
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||||
|
"Ping query caused exception: "+ex.getMessage(), ex );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
SolrQueryResponse pingrsp = new SolrQueryResponse();
|
||||||
|
core.execute(handler, req, pingrsp );
|
||||||
|
ex = pingrsp.getException();
|
||||||
|
}
|
||||||
|
catch( Exception e ) {
|
||||||
|
ex = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send an error or an 'OK' message (response code will be 200)
|
||||||
|
if( ex != null ) {
|
||||||
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||||
|
"Ping query caused exception: "+ex.getMessage(), ex );
|
||||||
|
}
|
||||||
|
|
||||||
|
rsp.add( "status", "OK" );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleEnable(boolean enable) throws SolrException {
|
protected void handleEnable(boolean enable) throws SolrException {
|
||||||
|
@ -19,9 +19,15 @@ package org.apache.solr.handler;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||||
|
import org.apache.solr.client.solrj.impl.CloudSolrClient;
|
||||||
|
import org.apache.solr.client.solrj.request.SolrPing;
|
||||||
|
import org.apache.solr.client.solrj.response.SolrPingResponse;
|
||||||
|
import org.apache.solr.cloud.MiniSolrCloudCluster;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
@ -30,6 +36,9 @@ import org.junit.Before;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
public class PingRequestHandlerTest extends SolrTestCaseJ4 {
|
public class PingRequestHandlerTest extends SolrTestCaseJ4 {
|
||||||
|
protected int NUM_SERVERS = 5;
|
||||||
|
protected int NUM_SHARDS = 2;
|
||||||
|
protected int REPLICATION_FACTOR = 2;
|
||||||
|
|
||||||
private final String fileName = this.getClass().getName() + ".server-enabled";
|
private final String fileName = this.getClass().getName() + ".server-enabled";
|
||||||
private File healthcheckFile = null;
|
private File healthcheckFile = null;
|
||||||
@ -164,6 +173,48 @@ public class PingRequestHandlerTest extends SolrTestCaseJ4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPingInClusterWithNoHealthCheck() throws Exception {
|
||||||
|
|
||||||
|
File solrXml = new File(SolrTestCaseJ4.TEST_HOME(), "solr-no-core.xml");
|
||||||
|
MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir().toFile(), solrXml, buildJettyConfig("/solr"));
|
||||||
|
|
||||||
|
final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertNotNull(miniCluster.getZkServer());
|
||||||
|
List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
|
||||||
|
assertEquals(NUM_SERVERS, jettys.size());
|
||||||
|
for (JettySolrRunner jetty : jettys) {
|
||||||
|
assertTrue(jetty.isRunning());
|
||||||
|
}
|
||||||
|
|
||||||
|
// create collection
|
||||||
|
String collectionName = "testSolrCloudCollection";
|
||||||
|
String configName = "solrCloudCollectionConfig";
|
||||||
|
File configDir = new File(SolrTestCaseJ4.TEST_HOME() + File.separator + "collection1" + File.separator + "conf");
|
||||||
|
miniCluster.uploadConfigDir(configDir, configName);
|
||||||
|
miniCluster.createCollection(collectionName, NUM_SHARDS, REPLICATION_FACTOR, configName, null);
|
||||||
|
|
||||||
|
// Send distributed and non-distributed ping query
|
||||||
|
SolrPingWithDistrib reqDistrib = new SolrPingWithDistrib();
|
||||||
|
reqDistrib.setDistrib(true);
|
||||||
|
SolrPingResponse rsp = reqDistrib.process(cloudSolrClient, collectionName);
|
||||||
|
assertEquals(0, rsp.getStatus());
|
||||||
|
|
||||||
|
SolrPing reqNonDistrib = new SolrPing();
|
||||||
|
rsp = reqNonDistrib.process(cloudSolrClient, collectionName);
|
||||||
|
assertEquals(0, rsp.getStatus());
|
||||||
|
|
||||||
|
// delete the collection we created earlier
|
||||||
|
miniCluster.deleteCollection(collectionName);
|
||||||
|
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
miniCluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper Method: Executes the request against the handler, returns
|
* Helper Method: Executes the request against the handler, returns
|
||||||
* the response, and closes the request.
|
* the response, and closes the request.
|
||||||
@ -181,4 +232,12 @@ public class PingRequestHandlerTest extends SolrTestCaseJ4 {
|
|||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SolrPingWithDistrib extends SolrPing {
|
||||||
|
public SolrPing setDistrib(boolean distrib) {
|
||||||
|
getParams().add("distrib", distrib ? "true" : "false");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user