当前位置:网站首页>ElastricSearch第二弹之分片原理
ElastricSearch第二弹之分片原理
2022-06-23 18:37:00 【InfoQ】
那么什么是主分片?什么是副本分片呢?
- shard(主分片):我们上边所说的分片其实就指的是主分片,主分片是数据的容器,文档保存在主分片内,主分片又被分配到集群内的各个节点里。每个shard都是一个lucene index。
- replica(副本分片):副本就是对分片的 Copy ,同步存储主分片的数据内容。为了达到高可用,Master 节点会避免将主分片和副本分片放在同一个节点上,所以副本分片数的最大值是 N-1(其中 N 为节点数)。
PUT /myIndex
{
"settings" : {
"number_of_shards" : 5,
"number_of_replicas" : 1
}
}
为什么要分片?为什么要区分主副分片呢?

- 绿色:集群健康完好,一切功能齐全正常,所有分片和副本都可以正常工作。
- 黄色:预警状态,所有主分片功能正常,但至少有一个副本是不能正常工作的。此时集群是可以正常工作的,但是高可用性在某种程度上会受影响。
- 红色:集群不可正常使用。某个或某些分片及其副本异常不可用,这时集群的查询操作还能执行,但是返回的结果会不准确。对于分配到这个分片的写入请求将会报错,最终会导致数据的丢失。
写索引原理:主分片和副本分片的同步原理

shard = hash(routing) % number_of_primary_shards_id_version
- 客户端向 ES1 节点(协调节点)发送写请求,通过路由计算公式得到值为 0,则当前数据应被写到主分片 S0 上。
- ES1 节点将请求转发到 S0 主分片所在的节点 ES3,ES3 接受请求并写入到磁盘。
- 并发将数据复制到两个副本分片 R0 上,其中通过乐观并发控制数据的冲突。一旦所有的副本分片都报告成功,则节点 ES3 将向协调节点报告成功,协调节点(ES1)向客户端报告成功。
副本分片是越多越好吗?
- (1)多个 replica 可以提升搜索操作的吞吐量和性能,但是如果只是在相同节点数目的集群上增加更多的副本分片并不能提高性能,因为每个分片从节点上获得的资源会变少,这个时候你就需要增加更多的硬件资源来提升吞吐量。
- (2)更多的副本分片数提高了数据冗余量,保证了数据的完整性,但是根据上边主副分片之间的交互原理可知,分片间的数据同步会占用一定的网络带宽,影响效率,所以索引的分片数和副本数也不是越多越好。
- 将数据分片是为了提高可处理数据的容量和易于进行水平扩展,为分片做副本是为了提高集群的稳定性和提高并发量。
- 副本是乘法,越多消耗越大,但也越保险。分片是除法,分片越多,单分片数据就越少也越分散。
- 副本越多,集群的可用性就越高,但是由于每个分片都相当于一个 Lucene 的索引文件,会占用一定的文件句柄、内存及 CPU。
边栏推荐
- Shengke communication IPO meeting: annual revenue of 460million China Zhenhua and industry fund are shareholders
- Save: software analysis, verification and test platform
- How to make a list sort according to the order of another list
- 直播回顾 | 云原生混部系统 Koordinator 架构详解(附完整PPT)
- 手把手写深度学习(15):在Hugging Face上构建自己的语料库
- 函數的定義和函數的參數
- Jerry's adding timer interrupt [chapter]
- When Jerry's serial port is set up, it prints garbled code, and the internal crystal oscillator is not calibrated [chapter]
- Jerry added an input capture channel [chapter]
- 混沌工程,了解一下
猜你喜欢

Application de JDBC dans les essais de performance

Online text entity extraction capability helps applications analyze massive text data

【NOI2014】15.起床困難綜合症【二進制】

Summary of accelerating mobile applications at network edge with software programmable FPGA

Product design - Requirements Analysis

Convex optimization notes

LeetCode 每日一题——30. 串联所有单词的子串

Programmable, protocol independent software switch (read the paper)

IDEA控制台显示中文乱码

Shunted self attention | vit method for solving small target problems, which is derived from PVT and higher than PVT
随机推荐
Graffiti intelligence passed the hearing: Tencent is an important shareholder planning to return to Hong Kong for listing
Convex optimization notes
LeetCode 1079. 活字印刷
Robust extraction of specific signals with time structure (Part 1)
Halcon knowledge: contour operator on region (1)
Design of hardware switch with programmable full function rate limiter
How to use the low code platform of the Internet of things for process management?
Various solutions to knapsack problems
从零开发小程序和公众号【第一期】
Cloud security daily 220623: the red hat database management system has found an arbitrary code execution vulnerability and needs to be upgraded as soon as possible
Matrix analysis notes (I)
基于 ShardingSphere 的得物数据库中间件平台“彩虹桥”演进之路
手把手写深度学习(15):在Hugging Face上构建自己的语料库
[comparative learning] koa JS, gin and asp Net core - Middleware
qgis导入WMS OR WMTS
CV background introduction
[noi 2014] 15. Syndrome de difficulté à se lever [binaire]
为什么你的数据图谱分析图上只显示一个值?
Jerry's DAC output mode setting [chapter]
Jerry's broadcast MP3 prompt sound function [chapter]