当前位置:网站首页>ES source code API call link source code analysis
ES source code API call link source code analysis
2022-07-31 04:55:00 【spirit of water】
Regarding the API call link, let's start with the familiar three-tier MVC architecture.Those who are doing development are more familiar with spring springMVC. The routine we are familiar with is that the request goes to the controller layer first, then the controller calls the service layer, and then the result is returned.Usually, we also have tomcat as a server to receive requests, and the received requests call the controller layer.A user's request, such as an http request, usually goes to the tomcat service first, and then calls the program's controller.
Then look at how es play, es does not use spring spingMVC, only Guice is used for container management, es does not choose to use a server similar to tomcat to receive requests, but chooses netty to implement the server,Complete the receiving and sending of requests.This corresponds to the RestController in the figure below. This layer has the same function as tomcat.The BaseRestHandler in the figure below can actually be understood as selecting a controller router, which selects a controller according to the url path in the request.The RestSearchAction in the third step in the figure below is the controller layer in the MVC that we understood before. Different functions are placed in different RestActions. In fact, some logic is also placed here.The NodeClient layer actually has a taste of service, and it is where the logic is really executed.Unlike traditional services, es is a natural distributed application.
Netty4HttpServerTransport.dispatchRequest()
RestController.dispatchRequest().tryAllHandlers()
RestController.dispatchRequest() calls wrappedHandler.handleRequest() in the method
BaseRestHandler.handleRequest() Then call the prepareRequest() method in the method. At this point, a specific action will actually be selected according to the request.prepareRequest() is actually an interface. You can see the implementation class below. The red box is just a case (this is an Action corresponding to deleting an index). In prepareRequest, the rest request is converted into a request recognized by es.
Analyze with a case (RestDeleteIndexAction)
Then see:
@Overridepublic RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index"))); deleteIndexRequest.timeout(request.paramAsTime("timeout", deleteIndexRequest.timeout())); deleteIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexRequest.masterNodeTimeout())); deleteIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteIndexRequest.indicesOptions())); return channel -> client.admin().indices().delete(deleteIndexRequest, new RestToXContentListener<>(channel));}
Follow the delete in the fifth step and go down to ElasticsearchClient.execute(), which is another interface, and then follow its implementation class, come to AbstractClient.execute(), and call doExecute(), this is an abstract method, its implementation class NodeClient.doExecute(), calls executeLocally() in the method, this method will call transportAction(action).execute(), you can see that the action is executed!
Continue to step 6, click in transportAction(action).execute() and come to TransportAction.execute() In this class, continue to click execute(), which calls requestFilterChain.proceed(), inGo down to proceed() and call this.action.doExecute(task, request, listener), this doExecute() is a method in the TransportAction class, and this class is an abstract class, so look at it according to doExecuteImplementation class, different functions correspond to different actions, or take the example of deleting the index,
边栏推荐
- Simple read operation of EasyExcel
- Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析
- 【C语言】操作符详解
- MySQL数据库增删改查(基础操作命令详解)
- MySQL常见面试题汇总(建议收藏!!!)
- Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
- 行业落地呈现新进展 | 2022开放原子全球开源峰会OpenAtom OpenHarmony分论坛圆满召开
- 开放原子开源基金会秘书长孙文龙 | 凝心聚力,共拓开源
- 开源社区三十年 | 2022开放原子全球开源峰会开源社区三十年专题活动圆满召开
- 重磅 | 开放原子校源行活动正式启动
猜你喜欢
Unity打灵狐者
ES 源码 API调用链路源码分析
mysql使用on duplicate key update批量更新数据
三道leetcode上的oj题
开放原子开源基金会秘书长孙文龙 | 凝心聚力,共拓开源
PWN ROP
MySQL transaction isolation level, rounding
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
Go语学习笔记 - 处理超时问题 - Context使用 | 从零开始Go语言
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
随机推荐
MySQL数据库备份
产学研用 共建开源人才生态 | 2022开放原子全球开源峰会教育分论坛圆满召开
Unity shader forge和自带的shader graph,有哪些优缺点?
WeChat applet uses cloud functions to update and add cloud database nested array elements
Hand in hand to realize the picture preview plug-in (3)
Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
开源社区三十年 | 2022开放原子全球开源峰会开源社区三十年专题活动圆满召开
PWN ROP
C Implementation of Simple Network File Copy
Unity手机游戏性能优化系列:针对CPU端的性能调优
MySQL fuzzy query can use INSTR instead of LIKE
npm、nrm两种方式查看源和切换镜像
DVWA installation tutorial (understand what you don't understand · in detail)
Understanding of the presence of a large number of close_wait states
MySQL optimization slow log query
View source and switch mirrors in two ways: npm and nrm
【py脚本】批量二值化处理图像
【云原生】DevOps(五):集成Harbor
prompt.ml/15中<svg>标签使用解释
Summary of MySQL common interview questions (recommended collection!!!)