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

分享好友

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

4.4.3 获取Handler

protected void init() throwsException { // check for management path String alternate =cores.getManagementPath(); if (alternate != null &&path.startsWith(alternate)) { path = path.substring(0, alternate.length()); } // unused feature ? int idx = path.indexOf(':'); if (idx > 0) { // save the portion after the ':' for a 'handler' path parameter path = path.substring(0, idx); } // Check for container handlers handler = cores.getRequestHandler(path); if (handler != null) { solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req); solrReq.getContext().put(CoreContainer.class.getName(), cores); requestType =RequestType.ADMIN; action =ADMIN; return; } // Parse a core or collection name from the path and attempt to see if it's a core name idx = path.indexOf("/", 1); if (idx > 1) { origCorename = path.substring(1, idx); // Try to resolve a Solr core name core =cores.getCore(origCorename); if (core != null) { path =path.substring(idx); } else{ if (cores.isCoreLoading(origCorename)) { // extra mem barriers, so don't look at this before trying to get core throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "SolrCore is loading"); } // the core may have just finished loading core =cores.getCore(origCorename); if (core != null) { path =path.substring(idx); } else{ if (!cores.isZooKeeperAware()) { core = cores.getCore(""); } } } } if(cores.isZooKeeperAware()) { // init collectionList (usually one name but not when there are aliases) String def = core != null ?core.getCoreDescriptor().getCollectionName() : origCorename; collectionsList = resolveCollectionListOrAlias(queryParams.get(COLLECTION_PROP, def)); // &collection= takes precedence if (core == null) { // lookup core from collection, or route away if need to String collectionName = collectionsList.isEmpty() ? null : collectionsList.get(0); // route to 1st //TODO try the other collections if can't find a local replica of the first? (and do to V2HttpSolrCall) boolean isPreferLeader = (path.endsWith("/update") || path.contains("/update/")); core = getCoreByCollection(collectionName, isPreferLeader); // find a local replica/core for the collection if (core != null) { if (idx > 0) { path =path.substring(idx); } } else{ // if we couldn't find it locally, look on other nodes if (idx > 0) { extractRemotePath(collectionName, origCorename); if (action ==REMOTEQUERY) { path =path.substring(idx); return; } } //core is not available locally or remotelyautoCreateSystemColl(collectionName); if (action != null) return; } } } // With a valid core... if (core != null) { MDCLoggingContext.setCore(core); config =core.getSolrConfig(); // get or create/cache the parser for the core SolrRequestParsers parser =config.getRequestParsers(); // Determine the handler from the url path if not set // (we might already have selected the cores handler)extractHandlerFromURLPath(parser); if (action != null) return; // With a valid handler and a valid core... if (handler != null) { // if not a /select, create the request if (solrReq == null) { solrReq =parser.parse(core, path, req); } invalidStates =checkStateVersionsAreValid(solrReq.getParams().get(CloudSolrClient.STATE_VERSION)); addCollectionParamIfNeeded(getCollectionsList()); action =PROCESS; return; // we are done with a valid handler} } log.debug("no handler or core retrieved for " + path + ", follow through..."); action = PASSTHROUGH;

}

4.4.4 CoreContainer

publicSolrRequestHandler getRequestHandler(String path) { return RequestHandlerBase.getRequestHandler(path, containerHandlers);

}

分享好友

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

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

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

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

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

栈主、嘉宾

查看更多
  • 我没
    栈主

小栈成员

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