{
  "id": "elasticsearch/primary-shard-not-allocated-due-to-shard-lock",
  "signature": "ShardLockObtainFailedException: [my_index][0] obtaining shard lock failed",
  "signature_zh": "分片锁获取失败：[my_index][0] 获取分片锁失败",
  "regex": "ShardLockObtainFailedException: \\[.*?\\]\\[\\d+\\] obtaining shard lock failed",
  "domain": "elasticsearch",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "分片锁无法获取，因为分片仍在恢复中，或者之前的节点崩溃在磁盘上留下了过期的锁文件。",
  "versions": [
    {
      "version": "7.17.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.6.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.11.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Deleting the index loses all data and may not resolve the underlying lock issue if the file system is corrupted.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Restarting does not remove stale lock files; the lock file persists and the same error occurs again.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Remove the stale shard lock file manually: find the shard directory under ES_PATH_CONF/data/nodes/0/indices/<index-uuid>/0/ and delete the 'index.lock' or 'shard.lock' file, then restart the node.",
      "success_rate": 0.9,
      "how": "Remove the stale shard lock file manually: find the shard directory under ES_PATH_CONF/data/nodes/0/indices/<index-uuid>/0/ and delete the 'index.lock' or 'shard.lock' file, then restart the node.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Reroute the unassigned shard using the Cluster Reroute API: POST /_cluster/reroute { \"commands\": [{ \"allocate_stale_primary\": { \"index\": \"my_index\", \"shard\": 0, \"node\": \"my_node\", \"accept_data_loss\": true } }] }",
      "success_rate": 0.75,
      "how": "Reroute the unassigned shard using the Cluster Reroute API: POST /_cluster/reroute { \"commands\": [{ \"allocate_stale_primary\": { \"index\": \"my_index\", \"shard\": 0, \"node\": \"my_node\", \"accept_data_loss\": true } }] }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "手动删除过期的分片锁文件：找到 ES_PATH_CONF/data/nodes/0/indices/<索引UUID>/0/ 目录下的 'index.lock' 或 'shard.lock' 文件，删除后重启节点。",
    "使用 Cluster Reroute API 重新分配未分配的分片：POST /_cluster/reroute { \"commands\": [{ \"allocate_stale_primary\": { \"index\": \"my_index\", \"shard\": 0, \"node\": \"my_node\", \"accept_data_loss\": true } }] }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2024-03-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}