Repository navigation
Description
Problem
The real TN replica-start command generation path is not covered by HAKeeper's existing command redelivery protection. A heartbeat can consume a TN StartReplica command before the TN has acknowledged starting the replica. If the committed heartbeat result is lost, the next heartbeat does not receive that command again.
This is a production control-plane recovery defect, independently reproduced on 4.2-dev e2c99334fd23b9260728695e29befd35ab26b454 and PR #30433 head 0d1637598769ac85c029ede64665906c253925b7. The causal owner files are unchanged between those revisions. Latest main c21a102e74590253dad70d86e0f18646b61457ae also reproduces it in the legacy delivery path, while the new acknowledged-delivery preparing/enabled paths pass the same real-producer lost-response test. See the main verification below.
Root cause
operator.addTnReplicabuildsStartReplicawithServiceType=TNServiceand leavesBootstrapping=false.bootstrapReplicaCommandStatusonly enables acknowledgment-based retention whenBootstrapping=true.getCommandBatchconsequently removes the real TN command on its first committed heartbeat delivery, even when the heartbeat reports no started replica.- If the result never reaches the caller, the target has neither started the replica nor retained a command to receive on the next heartbeat.
The existing TestBootstrapReplicaCommandsRetriedUntilHeartbeatAcknowledges manually constructs a TN command with Bootstrapping=true, so it passes without exercising the real producer contract. This is an accompanying test-coverage gap, rather than evidence that the defect is test-only.
Deterministic white-box reproduction
In pkg/hakeeper/rsm_test.go, add the pkg/hakeeper/operator import and run this diagnostic test. The file already imports testing, sm, pb and require.
func TestTNStartCommandSurvivesLostHeartbeatResponse(t *testing.T) {
const storeID = "tn-review"
const shardID uint64 = 2
op := operator.NewOperator("tnservice", shardID, operator.NoopEpoch,
operator.AddTnReplica{
StoreID: storeID, ShardID: shardID,
ReplicaID: 262146, LogShardID: 1,
})
commands := operator.NewController().Dispatch(
[]*operator.Operator{op}, pb.LogState{}, pb.TNState{},
pb.CNState{}, pb.ProxyState{},
)
require.Len(t, commands, 1)
require.False(t, commands[0].Bootstrapping)
rsm := NewStateMachine(0, 1).(*stateMachine)
rsm.state.State = pb.HAKeeperRunning
_, err := rsm.Update(sm.Entry{Cmd: GetUpdateCommandsCmd(1, commands)})
require.NoError(t, err)
hb, err := (&pb.TNStoreHeartbeat{UUID: storeID}).Marshal()
require.NoError(t, err)
first, err := rsm.Update(sm.Entry{Cmd: GetTNStoreHeartbeatCmd(hb)})
require.NoError(t, err)
var delivered pb.CommandBatch
require.NoError(t, delivered.Unmarshal(first.Data))
require.Len(t, delivered.Commands, 1)
// Discard the committed result: the TN did not observe the command.
second, err := rsm.Update(sm.Entry{Cmd: GetTNStoreHeartbeatCmd(hb)})
require.NoError(t, err)
var retried pb.CommandBatch
require.NoError(t, retried.Unmarshal(second.Data))
require.Len(t, retried.Commands, 1,
"unreported TN replica must remain deliverable after a lost response")
}The last assertion fails: the second response contains zero commands.
Local verification used Go 1.26.4, Linux/amd64, matching native artifacts and -race -count=1. The diagnostic was supplied through a Go overlay; production sources were unchanged.
| Revision/control | Result |
|---|---|
PR #30433 0d16375987, real producer and discarded first result |
Reproduced: expected one command, got zero; package 0.119 s |
Clean tracked 4.2-dev base e2c99334fd, same diagnostic |
Same failure; package 0.128 s |
Existing test with manually marked Bootstrapping=true |
Both log/TN cases pass; package 1.137 s |
Impact and incident attribution
A transient response loss can leave the original TN startup attempt without its startup command. This can delay replica availability and exceed startup/readiness deadlines. The reproduction does not establish that all later operator rescheduling or recovery paths fail forever.
The coverage failure on #30433 is consistent with this mechanism:
- 2026-10-16 22:47:26 UTC: HAKeeper elected its leader.
- 22:47:31: log shard elected its leader; HAKeeper entered Running.
- 22:47:37: HAKeeper enqueued
D/Startfor TN10005-tn, shard 2, replica 262146. - Until 22:48:03: the CN kept observing no ready TN shard, then the 30-second readiness deadline expired.
The specific CI heartbeat-response loss is not proven. The retained bundle has no per-heartbeat proposal/result trace or failure-time goroutine dump. This issue tracks the independently reproduced delivery defect. The separate debugUpdateCNLabel timeout in the race UT job remains a distinct investigation.
Fix and verification requirements
- Align the real TN command producer and HAKeeper's acknowledgment/redelivery owner. Review the meaning of
Bootstrappingbefore changing it globally; preserve normal operator and HAKeeper state transitions. - Exercise commands generated by the real controller, rather than relying only on hand-constructed commands with a different flag.
- Verify a committed-but-unobserved heartbeat result, repeated heartbeats with no replica report, and retirement only after the matching shard/replica report.
- Preserve idempotent start handling, log-service behavior, and cancellation/restart behavior. Increasing readiness timeouts alone does not repair command consumption before acknowledgment.
Latest main verification
Verified on main c21a102e74590253dad70d86e0f18646b61457ae, Go 1.27.1/Linux amd64 with -race. The diagnostic uses the real operator.Controller TN command, and the heartbeat advertises CommandDeliveryAckSupported=true, as the current TN does. It discards the first committed response, then retries without acknowledging or reporting the replica.
| Replicated command-delivery state | Result |
|---|---|
| Legacy: neither Preparing nor Enabled | Reproduces: second heartbeat returns zero commands |
| Preparing | Retains and redelivers the same command; matching ACK retires it |
| Enabled | Retains and redelivers the same command; matching ACK retires it |
All three scenarios were executed in one race run (package 0.110 s; expected failing legacy assertion, two passing controls). They are controlled RSM scenarios, not a full mixed-version deployment experiment.
Main's handleTNHeartbeat chooses getCommandBatchWithAck during Preparing/Enabled for capable TNs, avoiding this loss. Before Preparing, it still chooses the destructive legacy path. store.tryEnableCommandDelivery deliberately waits for capability/admission barriers across HAKeeper members and current service targets, so incomplete upgrades can keep that legacy path reachable. An activated modern cluster must not be classified as affected on the strength of the legacy reproduction alone.
The confirmed scope is therefore 4.2-dev plus main's pre-activation legacy compatibility path, with protection already present in main's new acknowledged-delivery paths. The specific #30433 coverage incident attribution remains unproven as stated above.
Activity
[-][Bug]: TN StartReplica commands bypass heartbeat redelivery protection on 4.2-dev[/-][+][Bug]: TN StartReplica can be consumed before acknowledgment in legacy delivery (4.2-dev and main)[/+]XuPeng-SH commentedon Oct 17, 2026
4.2-dev fix: #30444, commit
505f6ddaa958927034c78b0a9d0537d255ebba36.The fix closes both loss boundaries in the existing RSM owner: real TN
StartReplicacommands survive committed-but-unobserved heartbeats and unrelated/empty subsequent scheduling batches. Supersession, local stop/remove and shutdown revoke stale starts; no ACK protocol or schema backport is required.Clarification to the original exact-replica retirement wording: an exact target report confirms the requested replica. A fresh report of the same local shard under another replica ID cancels obsolete intent, because the current TN receiver keys replicas by shard and cannot replace an existing shard by replica ID; its checker accepts one working replica. Another target/shard report does not retire the start.
Local full HAKeeper/operator/TN-checker UT and race checks passed, as did focused TN/logservice consumer race tests, 100 repetitions of duplicate TN startup under race, incremental configured SCA (0 issues), vet and molint.
gpt-6.1-sol/xhighproduced the design and an independent final PASS review.This issue stays open for main's pre-activation legacy path. This fix does not establish the cause of the specific #30433 startup timeout or resolve its independent CN-label Raft timeout. CI has not been awaited or rerun.
XuPeng-SH commentedon Oct 17, 2026
Main fix submitted as #30445 (
551cf104d8), alongside 4.2-dev #30444.Main's pre-activation legacy path now retains real TN starts across committed-but-unobserved responses and unrelated accepted scheduling updates, with bounded supersession/removal/shutdown cleanup. Its existing preparing/enabled ACK completion and stable delivery identities remain separate and unchanged.
Verification includes full HAKeeper/operator/TN-checker normal/race tests, TN normal tests and eleven focused consumer race controls, 100 repeated duplicate-start race runs, real activation/snapshot/rollover/stale-ACK handoff, and an existing real service fixture extended to prove zero-ID legacy polls cannot consume work before activation. Incremental configured SCA, vet and molint passed; independent
gpt-6.1-sol/xhighfinal review PASS.Both PRs remain pending merge/CI; this comment does not claim the issue is already resolved on either branch. Mixed old/new HAKeeper semantic co-application is not validated; version-coherent rollout and downgrade limitations are explicit in the main PR. The earlier specific CI incident attribution remains unproven.
fix(hakeeper): retry pending TN start operators [4.2-dev] (#30444)
XuPeng-SH commentedon Oct 17, 2026
继续实测验证(2026-10-17):
4.2-dev
ac27db31696c0394ab1b2787b7b0a8f4933f088f(Go 1.26.4):checkers/coordinator、TN checker、Log checker、operator 完整普通与 race 测试均通过;真实 Coordinator → RSM 丢响应/批覆盖/重试与报告收敛测试实际执行通过。历史 RSM 重放和 bootstrap 重投对照也通过。LogService 重复 start/bootstrap/add/nonvoting-add/remove 及 TN 重复/不同 ID start 的 receiver 回归,普通与 race 均通过。均为 Linux/amd64、匹配分支 CGo 产物。main
a322466757b9b0165c59fbda565608653d923b2a(Go 1.27.1):用真实 operator producer 生成 TN StartReplica 后,丢弃首个已提交的心跳响应;-race诊断再次确认 legacy 模式首次返回 1 条、第二次返回 0 条,仍失败。Preparing 和 Enabled 两个对照均连续返回 1 条,通过。该诊断不把 Coordinator 周期重试与 RSM 内保留混为一谈。结论:#30444 的 4.2 修复已验证;main 对应 #30445 仍未合并,整个 #30443 的报告范围尚未全部解决。保留 @XuPeng-SH 开发指派,不整体转测。仍使用 #30443 跟踪,没有为同一缺口新建重复 issue。
fix(hakeeper): retry pending TN start operators (#30445)
XuPeng-SH commentedon Oct 17, 2026
继续独立实测验证(本轮截止 2026-10-17T17:51:03Z),#30445 合并后,#30443 的已确认功能范围在 main 与 4.2-dev 均通过,转 @Ariznawlll 测试。
环境:Linux/amd64 CPU/CGo;main
d304047724bea6104c5c2be496107928034b0778、Go 1.27.1;4.2-devac27db31696c0394ab1b2787b7b0a8f4933f088f、Go 1.26.4。隔离 worktree/Go overlay,仓库原工作树与既有服务未修改。通过仓库 mo-cgo-test 实际编译、链接并执行测试;未变化的 native 输入/产物由 wrapper 校验后复用。独立复现
TestAudit1751LostTNResponseRecovery:b111224b0c624773389b390cd3cf1223126b6ee2失败(首个重试返回 nil),为有效负对照。相关回归:
-race -count=100下通过,共 5,200 个测试/子测试通过事件。覆盖目标失效、不同 ID 报告、取消/teardown、重建、Log 候选失效/存储 incarnation、混合批次和 pointer ownership。命令(每次均非 cached、非空选择):
mo-cgo-test -p 1/2 -count=1 -short -tags matrixone_test -timeout=8m/12m -json [-race] [-overlay ...] ./pkg/hakeeper/checkers ./pkg/hakeeper/checkers/tnservice ./pkg/hakeeper/checkers/logservice ./pkg/hakeeper/operator;RSM、tnservice/logservice 和 SQL 的精确选择、原始 JSONL/stderr/退出码及 SHA 已保存在本轮审计记录。压力命令每次只指定一个精确测试名。机制澄清:修复是 Coordinator 对未完成 TN operator 的周期重发;legacy RSM 仍保留历史消费语义,并非承诺“第二次原始心跳在没有调度检查时也一定保留命令”。这符合当前 #30444/#30445 的功能闭环。需要健康检查继续运行、目标可用并最终交付;不是 exactly-once。未验证现场 CI 的具体丢响应原因、真实网络故障注入、混合旧新二进制滚动升级、GPU 或全仓库 CI;不把这些限制称为通过。
Ariznawlll commentedon Oct 17, 2026
测试版本
main,commit:429c27761be90c3c865685700cc208e194e61be6(修复 PR #30445 的 merge commitd304047724bea6104c5c2be496107928034b0778已进入该 main)。4.2-dev,commit:ac27db31696c0394ab1b2787b7b0a8f4933f088f(修复 PR #30444 已合入)。原问题验证
两条分支均执行真实 Coordinator 生成的 TN
StartReplica(Bootstrapping=false),提交首个心跳但丢弃响应,再在无副本报告情况下继续调度/心跳。TestTNStartRescheduledAfterLegacyCommandLoss的lost_response和overwritten_batch两个子场景在-race -count=3均通过;该原问题路径另以-race -count=20通过(每轮两个子场景)。实际返回为首次生成 1 条启动命令,旧版 RSM 消费后心跳暂为 0 条,但 Coordinator 后续调度每次重新生成与原命令相同的 1 条命令;没有新增 replica ID,目标 shard/replica 报告后停止重试并清除待处理 operator。该修复契约是周期性调度重发,不是旧版 RSM 无调度时对原始心跳的重投。Happy Path 覆盖
TestTNStartRescheduledAfterLegacyCommandLoss、TestTNStartReconcilesReportsAndTargets、TestTNStartReservationsAndPartialReports、TestTNStartRebuildAndTeardown、TestTNStartRetriesPreserveAcknowledgedDelivery、TestTNRetryPreservesPendingLogStart和TestTNRetryDoesNotResurrectObsoleteRemoval,-race -count=3全通过。覆盖真实目标报告后的完成、部分报告、重建、Preparing/Enabled ACK 与并存 Log 待处理命令。-race -count=3全通过。-race -count=3通过;4.2-dev 相同 RSM/TN/LogService 对照-race -count=3通过。Unhappy Path 覆盖
-race -count=3,额外原问题场景 20 轮通过。TestTNStartReconcilesReportsAndTargets在两条分支-race -count=3通过;应取消者没有陈旧命令复活,应保留者保持待处理状态。-race -count=3通过;重建产生新意图,清理后旧意图不复活。白盒验证
本问题是 HAKeeper 内部命令调度/心跳响应所有权路径,公共 SQL 无法精确控制“已提交但调用方未观察到心跳响应”。使用生产 Coordinator、operator 和 RSM 调用的确定性注入及
-race验证;没有将手工设定Bootstrapping=true的旧测试误作原问题覆盖。回归测试
回归已随产品修复进入上述两个官方分支:main 真实命令/丢响应测试、main ACK 对照、4.2-dev 对应测试。这是内部控制面故障/并发测试,不硬塞到 MOTR 的 SQL golden。PR 的 UT、静态检查与 Required 汇总成功;部分 TKE 构建/BVT 检查失败或被跳过,本轮未将它们算作集成通过,也未重跑共享 CI。
测试证据
go test -race -run '^TestTNStartRescheduledAfterLegacyCommandLoss$' -count=20 -timeout=8m ./pkg/hakeeper/checkers,main 与 4.2-dev 输出均为ok,无 race 报告;其余上述定向组均用-race -count=3实际运行,退出码 0。测试结论
测试通过。