作为最后手段分配丢失的主分片(allocate_stale_primary)
Elasticsearch集群/节点命令
# Which nodes hold copies of the primary (allocation id, store errors):
GET _shard_stores/musteri?status=red
# Last resort: promote a stale copy to primary; data loss is accepted:
POST _cluster/reroute
{
"commands": [
{
"allocate_stale_primary": {
"index": "musteri",
"shard": 0,
"node": "node-2",
"accept_data_loss": true
}
}
]
}作用
当持有最新主分片副本的节点永久丢失时,将另一节点上较旧的(非 in-sync)副本指定为主分片,使索引脱离 red。
适用场景
仅在承载主分片的节点无法恢复,且无法从快照还原或还原耗时更长时。
注意
陈旧副本不包含最新的写入;该副本之后的所有写入都会永久丢失。若丢失的节点之后回归,其上较新的副本会被删除。先考虑恢复节点和从快照还原。allocate_empty_primary 会创建完全空的分片并删除该分片中的所有数据;仅在没有任何副本留存时使用。