ITPub博客

首页 > > > solr调用lucene底层实现倒排索引源码解析-3

solr调用lucene底层实现倒排索引源码解析-3

作者:longmanma 时间:2019-12-18 18:07:31 0 删除 编辑

红色部分的调用

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.执行请求调用

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2730/viewspace-3170091/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-12-18

  • 博文量
    492
  • 访问量
    11988