绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
solr调用lucene底层实现倒排索引源码解析-3
2019-12-18 18:07:31

红色部分的调用

4.4.2 HttpSolrCall

/** * This method processes the request. */ public Action call() throwsIOException { MDCLoggingContext.reset(); MDCLoggingContext.setNode(cores); if (cores == null) { sendError(503, "Server is shutting down or failed to initialize"); returnRETURN; } if (solrDispatchFilter.abortErrorMessage != null) { sendError(500, solrDispatchFilter.abortErrorMessage); returnRETURN; } try{ init();//1 /* Authorize the request if 1. Authorization is enabled, and 2. The requested resource is not a known static file */ if (cores.getAuthorizationPlugin() != null &&shouldAuthorize()) { AuthorizationContext context =getAuthCtx(); log.debug("AuthorizationContext : {}", context); AuthorizationResponse authResponse =cores.getAuthorizationPlugin().authorize(context); if (authResponse.statusCode ==AuthorizationResponse.PROMPT.statusCode) { Map headers = (Map) getReq().getAttribute(AuthenticationPlugin.class.getName()); if (headers != null) { for (Map.Entrye : headers.entrySet()) response.setHeader(e.getKey(), e.getValue()); } log.debug("USER_REQUIRED "+req.getHeader("Authorization")+" "+req.getUserPrincipal()); } if (!(authResponse.statusCode == HttpStatus.SC_ACCEPTED) && !(authResponse.statusCode ==HttpStatus.SC_OK)) { log.info("USER_REQUIRED auth header {} context : {} ", req.getHeader("Authorization"), context); sendError(authResponse.statusCode, "Unauthorized request, Response code: " +authResponse.statusCode); returnRETURN; } } HttpServletResponse resp =response; switch(action) { caseADMIN: handleAdminRequest(); returnRETURN; caseREMOTEQUERY: remoteQuery(coreUrl +path, resp); returnRETURN; casePROCESS: final Method reqMethod =Method.getMethod(req.getMethod()); HttpCacheHeaderUtil.setCacheControlHeader(config, resp, reqMethod); // unless we have been explicitly told not to, do cache validation // if we fail cache validation, execute the query if (config.getHttpCachingConfig().isNever304() || !HttpCacheHeaderUtil.doCacheHeaderValidation(solrReq, req, reqMethod, resp)) { SolrQueryResponse solrRsp = newSolrQueryResponse(); /* even for HEAD requests, we need to execute the handler to * ensure we don't get an error (and to make sure the correct * QueryResponseWriter is selected and we get the correct * Content-Type) */SolrRequestInfo.setRequestInfo(newSolrRequestInfo(solrReq, solrRsp)); execute(solrRsp); //2 HttpCacheHeaderUtil.checkHttpCachingVeto(solrRsp, resp, reqMethod); Iterator> headers =solrRsp.httpHeaders(); while(headers.hasNext()) { Map.Entry entry =headers.next(); resp.addHeader(entry.getKey(), entry.getValue()); } QueryResponseWriter responseWriter =getResponseWriter(); if (invalidStates != null) solrReq.getContext().put(CloudSolrClient.STATE_VERSION, invalidStates); writeResponse(solrRsp, responseWriter, reqMethod); } returnRETURN; default: returnaction; } } catch(Throwable ex) { sendError(ex); // walk the the entire cause chain to search for an Error Throwable t =ex; while (t != null) { if (t instanceofError) { if (t !=ex) { log.error("An Error was wrapped in another exception - please report complete stacktrace on SOLR-6161", ex); } throw(Error) t; } t =t.getCause(); } returnRETURN; } finally {

MDCLoggingContext.clear();

}

}

其中 1初始化,2.执行请求调用

分享好友

分享这个小栈给你的朋友们,一起进步吧。

凉城时光
创建时间:2019-12-04 10:57:57
朋友 我们一起聊运维
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

栈主、嘉宾

查看更多
  • 我没
    栈主

小栈成员

查看更多
  • unnamed personq
  • unnamed personq
  • bluetooth
  • amadan
戳我,来吐槽~