写点什么

Elasticsearch Document 增删改内部原理

用户头像
escray
关注
发布于: 2021 年 02 月 01 日
Elasticsearch Document 增删改内部原理

文字内容整理自 B 站中华石杉的 Elasticsearch 顶尖高手系列课程核心知识篇


当你启动一个 Elasticsearch 的实例,就启动了一个节点。一组相互连接的节点就构成了集群。如果你运行一个单节点的 Elasticsearch,那就是只有一个节点的 Elasticsearch 集群。


Any time that you start an instance of Elasticsearch, you are starting a node. A collection of connected nodes is called a cluster. If you are running a single node of Elasticsearch, then you have a cluster of one node.


假设一个 Elastisearch 的集群有三个节点 Node,3 个 Primary Shard,3 个 Replica Shard。


当一个客户端 Client,假设是一个 Java 程序,要创建一个 Document,那么它可以选择任意一个 Node,然后将请求发送过去。


集群中的每一个节点 Node 都知道任意一个 Document 在哪个节点上,所以,对于客户端来说,请求发给哪个节点都一样。


All nodes know about all the other nodes in the cluster and can forward client requests to the appropriate node.


接收到请求的节点被称为协调节点 Coordinating node。


如果是增删改(注意,没有查)操作,这类只能由 Primary Shard 处理的,协调节点通过路由计算,将请求转发到对应的 Primary Shard。


Primary Shard 在其所在节点上完成操作,并且同步给自己的 Replica Shard。


最终由协调节点响应客户端 client,告知操作结果。


问题来了,是由 Primary Shard 通知 Coordinating Node 么,还是 Coordinating Node 监控或查询 Primary Shard 操作结果?


小结一下


  1. 客户端选择一个 node 发送请求过去,这个 node 就是 coordinating node(协调节点)

  2. coordinating node,对 document 进行路由,将请求转发给对应的 node(有 primary shard)

  3. 实际的 node 上的 primary shard 处理请求,然后将数据同步到 replica node

  4. coordinating node,如果发现 primary node 和所有 replica node 都搞定之后,就返回响应结果给客户端


补充


节点的角色 Node roles


  • master

  • data

  • data_center

  • data_hot

  • data_warm

  • data_cold

  • ingest

  • ml

  • remote_cluster_client

  • transform


Coordinating node


In the scatter phase, the coordinating node forwards the request to the data nodes which hold the data. Each data node executes the request locally and returns its results to the coordinating node. In the gather phase, the coordinating node reduces each data nodes's result into a single global result set.


参考资料


  1. Elasticsearch node

  2. ES 查询检索数据的过程,是什么样子的?


发布于: 2021 年 02 月 01 日阅读数: 37
用户头像

escray

关注

Let's Go 2017.11.19 加入

在学 Elasticsearch 的项目经理

评论

发布
暂无评论
Elasticsearch Document 增删改内部原理