SOLR-14942: Move request registration to ContentStreamHandlerBase (#2112)

This addresses review feedback from David Smiley on Jira. It moves the request registration to the ContentStreamHandlerBase class instead of doing a hack-ish instanceof check inside HttpSolrCall.
This commit is contained in:
Shalin Shekhar Mangar 2020-12-02 10:11:23 +05:30 committed by GitHub
parent feb897a962
commit d99c1667a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 72 deletions

View File

@ -22,6 +22,7 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.loader.ContentStreamLoader; import org.apache.solr.handler.loader.ContentStreamLoader;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.SolrCoreState;
import org.apache.solr.update.processor.UpdateRequestProcessor; import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorChain; import org.apache.solr.update.processor.UpdateRequestProcessorChain;
@ -47,6 +48,19 @@ public abstract class ContentStreamHandlerBase extends RequestHandlerBase {
@Override @Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
/*
We track update requests so that we can preserve consistency by waiting for them to complete
on a node shutdown and then immediately trigger a leader election without waiting for the core to close.
See how the SolrCoreState#pauseUpdatesAndAwaitInflightRequests() method is used in CoreContainer#shutdown()
Also see https://issues.apache.org/jira/browse/SOLR-14942 for details on why we do not care for
other kinds of requests.
*/
SolrCoreState solrCoreState = req.getCore().getSolrCoreState();
if (!solrCoreState.registerInFlightUpdate()) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Updates are temporarily paused for core: " + req.getCore().getName());
}
try {
SolrParams params = req.getParams(); SolrParams params = req.getParams();
UpdateRequestProcessorChain processorChain = UpdateRequestProcessorChain processorChain =
req.getCore().getUpdateProcessorChain(params); req.getCore().getUpdateProcessorChain(params);
@ -80,6 +94,9 @@ public abstract class ContentStreamHandlerBase extends RequestHandlerBase {
processor.close(); processor.close();
} }
} }
} finally {
solrCoreState.deregisterInFlightUpdate();
}
} }
protected abstract ContentStreamLoader newLoader(SolrQueryRequest req, UpdateRequestProcessor processor); protected abstract ContentStreamLoader newLoader(SolrQueryRequest req, UpdateRequestProcessor processor);

View File

@ -86,7 +86,6 @@ import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.ContentStreamHandlerBase; import org.apache.solr.handler.ContentStreamHandlerBase;
import org.apache.solr.handler.UpdateRequestHandler;
import org.apache.solr.logging.MDCLoggingContext; import org.apache.solr.logging.MDCLoggingContext;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
@ -551,18 +550,6 @@ public class HttpSolrCall {
remoteQuery(coreUrl + path, resp); remoteQuery(coreUrl + path, resp);
return RETURN; return RETURN;
case PROCESS: case PROCESS:
/*
We track update requests so that we can preserve consistency by waiting for them to complete
on a node shutdown and then immediately trigger a leader election without waiting for the core to close.
See how the SolrCoreState#pauseUpdatesAndAwaitInflightRequests() method is used in CoreContainer#shutdown()
Also see https://issues.apache.org/jira/browse/SOLR-14942 for details on why we do not care for
other kinds of requests.
*/
if (handler instanceof UpdateRequestHandler && !core.getSolrCoreState().registerInFlightUpdate()) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Updates are temporarily paused for core: " + core.getName());
}
try {
final Method reqMethod = Method.getMethod(req.getMethod()); final Method reqMethod = Method.getMethod(req.getMethod());
HttpCacheHeaderUtil.setCacheControlHeader(config, resp, reqMethod); HttpCacheHeaderUtil.setCacheControlHeader(config, resp, reqMethod);
// unless we have been explicitly told not to, do cache validation // unless we have been explicitly told not to, do cache validation
@ -596,12 +583,6 @@ public class HttpSolrCall {
writeResponse(solrRsp, responseWriter, reqMethod); writeResponse(solrRsp, responseWriter, reqMethod);
} }
return RETURN; return RETURN;
} finally {
if (handler instanceof UpdateRequestHandler) {
// every registered request must also be de-registered
core.getSolrCoreState().deregisterInFlightUpdate();
}
}
default: return action; default: return action;
} }
} catch (Throwable ex) { } catch (Throwable ex) {