使用 Explain ILM API 定位 step_info 卡住的原因
解读
在国内中大型 Elasticsearch 集群运维面试中,**“ILM 卡死”**是高频故障场景。面试官真正想考察的是:
- 你是否能快速判断“卡”在哪个阶段(step_info.action、step_info.name、step_info.phase);
- 能否结合 Explain ILM API 返回的 “step_time”、“step_info.start_time”、“failed_step”、“policy”、“index” 等字段,定位是 配置错误、权限不足、节点资源瓶颈,还是 Bug;
- 是否具备“一分钟定位、三分钟止血、十分钟根治”的实战节奏,而不是只会背官方文档。
知识点
-
Explain ILM API 核心字段
index:当前索引名policy:关联的 ILM policyphase:hot/warm/cold/frozen/deleteaction:rollover/shrink/forcemerge/freeze/deletestep: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 不一定相同
-
国内常见卡点 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或升级小版本
- rollover 条件写错:
-
排查套路(面试口述节奏)
- 先
GET <index>/_ilm/explain看 phase/action/step 三元组 - 若 step=ERROR,直接看
step_info.reason + stack_trace;若 step 长时间不变,看step_time是否超过 action_timeout - 对 shrink/allocate 类,再
GET _cluster/allocation/explain交叉验证 - 对 rollover,看索引 “_settings.index.lifecycle.rollover_alias” 是否存在且写入指向正确
- 最后
GET _ilm/status确认 ILM 总开关未被运维误关
- 先
答案
“我会按下面四步定位:
- 执行
GET my-index-2025.06.25/_ilm/explain?human拿到 phase=warm、action=shrink、step=shrinking-shards 且 step_time 已卡 4 小时,初步怀疑 shrink 资源不足。 - 查看
step_info.node_name发现被调度到 warm-3 节点,但step_info.shards_left=3一直不降;再GET _cluster/stats发现 warm 层总节点数 3,而目标分片数 0 需要把 6 分片合并到 1,节点磁盘水位超过 85%,导致无法分配。 - 交叉
GET _cluster/allocation/explain验证报错 “disk threshold exceeded”,确认是磁盘问题而非 ILM 配置。 - 立即 扩容 warm 节点两台 并调低
cluster.routing.allocation.disk.watermark.low至 80%,两分钟后 step_info.shards_left 开始下降,十分钟后 step 变为 complete,卡死解决。
总结:Explain ILM API 给出 精确到 step 的上下文,再叠加集群级诊断命令,30 秒内可定位 90% 的 ILM 卡顿。”
拓展思考
- 灰度场景:如果业务要求 白天禁止 forcemerge 以保查询,你会在 policy 里加
“prefer_primary_first”: true并配合 cron 触发 _ilm/move 到夜间 吗? - 多租户隔离:国内金融云常把 hot 层按业务标签 node.attr.group=pay/log 拆分,Explain 返回的
step_info.node_name若落在错误标签节点,需用 allocation awareness 强制纠偏,如何设计 policy 与 template 的联动? - 可观测性:在 阿里云 SLS + ES 双写 场景,如何利用 ILM explain 的 step_time 指标 构建 Grafana 面板,提前 1 小时预测 rollover 失败 并触发钉钉告警?