1. 问题描述
当集群某台节点离线后,又加入集群时,因为分片恢复问题,会遇到如下问题:
xxxxxxxxxx21obtaining shard lock timed out after 5000ms, previous lock details: [shard creation] trying to lock for [shard creation]]2failed to obtain in-memory shard lock
有时候,即使我们调用了retry_failedAPI,仍然无法恢复分片。
xxxxxxxxxx11POST _cluster/reroute?retry_failed=true&pretty
2. 解决方法
方法1:重启节点
该方法通过重启节点可以快速释放被锁住的内存。但是缺点是:如果多台节点都无法恢复分片,那么就需要重启多台节点。
方法2:手动清理内存
要知道分片被锁住,是因为ES线程正在对某个shard做bulk或者scroll等长时间的操作,导致该shard无法被其他线程获取。此时需要做以下步骤:
关闭索引的写入功能
xxxxxxxxxx61PUT <index_name>/_settings2{3"index": {4"blocks.write": true5}6}关闭该索引
xxxxxxxxxx11POST sumap_domain_20201009/_close等待10分钟,调用:
xxxxxxxxxx11POST _cluster/reroute?retry_failed=true&pretty如果还没有恢复,直接删除游标的上下文。(此操作会导致所有索引的游标都被删除)
xxxxxxxxxx11DELETE /_search/scroll/_all恢复索引设置
xxxxxxxxxx71PUT <index_name>/_settings2{3"index": {4"blocks.write": false5}6}7POST sumap_domain_20201009/_open
Comments NOTHING