使用 Explain ILM API 定位 step_info 卡住的原因

解读

在国内中大型 Elasticsearch 集群运维面试中,**“ILM 卡死”**是高频故障场景。面试官真正想考察的是:

  1. 你是否能快速判断“卡”在哪个阶段(step_info.action、step_info.name、step_info.phase);
  2. 能否结合 Explain ILM API 返回的 “step_time”、“step_info.start_time”、“failed_step”、“policy”、“index” 等字段,定位是 配置错误、权限不足、节点资源瓶颈,还是 Bug;
  3. 是否具备“一分钟定位、三分钟止血、十分钟根治”的实战节奏,而不是只会背官方文档。

知识点

  1. Explain ILM API 核心字段

    • index:当前索引名
    • policy:关联的 ILM policy
    • phase:hot/warm/cold/frozen/delete
    • action:rollover/shrink/forcemerge/freeze/delete
    • step:ERROR、retryable_failed、cluster_allocation_explanation、branch_check、complete 等
    • step_time:进入当前 step 的 UTC 时间,国内业务需+8h 换算
    • step_info:子对象,含 type、reason、cause、stack_trace、node_name、shards_left、bytes_left 等
    • failed_step:若曾失败,会记录最后一次失败 step 名,与当前 step 不一定相同
  2. 国内常见卡点 Top5

    • rollover 条件写错:"max_age": "7d" 但索引名没带日期后缀,导致条件永不触发
    • shrink 目标分片数 > 节点数:例如 6→0 但集群只有 3 个 warm 节点,allocation explain 会报 “NO(valid shard copy)”
    • forcemerge 段数 < 1:索引已只读且无新写,step_info.reason=“index has no segments to merge”
    • cold/frozen 阶段挂载快照仓库权限:S3/OSS 密钥无 ListBucket 权限,step_info 出现 “repository_verification_exception”
    • 7.10 之前 Bug:“retryable_failed” 无限重试,需手动 _ilm/retry 或升级小版本
  3. 排查套路(面试口述节奏)

    1. 先 GET <index>/_ilm/explain 看 phase/action/step 三元组
    2. 若 step=ERROR,直接看 step_info.reason + stack_trace;若 step 长时间不变,看 step_time 是否超过 action_timeout
    3. 对 shrink/allocate 类,再 GET _cluster/allocation/explain 交叉验证
    4. 对 rollover,看索引 “_settings.index.lifecycle.rollover_alias” 是否存在且写入指向正确
    5. 最后 GET _ilm/status 确认 ILM 总开关未被运维误关

答案

“我会按下面四步定位:

  1. 执行 GET my-index-2025.06.25/_ilm/explain?human 拿到 phase=warm、action=shrink、step=shrinking-shards 且 step_time 已卡 4 小时,初步怀疑 shrink 资源不足。
  2. 查看 step_info.node_name 发现被调度到 warm-3 节点,但 step_info.shards_left=3 一直不降;再 GET _cluster/stats 发现 warm 层总节点数 3,而目标分片数 0 需要把 6 分片合并到 1,节点磁盘水位超过 85%,导致无法分配。
  3. 交叉 GET _cluster/allocation/explain 验证报错 “disk threshold exceeded”,确认是磁盘问题而非 ILM 配置。
  4. 立即 扩容 warm 节点两台 并调低 cluster.routing.allocation.disk.watermark.low 至 80%,两分钟后 step_info.shards_left 开始下降,十分钟后 step 变为 complete,卡死解决。

总结:Explain ILM API 给出 精确到 step 的上下文,再叠加集群级诊断命令,30 秒内可定位 90% 的 ILM 卡顿。”

拓展思考

  1. 灰度场景:如果业务要求 白天禁止 forcemerge 以保查询,你会在 policy 里加 “prefer_primary_first”: true 并配合 cron 触发 _ilm/move 到夜间 吗?
  2. 多租户隔离:国内金融云常把 hot 层按业务标签 node.attr.group=pay/log 拆分,Explain 返回的 step_info.node_name 若落在错误标签节点,需用 allocation awareness 强制纠偏,如何设计 policy 与 template 的联动?
  3. 可观测性:在 阿里云 SLS + ES 双写 场景,如何利用 ILM explain 的 step_time 指标 构建 Grafana 面板,提前 1 小时预测 rollover 失败 并触发钉钉告警?