use of org.apache.solr.request.SolrRequestHandler in project lucene-solr by apache.
the class RecoveryStrategy method replicate.
private final void replicate(String nodeName, SolrCore core, ZkNodeProps leaderprops) throws SolrServerException, IOException {
final String leaderUrl = getReplicateLeaderUrl(leaderprops);
LOG.info("Attempting to replicate from [{}].", leaderUrl);
// send commit
commitOnLeader(leaderUrl);
// use rep handler directly, so we can do this sync rather than async
SolrRequestHandler handler = core.getRequestHandler(ReplicationHandler.PATH);
ReplicationHandler replicationHandler = (ReplicationHandler) handler;
if (replicationHandler == null) {
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Skipping recovery, no " + ReplicationHandler.PATH + " handler found");
}
ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.set(ReplicationHandler.MASTER_URL, leaderUrl);
// we check closed on return
if (isClosed())
return;
boolean success = replicationHandler.doFetch(solrParams, false).getSuccessful();
if (!success) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Replication for recovery failed.");
}
// solrcloud_debug
if (LOG.isDebugEnabled()) {
try {
RefCounted<SolrIndexSearcher> searchHolder = core.getNewestSearcher(false);
SolrIndexSearcher searcher = searchHolder.get();
Directory dir = core.getDirectoryFactory().get(core.getIndexDir(), DirContext.META_DATA, null);
try {
LOG.debug(core.getCoreContainer().getZkController().getNodeName() + " replicated " + searcher.search(new MatchAllDocsQuery(), 1).totalHits + " from " + leaderUrl + " gen:" + (core.getDeletionPolicy().getLatestCommit() != null ? "null" : core.getDeletionPolicy().getLatestCommit().getGeneration()) + " data:" + core.getDataDir() + " index:" + core.getIndexDir() + " newIndex:" + core.getNewIndexDir() + " files:" + Arrays.asList(dir.listAll()));
} finally {
core.getDirectoryFactory().release(dir);
searchHolder.decref();
}
} catch (Exception e) {
LOG.debug("Error in solrcloud_debug block", e);
}
}
}
use of org.apache.solr.request.SolrRequestHandler in project lucene-solr by apache.
the class PingRequestHandler method handlePing.
protected void handlePing(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
SolrParams params = req.getParams();
SolrCore core = req.getCore();
// Get the RequestHandler
//optional; you get the default otherwise
String qt = params.get(CommonParams.QT);
SolrRequestHandler handler = core.getRequestHandler(qt);
if (handler == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown RequestHandler (qt): " + qt);
}
if (handler instanceof PingRequestHandler) {
// In case it's a query for shard, use default handler
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
Throwable ex = null;
// In case it's a query for shard, return the result from delegated handler for distributed query to merge result
if (params.getBool(ShardParams.IS_SHARD, false)) {
try {
core.execute(handler, req, rsp);
ex = rsp.getException();
} 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();
NamedList<Object> headers = rsp.getResponseHeader();
if (headers != null) {
headers.add("zkConnected", pingrsp.getResponseHeader().get("zkConnected"));
}
} 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");
}
}
use of org.apache.solr.request.SolrRequestHandler in project SearchServices by Alfresco.
the class SolrInformationServer method isInIndexImpl.
private boolean isInIndexImpl(String ids) throws IOException {
SolrQueryRequest request = null;
try {
request = getLocalSolrQueryRequest();
SolrRequestHandler handler = core.getRequestHandler(REQUEST_HANDLER_GET);
SolrQueryResponse rsp = new SolrQueryResponse();
ModifiableSolrParams newParams = new ModifiableSolrParams(request.getParams());
newParams.set("ids", ids);
request.setParams(newParams);
handler.handleRequest(request, rsp);
@SuppressWarnings("rawtypes") NamedList values = rsp.getValues();
SolrDocumentList response = (SolrDocumentList) values.get(RESPONSE_DEFAULT_IDS);
return response.getNumFound() > 0;
} finally {
if (request != null) {
request.close();
}
}
}
Aggregations