Skip to content

[Bug]: LogService full-cluster cold restart panics on duplicate persisted HAKeeper replicas #32151

Done

Description

@jiangxinmeng1

Description

A three-voter LogService/HAKeeper cluster can fail to restart as a whole when more than one node's persisted mo-logservice.metadata retains both a removed HAKeeper replica ID and its current replacement ID for shard 0. With all peers down during startup, the zombie self-check has no authoritative membership reply. startReplicas then tries to start both IDs for the same shard in one NodeHost; NewService returns shard already exist and mo-service panics. If two of three nodes have this metadata, the remaining node cannot form quorum, so ordinary process restarts do not recover the cluster.

Environment and preconditions

  • Isolated three-voter cluster on 10.222.1.51, test binary from the d61a7206 LogService chaos bundle; concrete HAKeeper service-addresses are configured. No TN/CN was running.
  • Immediately before shutdown, data shard 1 voters: node1 385027, node2 395266, node3 477185; HAKeeper shard 0 voters: node1 385028, node2 395265, node3 477186.
  • node1's persisted metadata also contains removed shard-0 IDs 131073 and 374786; node2's contains removed shard-0 ID 131074. The old Raft files remain on disk. These records arose during earlier long-outage/replacement cycles; the complete original metadata files are preserved as mo-logservice.metadata.before-cold-recovery in the isolated test directory.
  • All three stores are stopped together before starting any of them. The test waits for data-directory locks to release. With healthy peers online, the membership self-check can filter the old IDs, so this cold-start precondition matters.

Stable reproduction

On the prepared isolated directory:

root=/home/mo/jxm/logservice-chaos-20261103-d61a7206
python3 "$root/reproduce_cold_restart.py" "$root" --rounds 3

The script requires all three test nodes initially running. Each round:

  1. Save the verified readback and current clean metadata; stop node1, node2 and node3, and wait for the directory locks to release.
  2. Restore the original metadata backup on node1/node2, preserving each store UUID, Raft directory, and original bootstrap-cluster=true configuration.
  3. Start all three nodes with their original configurations; inspect process status and new startup logs.
  4. For test-cluster recovery only, stop the surviving node3, restore the known-current-ID metadata and start all three nodes using temporary bootstrap-cluster=false configs for node1/node2. Check membership and readback before the next round.

Result: 3/3 rounds: node1 and node2 each log panic: shard already exist and exit; node3 remains running with one vote. The three subsequent test recoveries each restored the same 351-record readback from LSN 9451 (SHA256 bb28f629f8e5fa5378904365d1c64fab8f1cc3e806df9b06b4db64e2a733c5ac). The test cluster is running with three voters after the final recovery. An earlier harness attempt started before Dragonboat locks were released and produced failed to lock data directory; that invalid attempt is excluded from 3/3.

Representative startup logs on both failing nodes:

zombie self-check: getShardMembership failed ... connect: connection refused
[00000:31073] replaying raft logs       # node1 old HAKeeper ID
addMetadata for shardID 0, replicaID 131073 skipped, dupl shard
panic: shard already exist
main.startLogService ... cmd/mo-service/main.go:549

Setting bootstrap-cluster=false without removing the duplicate local metadata still produced the same panic. Therefore the failing path is NewService/startReplicas, before later bootstrap logic. After filtering old IDs in the isolated test only, Dragonboat recovered data shard replicas from their imported snapshots (indices 7826, 7825, 8464), all three addresses returned the same retained WAL data, and subsequent writes succeeded. No data corruption was observed.

Expected behavior

A legitimate whole-cluster cold restart must use the current persisted Raft membership, avoid starting two local replicas of the same shard, and restore a quorum without manually editing metadata. If the current membership cannot be established during startup, the store must not panic or silently select an obsolete voter. A first-time cluster bootstrap must still work.

Code path and scope

  • pkg/logservice/store.go:365 checkZombieReplicas is best-effort: when no peer answers authoritatively, it returns no zombies. That policy allows cold bootstrap but does not resolve multiple persisted IDs for one shard.
  • pkg/logservice/store.go:485 startReplicas iterates every unfiltered local metadata record and calls NodeHost.StartReplica for each. It does not reconcile duplicate shard IDs before the second start.
  • cmd/mo-service/main.go:549 panics on NewService error.

