首页  

elasticsearch分片分配机制简介     所属分类 elasticsearch 浏览量 988
allocation

分片分配
两个基础组件 allocators和deciders
Allocators 尝试寻找最优的节点来分配分片
deciders   判断并决定是否要进行这次分配

新建索引  已有索引更新

触发时机
index 增删
node 增删
手工 reroute
replica数量改变
集群重启

新建索引, allocators  优先选择分片较少的节点
deciders依次遍历allocators给出的节点, 并判断是否把分片分配到该节点. 
allocators只关心每个节点上的分片数, 不管每个分片的具体大小. 
deciders 会 阻止把分片分配到超出节点磁盘容量阈值的节点上.

已有索引
allocators 把主分片指定在已经拥有该分片完整数据的节点上. 
副本分片分配后, 从主分片同步数据,

primaryShardAllocator     查找拥有某 shard 最新数据的 node
replicaShardAllocator     查找拥有某 shard 数据的 node
BalancedShardsAllocator   查找拥有最少 shard 个数的 node



es5中的Deciders


MaxRetryAllocationDecider 
ReplicaAfterPrimaryActiveAllocationDecider 
RebalanceOnlyWhenActiveAllocationDecider 
ClusterRebalanceAllocationDecider 
ConcurrentRebalanceAllocationDecider 
EnableAllocationDecider 
NodeVersionAllocationDecider 
SnapshotInProgressAllocationDecider 
FilterAllocationDecider 
SameShardAllocationDecider 
DiskThresholdDecider 
ThrottlingAllocationDecider 
ShardsLimitAllocationDecider 
AwarenessAllocationDecider 

org.elasticsearch.cluster.ClusterModule#createAllocationDeciders

决策结果
ALWAYS YES NO THROTTLE

负载均衡类
SameShardAllocationDecider
避免主副分片分配到同一个节点

AwarenessAllocationDecider
感知分配器,感知服务器、机架等,尽量分散存储shard

cluster.routing.allocation.awareness.attributes: rack_id
cluster.routing.allocation.awareness.attributes: zone

并发控制类
ThrottlingAllocationDecider
recovery阶段的限速配置,包括:

cluster.routing.allocation.node_concurrent_recoveries
cluster.routing.allocation.node_initial_primaries_recoveries
cluster.routing.allocation.node_concurrent_incoming_recoveries
cluster.routing.allocation.node_concurrent_outgoing_recoveries

ConcurrentRebalanceAllocationDecider
rebalance并发控制

通过cluster.routing.allocation.cluster_concurrent_rebalance参数控制,可以动态生效

DiskThresholdDecider
根据磁盘空间进行决策的分配器

条件限制类
RebalanceOnlyWhenActiveAllocationDecider
所有shard都处在active状态下,才可以执行rebalance操作

FilterAllocationDecider
通过接口动态设置的过滤器,包括:

index.routing.allocation.require.【必须】
index.routing.allocation.include. 【允许】
index.routing.allocation.exclude.* 【排除】
cluster.routing.allocation.require.*
cluster.routing.allocation.include.*
cluster.routing.allocation.exclude.*
配置的目标为节点 ip 或节点名等。cluster级别设置会覆盖 index 级别设置。

ReplicaAfterPrimaryActiveAllocationDecider
保证只会在主分片分配完毕后才开始分配分片副本。

ClusterRebalanceAllocationDecider
通过集群中active的shard状态来决定是否可以执行rebalance,通过配置cluster.routing.allocation.allow_rebalance控制,可以动态生效:

indices_all_active
当集群所有的节点分配完毕,才认定集群rebalance完成 默认
indices_primaries_active
只要所有主分片分配完毕,就可以认定集群rebalance 完成
always
即使当主分片和分片副本都没有分配,也允许rebalance操作

上一篇     下一篇
linux history 命令

代码分支和版本管理小技巧

韭菜的自我修养读书笔记

elasticsearch的几个特色功能

常用时序数据库比较

Influxdb概念及原理简介