[代码] 如何处理添加和删除文档请求
2013-07-05 21:04
363 查看
who got updateRequest first?
the answer is SolrDispatchFilter. let's look a graph first:1. .doFilter receive any update request first. doFilter will choice a right core for this request.
a. if the request specify a core(for index request) or cores(for search request), give the request to the specified core(s)
b. if not, we will try the collection. find the first leader core then send this request to it. usually the
then doFilter will find the rigth requestHander for the request according the request. the requestHandler would be :
the REST API decide which handler will be taken
2. now, we got a handler and a core to process this request. bring the request to core.execute(handler, req, rsp). the specified core will deal with the rest.
the core add some header to response the call supper.handleRequestBody(req, rsp)
above is the full code of HandleRequestBody(……)
1. create all the processor in the processorChain and return the first processor(LogUpdateProcessor)
the processorChain :
2. got a documentLoader according to the requestHandler. then call Loader.load(req,
rsp, stream)
.load() call processUpdate and process different commands respectively. all update request pass to processor created in the step 1. the processor is LogUpdateProcessor.
it call next processor in the processor chain recursively
the commit command with add or delete request will be removed in this progress. commit will execute at the next step 3
if we recieve a json format index request, the documentLoader here would be JsonLoader. we discuss add doc request processing which is the same as delete request
we look into the JsonLoader.processUpdate()
void processUpdate() throws IOException { int ev = parser.nextEvent(); while ( ev != JSONParser.EOF ) { switch ( ev ) { case JSONParser.ARRAY_START: handleAdds(); break ; case JSONParser.STRING: if ( parser.wasKey() ) { String v = parser.getString(); if ( v.equals( UpdateRequestHandler.ADD ) ) { int ev2 = parser.nextEvent(); if (ev2 == JSONParser.OBJECT_START) { processor.processAdd( parseAdd() ); } else if (ev2 == JSONParser.ARRAY_START) { handleAdds(); } else { assertEvent(ev2, JSONParser.OBJECT_START); } } else if ( v.equals( UpdateRequestHandler.COMMIT ) ) { CommitUpdateCommand cmd = new CommitUpdateCommand(req, false ); cmd.waitSearcher = true ; parseCommitOptions( cmd ); processor.processCommit( cmd ); } else if ( v.equals( UpdateRequestHandler.OPTIMIZE ) ) { CommitUpdateCommand cmd = new CommitUpdateCommand(req, true ); cmd.waitSearcher = true ; parseCommitOptions( cmd ); processor.processCommit( cmd ); } else if ( v.equals( UpdateRequestHandler.DELETE ) ) { handleDeleteCommand(); } else if ( v.equals( UpdateRequestHandler.ROLLBACK ) ) { processor.processRollback( parseRollback() ); } else { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown command: " +v+ " [" +parser.getPosition()+ "]" ); } break ; } // fall through case JSONParser.LONG: case JSONParser.NUMBER: case JSONParser.BIGNUMBER: case JSONParser.BOOLEAN: case JSONParser.NULL: log.info( "can't have a value here! " +JSONParser.getEventString(ev)+ " " +parser.getPosition() ); case JSONParser.OBJECT_START: case JSONParser.OBJECT_END: case JSONParser.ARRAY_END: break ; default : log.info( "Noggit UNKNOWN_EVENT_ID:" +ev); break ; } // read the next event ev = parser.nextEvent(); } } |
LogUpdateProcessor.processAdd(cmd)
public void processAdd(AddUpdateCommand cmd) throws IOException { if (logDebug) { log.debug( "PRE_UPDATE " + cmd.toString()); } // call delegate first so we can log things like the version that get set later if (next != null ) next.processAdd(cmd); // Add a list of added id's to the response if (adds == null ) { adds = new ArrayList<String>(); toLog.add( "add" ,adds); } if (adds.size() < maxNumToLog) { //10 long version = cmd.getVersion(); String msg = cmd.getPrintableId(); if (version != 0 ) msg = msg + " (" + version + ')' ; adds.add(msg); } numAdds++; } |
firstly . then LogUpdateProcessor.processAdd( cmd) will write some logs info.
now, the request deal by DistributedUpdateProcessor.processAdd(cmd). DistributedUpdateProcessor is
the key point for cloud solr. it decid which silce the request should send to.
follow code hash the request cmd then decid which nodes this request should sennd to. whether or not i'm a leader. seting forwardToLeader flag to indicate whether or not to distribute
to leader.
int hash = 0 ; if (zkEnabled) { zkCheck(); hash = hash(cmd); nodes = setupRequest(hash); } else { isLeader = getNonZkLeaderAssumption(req); } |
if (!forwardToLeader) { // clone the original doc SolrInputDocument clonedDoc = cmd.solrDoc.deepCopy(); dropCmd = versionAdd(cmd, clonedDoc); cmd.solrDoc = clonedDoc; } |
if there are any node need to distribute to then do :
if (nodes != null ) { params = new ModifiableSolrParams(req.getParams()); params.set(DISTRIB_UPDATE_PARAM, (isLeader ? DistribPhase.FROMLEADER.toString() : DistribPhase.TOLEADER.toString())); params.remove( "commit" ); // this will be distributed from the local commit cmdDistrib.distribAdd(cmd, nodes, params); //key function for distribute command } |
this addRequest(cmd) to all nodes.
3. process commit or rollback if the request contain those kind of commands
4. call processor.finish() to finish the request processing and finish the severlet response
相关文章推荐
- 开发人员在使用Aspose.Pdf for .NET时如何用C#和VB两种代码添加附件到PDF文档?
- 在VS2005如何删除已添加的消息处理函数
- 在VS2005如何删除已添加的消息处理函数
- PDF文档如何添加、删除或移动页面
- C# 如何在Word文档中添加,替换和删除书签
- C# 如何处理Word文档分页——插入、删除、阻止分页
- 新手篇01_如何在新建文档中添加控件以及初始化时删除菜单及工具栏
- SQLite数据库创建、升级数据库、事务处理、添加、更新、删除、查询管理操作类完整代码
- 如何在Keil中添加AStyle对代码进行格式化处理
- 如何批量 删除/添加 数据库中被注入的代码?
- 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加MIME映射
- C#如何实现在PPT文档中插入、编辑和删除表格的操作
- C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
- js中cookie的添加、取值、删除示例代码
- 关于gridview如何添加编辑删除
- 由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为)以便将异常信息发送回客户端,或打开对每个 Microsoft .NET Framework SDK 文档的跟踪并检查服务器跟踪日志。
- 动态添加删除表格行的js实现代码
- jQuery动态添加与删除tr行实例代码
- 如何通过代码添加ChildViewController
- java 集合类如何正确在迭代中添加删除元素