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

分享好友

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

4.4 入口是SolrDispatchFilter,整个流程如流程图所示

从上面的流程图可以看出,solr采用filter的模式(如struts2,springmvc使用servlet模式),然后以容器的方式来封装各种Handler,Handler负责处理各种请求,终调用的是lucene的底层实现。

注意:solr没有使用lucene本身的QueryParser,而是自己重写了这个组件。

4.4.1 SolrDispatchFilter入口

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throwsIOException, ServletException { if (!(request instanceof HttpServletRequest)) return; try{ if (cores == null ||cores.isShutDown()) { try{ init.await(); } catch (InterruptedException e) { //well, no wait then} final String msg = "Error processing the request. CoreContainer is either not initialized or shutting down."; if (cores == null ||cores.isShutDown()) { log.error(msg); throw newUnavailableException(msg); } } AtomicReference wrappedRequest = new AtomicReference (); if (!authenticateRequest(request, response, wrappedRequest)) { // the response and status code have already been // sent return; } if (wrappedRequest.get() != null) { request =wrappedRequest.get(); } request =closeShield(request, retry); response =closeShield(response, retry); if (cores.getAuthenticationPlugin() != null) { log.debug("User principal: {}", ((HttpServletRequest) request).getUserPrincipal()); } // No need to even create the HttpSolrCall object if this path is excluded. if (excludePatterns != null) { String requestPath =((HttpServletRequest) request).getServletPath(); String extraPath =((HttpServletRequest) request).getPathInfo(); if (extraPath != null) { // In embedded mode, servlet path is empty - include all post-context path here for // testing requestPath +=extraPath; } for(Pattern p : excludePatterns) { Matcher matcher =p.matcher(requestPath); if(matcher.lookingAt()) { chain.doFilter(request, response); return; } } } HttpSolrCall call =getHttpSolrCall((HttpServletRequest) request, (HttpServletResponse) response, retry); ExecutorUtil.setServerThreadFlag(Boolean.TRUE); try{ Action result = call.call(); //1 switch(result) { casePASSTHROUGH: chain.doFilter(request, response); break; caseRETRY: doFilter(request, response, chain, true); break; caseFORWARD: request.getRequestDispatcher(call.getPath()).forward(request, response); break; } } finally{ call.destroy(); ExecutorUtil.setServerThreadFlag(null); } } finally {

consumeInputFully((HttpServletRequest) request);

}

}

分享好友

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

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

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

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

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

栈主、嘉宾

查看更多
  • 我没
    栈主

小栈成员

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