solr索引过程源码解析

本文详细探讨了Solr索引过程的源码分析,从SolrDispatchFilter开始,经HttpSolrCall调用,到SolrRequestHandler的选取。在更新过程中涉及tlog更新、分布式转发及更新链。核心部分是通过DocumentLoader的load方法,以XML格式为例,调用XMLLoader的processUpdate方法,最终利用indexWriter.updateDocument完成Lucene索引的更新。整个流程复杂且扩展性强。
摘要由CSDN通过智能技术生成

在文章http://blog.csdn.net/jj380382856/article/details/51603818我们分析了更新索引的solrj源码的处理方式,最后会向solr发送一个/update的请求,下面我们继续分析solr在接收到这个请求会怎么处理。

1.请求首先被SolrDispatchFilter截获,然后执行dofilter方法

2.在方法中调用 Action result = call.call();方法,进入HttpSolrCall.call()方法,这个方法会调用这个类的init()方法,该方法的主要作用是根据servlet和solrconfig的配置获取当前处理请求的SolrRequestHandler的对象。这个方法中调用了 extractHandlerFromURLPath(parser);方法,该方法代码如下。

private void extractHandlerFromURLPath(SolrRequestParsers parser) throws Exception {
    if (handler == null && path.length() > 1) { // don't match "" or "/" as valid path
      handler = core.getRequestHandler(path);
。。。。。。
  }

执行完这个代码后handler变成了


init()方法执行完成后action变成了process,HttpSolrCall.call()方法继续执行,代码如下,主要就是封装请求,这里面的主要的代码是  execute(solrRsp);

 switch (action) {
        case ADMIN:
          handleAdminRequest();
          return RETURN;
        case REMOTEQUERY:
          remoteQuery(coreUrl + path, resp);
          return RETURN;
        case PROCESS:
          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 = new SolrQueryResponse();
              /* 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(new SolrRequestInfo(solrReq, solrRsp));
            execute(solrRsp);<span style="color:#ff0000;">//主要代码</span>
            HttpCacheHeaderUtil.checkHttpCachingVeto(solrRsp, resp, reqMethod);
            Iterator<Map.Entry<String, String>> headers = solrRsp.httpHeaders();
            while (headers.hasNext()) {
              Map.Entry<String, String> entry = headers.next();
              resp.addHeader(ent
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值