This differs from #27803 (discovery-only warm restart with no concrete addresses) and #32135 (old initial ID absent from local metadata but reintroduced by bootstrap config). Here concrete peer addresses exist, old IDs remain in local metadata, and all peers are temporarily unavailable during cold start.

Impact and evidence

Two out of three stores can repeatedly fail at startup, preventing both the data and HAKeeper shards from forming a majority. The observed effect is cluster unavailability; no confirmed WAL loss or corruption.

Raw evidence on 51: $root/cold-repeat-verified2-20261104.log, node-{1,2}/stdout.log, the two mo-logservice.metadata.before-cold-recovery files, and restart-20261104.* readback files. The script is $root/reproduce_cold_restart.py. Manual metadata filtering was performed only to recover the isolated test cluster and is not a proposed production fix.

A regression should cover multiple historical IDs for one shard on at least two stores, all-peers-down startup with concrete service addresses, genuine first bootstrap, and normal single-node restart while peers are available.

Activity

  1. self-assigned this
    on Nov 4, 2026
  2. jiangxinmeng1 commented on Nov 4, 2026

    @jiangxinmeng1
    ContributorAuthor

    Additional cold-start boundary tests on the same isolated three-voter cluster:

    • With only current replica IDs in local metadata, all three stores cold-started under their original bootstrap-cluster=true configs. Both shards returned the same three-member views; retained WAL readback matched the pre-stop SHA256, and three new appends succeeded. This controls for bootstrap configuration by itself.
    • With stale HAKeeper IDs on only node1, starting node1 before its peers reproduced panic: shard already exist. Clean node2/node3 then formed a working 2/3 majority and completed three appends/readbacks. Restarting node1 again with the same stale metadata after those peers were online succeeded: startup skipped IDs 131073 and 374786, and the three-member views returned.
    • With stale IDs on both node1 and node2, starting clean node3 five seconds earlier did not rescue the cluster. Node3 alone returned shard not found for the data-shard lookup; node1 and node2 both panicked when started. After restoring only the known-current metadata in this test environment, all three voters recovered and retained readback matched the pre-stop SHA256.

    The practical boundary is whether startup can obtain a usable peer membership view before it processes multiple local IDs for one shard. One healthy store online is insufficient in this tested topology; two healthy stores allowed the stale third store to rejoin. Full evidence and hashes: three-node failure report. The reproduction script is here.

  3. added a commit that references this issue on Nov 6, 2026
    ee5e93b
  4. XuPeng-SH commented on Nov 6, 2026

    @XuPeng-SH
    Contributor

    QA 交接:#32149 已于 2026-11-06 07:40:26 UTC 合入 main,merge ee5e93bcefd4f04bcda6b8e5002eef96038396d3,最终 head f83150eb8ffb17a3d91a3fbf6865e5a0d0b9ec2e。转交 @Ariznawlll 验证,不代表验收通过。

    修复范围:普通 HAKeeper 冷启动在本地保留多个历史 replica ID、peer membership 无法回答时,选择未被判为 zombie 的最高本地 HAKeeper ID,跳过旧 ID,避免同一 NodeHost 为 shard 0 启动两个副本;已有 replacement 运行时 bootstrap 不重放配置中的初始 ID。这依赖 HAKeeper replica ID 单调分配,不是任意损坏 metadata 的恢复承诺。

    已完整核对正文及 1 条评论、PR 最终 diff 和讨论。旧构建中的 3/3 全集群冷启动 panic、一个健康节点不足而两个健康节点可救回的边界,均属于修复前证据,暂无本次合并版本的已验证反例。作者报告真实三 voter 历史 metadata 冷重启回归及组合分支包测试通过;最新本地验证和 approved review 绑定旧 head 790bca9921,Mergify 报告合并门禁 CI Required 成功。本轮未执行本地/集群测试,也未修改测试或生产 metadata。

    QA 建议:至少两个节点保留旧/新 shard-0 ID,原配置下全部停机、等待目录锁释放后冷启,确认无 duplicate-shard panic、恢复两 shard quorum、原有 WAL hash/LSN/payload 一致且新写成功;另做单节点 stale、单个 clean 节点先起、两 healthy peer 可回答、干净首次 bootstrap、初始 ID 已不存在的 replacement 对照。最终回归用 membership probe 注入“无人应答”,不是已完成三 voter 网络 chaos 或任意灾难恢复验证。#27803 的 discovery-only 路径及其他 LogService 故障应按各自范围验收。

  5. Ariznawlll commented on Nov 22, 2026

    @Ariznawlll
    Collaborator

    阶段性测试结果

    在官方 main cc2c82dc4a6cb2cbcc046ef9caebde50c6004b15 上,TestHAKeeperColdRestartWithHistoricalReplicas 及成员存在/缺失、RPC 失败、无地址、节点意见不一致和 zombie 跳过等定向用例以 go test -race -count=3 通过。

    冷启动用例在同一测试进程内创建真实的三个 LogService 服务:两节点构造多个历史 HAKeeper 副本记录,全部关闭后重新启动,验证选择当前副本并重新选出 leader;第三节点的 replacement bootstrap 也保持正确。成员查询“无人应答”由测试注入,不能等同于真实网络隔离。

    本次未验证多机/多进程全集群故障、TN/TAE WAL hash 与 payload、业务新写入或其他生产恢复边界;因此 Issue 暂保持开放。

  6. Ariznawlll commented on Nov 24, 2026

    @Ariznawlll
    Collaborator

    结论

    验收通过,关闭本 Issue。此前阶段性验证缺少的真实磁盘持久化、原 WAL 数据保留及恢复后新写入已经补齐;两个节点同时保留多个历史 HAKeeper replica ID、全部 peer 不可用时,三 voter 能选择当前副本并恢复 leader,不再触发 shard already exist 启动失败。

    测试版本与修复范围

    原冷启动场景

    TestHAKeeperColdRestartWithHistoricalReplicas 以 -count=3 执行,3/3 通过:

    • 建立三个 LogService 服务和三个 HAKeeper voting replica;node1 保留两个旧 ID,node2 保留一个旧 ID,同时保留各自当前 replacement ID。
    • 全部关闭后,在 membership 查询无人应答的条件下依次冷启动,三个服务均选择当前 ID,且 HAKeeper 重新选出 leader。
    • 第三个节点没有旧 initial-ID 记录;再次以包含旧 initial ID 的 bootstrap 配置调用时,已持久化 replacement 仍保持运行,没有被重放替换。
    • 成员存在/缺失、RPC 失败、无地址、节点意见不一致和 zombie 跳过等定向测试此前已以 go test -race -count=3 通过。

    真实磁盘、WAL 与新写验证

    MOTR 注入的 disk-backed 控制使用 vfs.Default 和每个测试独立的临时磁盘目录,两个测试各执行 3 次,合计 6/6 通过:

    • TestQA32151DiskColdRestart:重复上述双节点多历史 ID、全停后无人应答的冷启动,验证当前 replica 和 leader 恢复。
    • TestQA32151DiskColdRestartRetainsWAL:另外建立真实三 voter data shard,在停止前提交 qa-wal-before;冷启动后按原 LSN 读回,断言完整 record bytes 与提交前完全一致,再成功 Append qa-wal-after,且新 LSN 大于原 LSN。
    • 因而本轮不仅检查进程未 panic,也覆盖了原 Issue 交接要求的 WAL LSN/payload 保留和恢复后的业务写入接口。

    回归去向与边界

    • 历史 replica 用例位于研发 pkg/logservice/zombie_repro_test.go;磁盘与 WAL 控制位于 MOTR .github/qa/issue_32151_disk_test.go,由 .github/workflows/qa-main-issue-regression.yml 强制检查每个测试的 3 次 PASS 计数。
    • 本轮是同一测试进程内三个真实 LogService 实例的受控冷启动,membership“无人应答”由测试注入;不声称已完成多机/多进程 Chaos、任意 metadata 损坏恢复或 TN/TAE 业务 WAL 全量恢复。原 Issue 本身未运行 TN/CN,这些边界不改变本次针对 duplicate persisted HAKeeper replica 冷启动路径的关闭结论。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions