本文基于es7.3版本。
集群级别的分片分配配置,主要有下面几个:
cluster.routing.allocation.enable:启用或禁止特定种类分片的分配。有下面四种取值:
all
- (default) Allows shard allocation for all kinds of shards.允许所有种类分片的分配,包括primary和replica。默认行为。primaries
- Allows shard allocation only for primary shards.仅允许primary分片的分配,节点重启后,replica的分片不恢复。new_primaries
- Allows shard allocation only for primary shards for new indices.仅允许新建索引的primary分片的分配。测试了一下,貌似与上面的区别不大。none
- No shard allocations of any kind are allowed for any indices.不允许任何种类分片的分配。新建的索引也不会分配primary和replica分片。
仅影响变化的分片。默认情况下,集群中某个节点失败后,此节点上的shard会恢复到其他节点上,设置非all值,会导致失败节点上shard不会恢复到其他节点。这在集群维护时非常有用,避免了节点重启时,分片在节点间移动的开销。需要注意的是,无论何种取值,节点重启后,如果此节点上存在某分片的replica copy,并且集群中没有此分片的primary copy,则此replica copy会恢复为primary copy。另外,即使在none下,新建索引不分配任何分片,但是集群重启后,仍然会分配primary分片。
cluster.routing.allocation.node_concurrent_incoming_recoveries:单个节点的入口并发恢复的分片数量。表示此节点作为恢复目标节点,分片在其他节点或者是由于Rebalance或者是由于其他节点失败,导致需要在此节点上恢复分片。默认是2个并发分片。
cluster.routing.allocation.node_concurrent_outgoing_recoveries:单个几点的出口并发恢复的分片数量。表示此节点作为恢复的源节点,由于Rebalance导致需要从此节点迁移部分分片到其他节点。默认是2个并发分片。
cluster.routing.allocation.node_concurrent_recoveries:用于快速设置上面两个参数,至于这个是总数两个平分,还是分别设置两个限制,目前未知。先留个坑,等我翻看源码再回来填。从下面的代码看,是分别设置。
//ThrottlingAllocationDecider.java
public static final int DEFAULT_CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES = 2;
public static final int DEFAULT_CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES = 4;
public static final String NAME = "throttling";
public static final Setting<Integer> CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING =
new Setting<>("cluster.routing.allocation.node_concurrent_recoveries",
Integer.toString(DEFAULT_CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES),
(s) -> Setting.parseInt(s, 0, "cluster.routing.allocation.node_concurrent_recoveries"),
Property.Dynamic, Property.NodeScope);
public static final Setting<Integer> CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING =
Setting.intSetting("cluster.routing.allocation.node_initial_primaries_recoveries",
DEFAULT_CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES, 0,
Property.Dynamic, Property.NodeScope);
public static final Setting<Integer> CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING =
new Setting<>("cluster.routing.allocation.node_concurrent_incoming_recoveries",
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING::getRaw,
(s) -> Setting.parseInt(s, 0, "cluster.routing.allocation.node_concurrent_incoming_recoveries"),
Property.Dynamic, Property.NodeScope);
public static final Setting<Integer> CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING =
new Setting<>("cluster.routing.allocation.node_concurrent_outgoing_recoveries",
CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING::getRaw,
(s) -> Setting.parseInt(s, 0, "cluster.routing.allocation.node_concurrent_outgoing_rec