1. SolrCloud的update索引链
solr cloud的update索引链的类是org.apache.solr.update.processor.UpdateRequestProcessorChain,这个类在solr初始化的时候就会定义
solr cloud的update索引链在solrconfig.xml中进行定义
代码语言:javascript复制<updateRequestProcessorChain name="add-unknown-fields-to-the-schema" default="${update.autoCreateFields:true}"
processor="uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date">
<processor class="solr.LogUpdateProcessorFactory"/>
<processor class="solr.DistributedUpdateProcessorFactory"/>
<processor class="solr.RunUpdateProcessorFactory"/>
</updateRequestProcessorChain>
2. SolrCloud索引链初始化过程
代码语言:javascript复制public void init(PluginInfo info) {
final String infomsg = "updateRequestProcessorChain ""
(null != info.name ? info.name : "") """
(info.isDefault() ? " (default)" : "");
log.debug("creating " infomsg);
// 根据solrconfig.xml中的配置创建UpdateRequestProcessorFactory的实例列表
List<UpdateRequestProcessorFactory> list = new ArrayList<>
(solrCore.initPlugins(info.getChildren("processor"),UpdateRequestProcessorFactory.class,null));
// 如果solrconfig.xml中的updateRequestProcessorChain没有配置processor子属性列表,
// 那么上一步创建的list为空,抛出异常
if(list.isEmpty()){
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
infomsg " require at least one processor");
}
int numDistrib = 0;
int runIndex = -1;
// 统计上一步创建的UpdateRequestProcessorFactory列表中DistributingUpdateProcessorFactory的
// 实例的数量,和RunUpdateProcessorFactory在列表中的位置
for (int i = list.size()-1; 0 <= i; i--) {
UpdateRequestProcessorFactory factory = list.get(i);
if (factory instanceof DistributingUpdateProcessorFactory) {
numDistrib ;
}
if (factory instanceof RunUpdateProcessorFactory) {
runIndex = i;
}
}
// 如果上一步DistributingUpdateProcessorFactory的数量大于1,抛出异常
if (1 < numDistrib) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
infomsg " may not contain more then one "
"instance of DistributingUpdateProcessorFactory");
}
// 如果上一步UpdateRequestProcessorFactory列表中存在RunUpdateProcessorFactory,
// 但是DistributingUpdateProcessorFactory不存在,向列表中RunUpdateProcessorFactory的前面
// 插入默认的DistributedUpdateProcessorFactory实例
if (0 <= runIndex && 0 == numDistrib) {
// by default, add distrib processor immediately before run
DistributedUpdateProcessorFactory distrib
= new DistributedUpdateProcessorFactory();
distrib.init(new NamedList());
list.add(runIndex, distrib);
log.debug("inserting DistributedUpdateProcessorFactory into " infomsg);
}
// 根据solrconfig.xml中processor和post-processor属性生成最终的UpdateRequestProcessorFactory的列表
chain = list;
ProcessorInfo processorInfo = new ProcessorInfo(new MapSolrParams(info.attributes));
if (processorInfo.isEmpty()) return;
UpdateRequestProcessorChain newChain = constructChain(this, processorInfo, solrCore);
chain = newChain.chain;
}
下一篇文章具体介绍solr cloud中索引一篇文档的具体流程