elasticsearch system_error ai_generated true

分片锁获取失败:[my_index][0] 获取分片锁失败

ShardLockObtainFailedException: [my_index][0] obtaining shard lock failed

ID: elasticsearch/primary-shard-not-allocated-due-to-shard-lock

其他格式: JSON · Markdown 中文 · English
82%修复率
85%置信度
1证据数
2024-03-12首次发现

版本兼容性

版本状态引入弃用备注
7.17.10 active
8.6.2 active
8.11.0 active

根因分析

分片锁无法获取,因为分片仍在恢复中,或者之前的节点崩溃在磁盘上留下了过期的锁文件。

English

A shard lock cannot be acquired because the shard is still being recovered or a previous node crash left a stale lock file on disk.

generic

官方文档

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html

解决方案

  1. 手动删除过期的分片锁文件:找到 ES_PATH_CONF/data/nodes/0/indices/<索引UUID>/0/ 目录下的 'index.lock' 或 'shard.lock' 文件,删除后重启节点。
  2. 使用 Cluster Reroute API 重新分配未分配的分片:POST /_cluster/reroute { "commands": [{ "allocate_stale_primary": { "index": "my_index", "shard": 0, "node": "my_node", "accept_data_loss": true } }] }

无效尝试

常见但无效的做法:

  1. 70% 失败

    Deleting the index loses all data and may not resolve the underlying lock issue if the file system is corrupted.

  2. 85% 失败

    Restarting does not remove stale lock files; the lock file persists and the same error occurs again.